Skip to content

Commit f23efb9

Browse files
committed
initial implementation
1 parent c2673bf commit f23efb9

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

.github/workflows/workflow-run-docker-rust-build.yaml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,64 @@ env:
6666
AWS_ECR_ACCOUNT_NUM: ${{ secrets.ENV_ECR_AWS_ACCOUNT_NUM }}
6767
GCP_DOCKER_ARTIFACT_REPO: ${{ vars.GCP_DOCKER_ARTIFACT_REPO }}
6868
TARGET_REGISTRY: ${{ inputs.TARGET_REGISTRY }}
69+
GCP_DOCKER_BUILD_LOCK_BUCKET: "aptos-docker-build-lock-bucket"
6970

7071
permissions:
7172
contents: read
7273
id-token: write #required for GCP Workload Identity federation which we use to login into Google Artifact Registry
7374

7475
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+
75123
rust-all:
76124
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'
77127
steps:
78128
- uses: actions/checkout@v4
79129
with:
@@ -118,4 +168,9 @@ jobs:
118168
sudo systemctl stop docker
119169
sudo tar --posix -cf /home/runner/docker-cache.tzst -P -C /var/lib/docker --use-compress-program zstdmt .
120170
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"

.github/workflows/workflow-run-replay-verify-on-archive.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ jobs:
5252
# we can optionally use the IMAGE_TAG to find the exact commit to checkout
5353
fetch-depth: 10
5454

55+
- name: Build Docker images
56+
uses: aptos-labs/aptos-core/.github/workflows/workflow-run-docker-rust-build.yaml@main
57+
with:
58+
GIT_SHA: ${{ env.IMAGE_TAG }}
59+
TARGET_CACHE_ID: ${{ github.ref_name }}
60+
5561
- uses: aptos-labs/aptos-core/.github/actions/docker-setup@main
5662
id: docker-setup
5763
with:

0 commit comments

Comments
 (0)