Skip to content

Commit

Permalink
ci: use same structure for exporter job deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-micah committed Feb 29, 2024
1 parent 865c1bd commit b584477
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 25 deletions.
26 changes: 9 additions & 17 deletions .github/workflows/exporter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
uses: docker/metadata-action@v4
with:
images: |
${{ secrets.CLOUD_RUN_EXPORTER_IMAGE }}
${{ vars.CLOUD_RUN_EXPORTER_IMAGE }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha
Expand All @@ -156,22 +156,14 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-from: type=registry,ref=${{ vars.CLOUD_RUN_EXPORTER_IMAGE }}:buildcache
cache-to: type=registry,ref=${{ vars.CLOUD_RUN_EXPORTER_IMAGE }}:buildcache,mode=max

- name: Replace variables in exporter-job.yaml
run: |
sed -i s#%EXPORTER_IMAGE%#${{ fromJSON(steps.meta.outputs.json).tags[1] }}#g exporter-job.yaml
sed -i s#%SERVICE_ACCOUNT%#${{ secrets.CLOUD_RUN_SERVICE_ACCOUNT }}#g exporter-job.yaml
- name: Update Cloud Run Job
run: |
gcloud beta run jobs update ${{ secrets.CLOUD_RUN_EXPORTER }} \
--project=${{ secrets.GCP_PROJECT_ID }} \
--image=${{ fromJSON(steps.meta.outputs.json).tags[1] }} \
--service-account=${{ secrets.CLOUD_RUN_SERVICE_ACCOUNT }} \
--parallelism=1 \
--set-cloudsql-instances=${{ secrets.CLOUD_SQL_DB }} \
--execution-environment=gen2 \
--region=us-central1 \
--set-env-vars=EXPORTER__DATABASE__REQUIRE_SSL=false \
--set-secrets=EXPORTER__DATABASE__SOCKET=APP__DATABASE__SOCKET:2 \
--set-secrets=EXPORTER__DATABASE__DATABASE_NAME=APP__DATABASE__DATABASE_NAME:1 \
--set-secrets=EXPORTER__DATABASE__PASSWORD=APP__DATABASE__PASSWORD:1 \
--set-secrets=EXPORTER__DATABASE__USERNAME=APP__DATABASE__USERNAME:1 \
--set-secrets=EXPORTER__SHEETS__SPREADSHEET_ID=EXPORTER__SHEETS__SPREADSHEET_ID:1
gcloud run jobs replace exporter-job.yaml --region=us-central1 --project=${{ secrets.GCP_PROJECT_ID }}
16 changes: 8 additions & 8 deletions .github/workflows/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,18 @@ jobs:
cache-from: type=registry,ref=${{ vars.CLOUD_RUN_OTEL_COLLECTOR_IMAGE }}:buildcache
cache-to: type=registry,ref=${{ vars.CLOUD_RUN_OTEL_COLLECTOR_IMAGE }}:buildcache,mode=max

- name: Replace variables in run-service.yaml
- name: Replace variables in backend-service.yaml
run: |
sed -i s#%OTEL_COLLECTOR_IMAGE%#${{ fromJSON(steps.otel-collector-meta.outputs.json).tags[1] }}#g run-service.yaml
sed -i s#%APP_IMAGE%#${{ fromJSON(steps.backend-meta.outputs.json).tags[1] }}#g run-service.yaml
sed -i s#%SERVICE_ACCOUNT%#${{ secrets.CLOUD_RUN_SERVICE_ACCOUNT }}#g run-service.yaml
sed -i s#%APP__APPLICATION__PORT%#${{ secrets.APP__APPLICATION__PORT }}#g run-service.yaml
sed -i s#%APP__APPLICATION__BASE_URL%#${{ secrets.APP__APPLICATION__BASE_URL }}#g run-service.yaml
sed -i s#%APP__BIGCOMMERCE__INSTALL_REDIRECT_URI%#${{ secrets.APP__BIGCOMMERCE__INSTALL_REDIRECT_URI }}#g run-service.yaml
sed -i s#%OTEL_COLLECTOR_IMAGE%#${{ fromJSON(steps.otel-collector-meta.outputs.json).tags[1] }}#g backend-service.yaml
sed -i s#%APP_IMAGE%#${{ fromJSON(steps.backend-meta.outputs.json).tags[1] }}#g backend-service.yaml
sed -i s#%SERVICE_ACCOUNT%#${{ secrets.CLOUD_RUN_SERVICE_ACCOUNT }}#g backend-service.yaml
sed -i s#%APP__APPLICATION__PORT%#${{ secrets.APP__APPLICATION__PORT }}#g backend-service.yaml
sed -i s#%APP__APPLICATION__BASE_URL%#${{ secrets.APP__APPLICATION__BASE_URL }}#g backend-service.yaml
sed -i s#%APP__BIGCOMMERCE__INSTALL_REDIRECT_URI%#${{ secrets.APP__BIGCOMMERCE__INSTALL_REDIRECT_URI }}#g backend-service.yaml
- name: Deploy Cloud Run
run: |
gcloud run services replace run-service.yaml --region=us-central1 --project=${{ secrets.GCP_PROJECT_ID }}
gcloud run services replace backend-service.yaml --region=us-central1 --project=${{ secrets.GCP_PROJECT_ID }}
coverage:
name: coverage
Expand Down
File renamed without changes.
53 changes: 53 additions & 0 deletions exporter-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apiVersion: run.googleapis.com/v1
kind: Job
metadata:
name: exporter
spec:
template:
metadata:
annotations:
run.googleapis.com/cloudsql-instances: stand-with-ukraine-bc-app:us-central1:db
run.googleapis.com/execution-environment: gen2
spec:
parallelism: 1
taskCount: 1
template:
spec:
containers:
- name: exporter
image: "%EXPORTER_IMAGE%"
env:
- name: EXPORTER__DATABASE__REQUIRE_SSL
value: 'false'
- name: EXPORTER__DATABASE__SOCKET
valueFrom:
secretKeyRef:
key: '2'
name: APP__DATABASE__SOCKET
- name: EXPORTER__DATABASE__DATABASE_NAME
valueFrom:
secretKeyRef:
key: '1'
name: APP__DATABASE__DATABASE_NAME
- name: EXPORTER__DATABASE__PASSWORD
valueFrom:
secretKeyRef:
key: '1'
name: APP__DATABASE__PASSWORD
- name: EXPORTER__DATABASE__USERNAME
valueFrom:
secretKeyRef:
key: '1'
name: APP__DATABASE__USERNAME
- name: EXPORTER__SHEETS__SPREADSHEET_ID
valueFrom:
secretKeyRef:
key: '1'
name: EXPORTER__SHEETS__SPREADSHEET_ID
resources:
limits:
cpu: 1000m
memory: 512Mi
maxRetries: 0
timeoutSeconds: '600'
serviceAccountName: "%SERVICE_ACCOUNT%"

0 comments on commit b584477

Please sign in to comment.