Skip to content

Commit 7f3a409

Browse files
chore,ci: reduce frequency of scheduled docker image builds
Reduce amount of disk space we are costing GitHub. Currently we have 350+ tagged releases each more than 3GB, amounting to more than 1TB of storage. This should reduce out future usage in the long run GitHub actions run will be cancelled for this commit on master branch as it does not make any changes to the built docker image, and the docker image was just rebuilt in the previous commit for other unrelated reasons
1 parent 717095f commit 7f3a409

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

.github/workflows/docker_image.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,52 @@ jobs:
3333
steps:
3434
- name: Clone repository
3535
uses: actions/checkout@v6
36+
37+
# Skip building the Docker image on scheduled runs if the last successful
38+
# image build (the one tagged "latest") is less than IMAGE_MIN_INTERVAL_DAYS old.
39+
- name: Optionally skip building image
40+
if: github.event_name == 'schedule'
41+
id: skip-build
42+
env:
43+
IMAGE_MIN_INTERVAL_DAYS: 30
44+
run: |
45+
LAST_TIMESTAMP=$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
46+
-H "Accept: application/vnd.github+json" \
47+
"https://api.github.com/users/termux/packages/container/package-builder/versions" |
48+
jq --raw-output 'map(select(.metadata.container.tags | contains(["latest"])))[0].created_at')
49+
LAST_UNIX_TIME=$(date -d "$LAST_TIMESTAMP" +%s)
50+
CURRENT_UNIX_TIME=$(date +%s)
51+
if (( "$CURRENT_UNIX_TIME" - "$LAST_UNIX_TIME" < $IMAGE_MIN_INTERVAL_DAYS*24*60*60 )); then
52+
echo "Skipping building Docker image: last successful build was done on $LAST_TIMESTAMP (< $IMAGE_MIN_INTERVAL_DAYS days)"
53+
echo "skip-build=true" >> "$GITHUB_OUTPUT"
54+
fi
55+
3656
- name: Build
57+
if: ${{ steps.skip-build.outputs.skip-build != 'true' }}
3758
run: |
3859
docker build --tag termux/package-builder:latest scripts/
3960
docker tag termux/package-builder:latest ghcr.io/termux/package-builder:latest
4061
- name: Build (CGCT)
62+
if: ${{ steps.skip-build.outputs.skip-build != 'true' }}
4163
run: |
4264
docker build --tag termux/package-builder-cgct:latest --file scripts/Dockerfile.cgct scripts/
4365
docker tag termux/package-builder-cgct:latest ghcr.io/termux/package-builder-cgct:latest
4466
- name: Login to GHCR
45-
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-packages'
67+
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-packages' && steps.skip-build.outputs.skip-build != 'true'
68+
4669
uses: docker/login-action@v3
4770
with:
4871
registry: ghcr.io
4972
username: ${{ github.actor }}
5073
password: ${{ secrets.GITHUB_TOKEN }}
5174
- name: Login to Docker Hub
52-
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-packages'
75+
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-packages' && steps.skip-build.outputs.skip-build != 'true'
5376
uses: docker/login-action@v3
5477
with:
5578
username: grimler
5679
password: ${{ secrets.DOCKER_TOKEN }}
5780
- name: Push
58-
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-packages'
81+
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'termux/termux-packages' && steps.skip-build.outputs.skip-build != 'true'
5982
run: |
6083
# ghcr.io seem to be unstable sometimes. It may suddenly drop connection
6184
# during docker push when some layers are already uploaded. The workaround

0 commit comments

Comments
 (0)