|
| 1 | +--- |
| 2 | +name: Prod |
| 3 | + |
| 4 | +on: |
| 5 | + release: |
| 6 | + types: |
| 7 | + - released |
| 8 | + - prereleased |
| 9 | + |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + outputs: |
| 14 | + image: ${{ steps.export.outputs.image }} |
| 15 | + tag: ${{ steps.export.outputs.tag }} |
| 16 | + |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + ref: master # reference branch |
| 24 | + |
| 25 | + - name: Install (Buildx) |
| 26 | + uses: docker/setup-buildx-action@v3 |
| 27 | + |
| 28 | + - name: Login (GCP) |
| 29 | + uses: google-github-actions/auth@v2 |
| 30 | + with: |
| 31 | + credentials_json: ${{ secrets.CREDENTIALS_JSON }} |
| 32 | + |
| 33 | + - name: Install (Gcloud) |
| 34 | + uses: google-github-actions/setup-gcloud@v1 |
| 35 | + with: |
| 36 | + project_id: crane-cloud-274413 |
| 37 | + install_components: "gke-gcloud-auth-plugin" |
| 38 | + |
| 39 | + - name: Login (GCR) |
| 40 | + run: gcloud auth configure-docker |
| 41 | + |
| 42 | + - id: meta |
| 43 | + name: Tag |
| 44 | + uses: docker/metadata-action@v3 |
| 45 | + with: |
| 46 | + flavor: | |
| 47 | + latest=true |
| 48 | + images: gcr.io/crane-cloud-274413/database-api |
| 49 | + tags: | |
| 50 | + type=ref,event=branch |
| 51 | + type=ref,event=pr |
| 52 | + type=semver,pattern={{version}} |
| 53 | + type=semver,pattern={{major}}.{{minor}} |
| 54 | + type=sha |
| 55 | +
|
| 56 | + - name: Build |
| 57 | + uses: docker/build-push-action@v2 |
| 58 | + with: |
| 59 | + cache-from: type=gha |
| 60 | + cache-to: type=gha,mode=max |
| 61 | + context: . |
| 62 | + file: docker/prod/Dockerfile |
| 63 | + labels: ${{ steps.meta.outputs.labels }} |
| 64 | + push: true |
| 65 | + tags: ${{ steps.meta.outputs.tags }} |
| 66 | + |
| 67 | + - id: export |
| 68 | + name: Export |
| 69 | + uses: actions/github-script@v5 |
| 70 | + with: |
| 71 | + script: | |
| 72 | + const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`) |
| 73 | + const fullUrl = metadata.tags.find((t) => t.includes(':sha-')) |
| 74 | + if (fullUrl == null) { |
| 75 | + core.error('Unable to find sha tag of image') |
| 76 | + } else { |
| 77 | + const tag = fullUrl.split(':')[1] |
| 78 | + core.setOutput('image', fullUrl) |
| 79 | + core.setOutput('tag', tag) |
| 80 | + } |
| 81 | +
|
| 82 | + Production: |
| 83 | + name: Deploy (Production) |
| 84 | + |
| 85 | + needs: |
| 86 | + - build |
| 87 | + |
| 88 | + runs-on: ubuntu-latest |
| 89 | + |
| 90 | + env: |
| 91 | + namespace: cranecloud-prod |
| 92 | + |
| 93 | + steps: |
| 94 | + - name: Clone |
| 95 | + uses: actions/checkout@v2 |
| 96 | + |
| 97 | + - name: Login (GCP) |
| 98 | + uses: google-github-actions/auth@v2 |
| 99 | + with: |
| 100 | + credentials_json: ${{ secrets.CREDENTIALS_JSON }} |
| 101 | + |
| 102 | + - name: Install (Gcloud) |
| 103 | + uses: google-github-actions/setup-gcloud@v1 |
| 104 | + with: |
| 105 | + project_id: crane-cloud-274413 |
| 106 | + install_components: "gke-gcloud-auth-plugin" |
| 107 | + |
| 108 | + - name: Login (Kubernetes Cluster) |
| 109 | + uses: google-github-actions/get-gke-credentials@v1 |
| 110 | + with: |
| 111 | + cluster_name: staging-cluster |
| 112 | + location: us-central1-a |
| 113 | + project_id: crane-cloud-274413 |
| 114 | + |
| 115 | + - name: Add Repo (cranecloud) |
| 116 | + run: | |
| 117 | + helm repo add cranecloud https://crane-cloud.github.io/helm-charts/ |
| 118 | +
|
| 119 | + - name: Helm Release |
| 120 | + run: | |
| 121 | + helm upgrade --install \ |
| 122 | + database-api cranecloud/cranecloud \ |
| 123 | + --values helm/values.prod.yaml \ |
| 124 | + --namespace $namespace \ |
| 125 | + --set image.tag="${{ needs.build.outputs.tag }}" \ |
| 126 | + --set environment.DATABASE_URI="${{ secrets.PRODUCTION_DATABASE_URI }}" \ |
| 127 | + --set environment.JWT_SALT="${{ secrets.PRODUCTION_JWT_SALT }}" \ |
| 128 | + --set environment.ACTIVITY_LOGGER_URL="${{ secrets.PRODUCTION_ACTIVITY_LOGGER_URL }}" \ |
| 129 | + --set environment.ADMIN_MYSQL_USER="${{ secrets.PRODUCTION_ADMIN_MYSQL_USER }}" \ |
| 130 | + --set environment.ADMIN_MYSQL_PASSWORD="${{ secrets.PRODUCTION_ADMIN_MYSQL_PASSWORD }}" \ |
| 131 | + --set environment.ADMIN_MYSQL_HOST="${{ secrets.PRODUCTION_ADMIN_MYSQL_HOST }}" \ |
| 132 | + --set environment.ADMIN_MYSQL_PORT="${{ secrets.PRODUCTION_ADMIN_MYSQL_PORT }}" \ |
| 133 | + --set environment.ADMIN_PSQL_USER="${{ secrets.PRODUCTION_ADMIN_PSQL_USER }}" \ |
| 134 | + --set environment.ADMIN_PSQL_PASSWORD="${{ secrets.PRODUCTION_ADMIN_PSQL_PASSWORD }}" \ |
| 135 | + --set environment.ADMIN_PSQL_HOST="${{ secrets.PRODUCTION_ADMIN_PSQL_HOST }}" \ |
| 136 | + --set environment.ADMIN_PSQL_PORT="${{ secrets.PRODUCTION_ADMIN_PSQL_PORT }}" \ |
| 137 | + --set environment.MAIL_PASSWORD="${{ secrets.MAIL_PASSWORD }}" \ |
| 138 | + --timeout=300s |
| 139 | +
|
| 140 | + - name: Monitor Rollout |
| 141 | + run: | |
| 142 | + kubectl rollout status deployment/database-api --timeout=300s --namespace $namespace |
0 commit comments