|
| 1 | +name: "☁️ Publish Images to GCP" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + image_tag: |
| 7 | + description: The image tag to publish |
| 8 | + type: string |
| 9 | + required: false |
| 10 | + default: "" |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + id-token: write |
| 15 | + |
| 16 | +env: |
| 17 | + PROJECT_ID: "basicblock" |
| 18 | + GAR_LOCATION: "us-central1" |
| 19 | + GAR_REPOSITORY: "docker-images" |
| 20 | + WORKLOAD_IDENTITY_PROVIDER: "projects/327281795986/locations/global/workloadIdentityPools/github-pool/providers/basicblock-repo" |
| 21 | + SERVICE_ACCOUNT_EMAIL: "githubactions@basicblock.iam.gserviceaccount.com" |
| 22 | + |
| 23 | +jobs: |
| 24 | + publish-webapp: |
| 25 | + name: "Build and push webapp" |
| 26 | + runs-on: ubuntu-latest |
| 27 | + env: |
| 28 | + PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING: 1 |
| 29 | + steps: |
| 30 | + - name: ⬇️ Checkout repo |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + submodules: recursive |
| 34 | + |
| 35 | + - name: "#️⃣ Get image tag" |
| 36 | + id: get_tag |
| 37 | + uses: ./.github/actions/get-image-tag |
| 38 | + with: |
| 39 | + tag: ${{ inputs.image_tag }} |
| 40 | + |
| 41 | + - name: 📛 Set tags to push |
| 42 | + id: set_tags |
| 43 | + run: | |
| 44 | + ref_without_tag=${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/trigger.dev |
| 45 | + image_tags=$ref_without_tag:${{ steps.get_tag.outputs.tag }} |
| 46 | +
|
| 47 | + if [[ "${{ steps.get_tag.outputs.is_semver }}" == true ]]; then |
| 48 | + image_tags=$image_tags,$ref_without_tag:v4-beta |
| 49 | + fi |
| 50 | +
|
| 51 | + echo "image_tags=${image_tags}" >> "$GITHUB_OUTPUT" |
| 52 | +
|
| 53 | + - name: 📝 Set build info |
| 54 | + id: set_build_info |
| 55 | + run: | |
| 56 | + tag=${{ steps.get_tag.outputs.tag }} |
| 57 | + if [[ "${{ steps.get_tag.outputs.is_semver }}" == true ]]; then |
| 58 | + echo "BUILD_APP_VERSION=${tag}" >> "$GITHUB_OUTPUT" |
| 59 | + fi |
| 60 | + echo "BUILD_GIT_SHA=${{ github.sha }}" >> "$GITHUB_OUTPUT" |
| 61 | + echo "BUILD_GIT_REF_NAME=${{ github.ref_name }}" >> "$GITHUB_OUTPUT" |
| 62 | + echo "BUILD_TIMESTAMP_SECONDS=$(date +%s)" >> "$GITHUB_OUTPUT" |
| 63 | +
|
| 64 | + - name: 'Authenticate to Google Cloud' |
| 65 | + id: auth |
| 66 | + uses: google-github-actions/auth@v2 |
| 67 | + with: |
| 68 | + token_format: access_token |
| 69 | + service_account: ${{ env.SERVICE_ACCOUNT_EMAIL }} |
| 70 | + workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }} |
| 71 | + project_id: ${{ env.PROJECT_ID }} |
| 72 | + |
| 73 | + - name: 'Docker auth' |
| 74 | + uses: docker/login-action@v3 |
| 75 | + with: |
| 76 | + username: oauth2accesstoken |
| 77 | + password: ${{ steps.auth.outputs.access_token }} |
| 78 | + registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev |
| 79 | + |
| 80 | + - name: Set up Docker Buildx |
| 81 | + uses: docker/setup-buildx-action@v3 |
| 82 | + |
| 83 | + - name: 🐳 Build image and push to Artifact Registry |
| 84 | + uses: docker/build-push-action@v6 |
| 85 | + with: |
| 86 | + context: . |
| 87 | + file: ./docker/Dockerfile |
| 88 | + platforms: linux/amd64 |
| 89 | + tags: ${{ steps.set_tags.outputs.image_tags }} |
| 90 | + push: true |
| 91 | + build-args: | |
| 92 | + BUILD_APP_VERSION=${{ steps.set_build_info.outputs.BUILD_APP_VERSION }} |
| 93 | + BUILD_GIT_SHA=${{ steps.set_build_info.outputs.BUILD_GIT_SHA }} |
| 94 | + BUILD_GIT_REF_NAME=${{ steps.set_build_info.outputs.BUILD_GIT_REF_NAME }} |
| 95 | + BUILD_TIMESTAMP_SECONDS=${{ steps.set_build_info.outputs.BUILD_TIMESTAMP_SECONDS }} |
| 96 | + SENTRY_RELEASE=${{ steps.set_build_info.outputs.BUILD_GIT_SHA }} |
| 97 | + SENTRY_ORG=triggerdev |
| 98 | + SENTRY_PROJECT=trigger-cloud |
| 99 | + secrets: | |
| 100 | + sentry_auth_token= |
| 101 | +
|
| 102 | + publish-workers: |
| 103 | + name: "Build and push ${{ matrix.package }}" |
| 104 | + runs-on: ubuntu-latest |
| 105 | + strategy: |
| 106 | + fail-fast: false |
| 107 | + matrix: |
| 108 | + package: [coordinator, docker-provider, kubernetes-provider, supervisor] |
| 109 | + steps: |
| 110 | + - name: ⬇️ Checkout repo |
| 111 | + uses: actions/checkout@v4 |
| 112 | + |
| 113 | + - name: "#️⃣ Get image tag" |
| 114 | + id: get_tag |
| 115 | + uses: ./.github/actions/get-image-tag |
| 116 | + with: |
| 117 | + tag: ${{ inputs.image_tag }} |
| 118 | + |
| 119 | + - name: 📦 Get image repo |
| 120 | + id: get_repository |
| 121 | + run: | |
| 122 | + if [[ "${{ matrix.package }}" == *-provider ]]; then |
| 123 | + provider_type=$(echo "${{ matrix.package }}" | cut -d- -f1) |
| 124 | + repo=provider/${provider_type} |
| 125 | + else |
| 126 | + repo="${{ matrix.package }}" |
| 127 | + fi |
| 128 | + echo "repo=${repo}" >> "$GITHUB_OUTPUT" |
| 129 | +
|
| 130 | + - name: 📛 Set tags to push |
| 131 | + id: set_tags |
| 132 | + run: | |
| 133 | + ref_without_tag=${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ steps.get_repository.outputs.repo }} |
| 134 | + image_tags=$ref_without_tag:${{ steps.get_tag.outputs.tag }} |
| 135 | +
|
| 136 | + if [[ "${{ matrix.package }}" == "supervisor" && "${{ steps.get_tag.outputs.is_semver }}" == true ]]; then |
| 137 | + image_tags=$image_tags,$ref_without_tag:v4-beta |
| 138 | + fi |
| 139 | +
|
| 140 | + echo "image_tags=${image_tags}" >> "$GITHUB_OUTPUT" |
| 141 | +
|
| 142 | + - name: 'Authenticate to Google Cloud' |
| 143 | + id: auth |
| 144 | + uses: google-github-actions/auth@v2 |
| 145 | + with: |
| 146 | + token_format: access_token |
| 147 | + service_account: ${{ env.SERVICE_ACCOUNT_EMAIL }} |
| 148 | + workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }} |
| 149 | + project_id: ${{ env.PROJECT_ID }} |
| 150 | + |
| 151 | + - name: 'Docker auth' |
| 152 | + uses: docker/login-action@v3 |
| 153 | + with: |
| 154 | + username: oauth2accesstoken |
| 155 | + password: ${{ steps.auth.outputs.access_token }} |
| 156 | + registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev |
| 157 | + |
| 158 | + - name: Set up Docker Buildx |
| 159 | + uses: docker/setup-buildx-action@v3 |
| 160 | + |
| 161 | + - name: 🐳 Build image and push to Artifact Registry |
| 162 | + uses: docker/build-push-action@v6 |
| 163 | + with: |
| 164 | + context: . |
| 165 | + file: ./apps/${{ matrix.package }}/Containerfile |
| 166 | + platforms: linux/amd64 |
| 167 | + tags: ${{ steps.set_tags.outputs.image_tags }} |
| 168 | + push: true |
0 commit comments