|
66 | 66 | AWS_ECR_ACCOUNT_NUM: ${{ secrets.ENV_ECR_AWS_ACCOUNT_NUM }}
|
67 | 67 | GCP_DOCKER_ARTIFACT_REPO: ${{ vars.GCP_DOCKER_ARTIFACT_REPO }}
|
68 | 68 | TARGET_REGISTRY: ${{ inputs.TARGET_REGISTRY }}
|
| 69 | + GCP_DOCKER_BUILD_LOCK_BUCKET: "aptos-docker-build-lock-bucket" |
69 | 70 |
|
70 | 71 | permissions:
|
71 | 72 | contents: read
|
72 | 73 | id-token: write #required for GCP Workload Identity federation which we use to login into Google Artifact Registry
|
73 | 74 |
|
74 | 75 | jobs:
|
| 76 | + pre-build-validation: |
| 77 | + outputs: |
| 78 | + image-exist: ${{ steps.set-output.outputs.image-exist }} |
| 79 | + runs-on: runs-on,cpu=4,family=c7,image=aptos-ubuntu-x64,run-id=${{ github.run_id }},spot=co,disk=small |
| 80 | + steps: |
| 81 | + - uses: actions/checkout@v4 |
| 82 | + with: |
| 83 | + ref: ${{ env.GIT_SHA }} |
| 84 | + |
| 85 | + - name: Check if docker images already exist |
| 86 | + id: check-images |
| 87 | + uses: aptos-labs/aptos-core/.github/actions/wait-images-ci@main |
| 88 | + continue-on-error: true |
| 89 | + with: |
| 90 | + GIT_SHA: ${{ env.GIT_SHA }} |
| 91 | + GCP_DOCKER_ARTIFACT_REPO: ${{ env.GCP_DOCKER_ARTIFACT_REPO }} |
| 92 | + WAIT_FOR_IMAGE_SECONDS: 1 |
| 93 | + |
| 94 | + - name: Set output |
| 95 | + id: set-output |
| 96 | + depends-on: check-images |
| 97 | + run: | |
| 98 | + if [ "${{ steps.check-images.outcome }}" = "success" ]; then |
| 99 | + echo "image-exist=true" >> $GITHUB_OUTPUT |
| 100 | + else |
| 101 | + echo "image-exist=false" >> $GITHUB_OUTPUT |
| 102 | + fi |
| 103 | + |
| 104 | + - name: Lock File Check and Lock if not exists |
| 105 | + id: check-lock |
| 106 | + if: steps.check-images.outcome == 'failure' |
| 107 | + run: | |
| 108 | + set +e |
| 109 | + gcloud storage ls gs://${{ env.GCP_DOCKER_BUILD_LOCK_BUCKET }}/${{ env.GIT_SHA }}.txt |
| 110 | + result=$? |
| 111 | + set -e |
| 112 | + if [ $result -eq 0 ]; then |
| 113 | + echo "Lock file exists: Current workflow building: " |
| 114 | + gcloud storage cat gs://${{ env.GCP_DOCKER_BUILD_LOCK_BUCKET }}/${{ env.GIT_SHA }}.txt |
| 115 | + echo "Rerun again when the image is finished building" && exit 1 |
| 116 | + else |
| 117 | + echo "Lock file does not exist" |
| 118 | + echo "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" > ${GIT_SHA}.txt |
| 119 | + gcloud storage cp ${GIT_SHA}.txt gs://${GCP_DOCKER_BUILD_LOCK_BUCKET}/${GIT_SHA}.txt |
| 120 | + echo "Docker Build locked" |
| 121 | + fi |
| 122 | +
|
75 | 123 | rust-all:
|
76 | 124 | runs-on: runs-on,cpu=64,family=c7,image=aptos-ubuntu-x64,run-id=${{ github.run_id }},spot=co,disk=large
|
| 125 | + needs: pre-build-validation |
| 126 | + if: needs.pre-build-validation.outputs.image-exist == 'false' |
77 | 127 | steps:
|
78 | 128 | - uses: actions/checkout@v4
|
79 | 129 | with:
|
@@ -118,4 +168,9 @@ jobs:
|
118 | 168 | sudo systemctl stop docker
|
119 | 169 | sudo tar --posix -cf /home/runner/docker-cache.tzst -P -C /var/lib/docker --use-compress-program zstdmt .
|
120 | 170 | fi
|
121 |
| -
|
| 171 | + |
| 172 | + - name: Post-run Lock Cleanup |
| 173 | + if: always() |
| 174 | + run: | |
| 175 | + gcloud storage rm gs://${{ env.GCP_DOCKER_BUILD_LOCK_BUCKET }}/${GIT_SHA}.txt || true |
| 176 | + echo "Docker Build unlocked" |
0 commit comments