-
-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Free space and repeatability for the Docker Hub workflow #36716
Merged
vbraun
merged 7 commits into
sagemath:develop
from
soehms:free_space_on_docker_hub_workflow
Dec 10, 2023
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b23f4ce
free_space_on_docker_hub_workflow initial
soehms dc6b557
Merge branch 'sagemath:develop' into free_space_on_docker_hub_workflow
soehms 4ab880e
Merge branch 'sagemath:develop' into free_space_on_docker_hub_workflow
soehms badc523
Merge branch 'develop' into free_space_on_docker_hub_workflow
soehms 96de804
Match all release tags
soehms 0b5984a
Merge branch 'develop' into free_space_on_docker_hub_workflow
soehms a1a32ab
Merge branch 'sagemath:develop' into free_space_on_docker_hub_workflow
soehms File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Reusable workflow for Docker Hub images | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
dockerhub_repository: | ||
default: sagemath-dev | ||
type: string | ||
dockerfile_target: | ||
default: make-build | ||
type: string | ||
|
||
jobs: | ||
build-and-push: | ||
name: Build Docker image and push to DockerHub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Maximize build disk space | ||
uses: easimon/maximize-build-space@v8 | ||
with: | ||
# need space in /var for Docker images | ||
root-reserve-mb: 40000 | ||
remove-dotnet: true | ||
remove-android: true | ||
remove-haskell: true | ||
remove-codeql: true | ||
remove-docker-images: true | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set tag | ||
# docker/metadata-action@v4 is not used since we need to distinguish | ||
# between latest and develop tags | ||
id: set_tag | ||
run: | | ||
git fetch --depth=1 origin +refs/tags/*:refs/tags/* | ||
TAG_NAME=$(git tag --sort=creatordate | tail -1) | ||
REPO=${{ inputs.dockerhub_repository }} | ||
# see if the tag has already been pushed | ||
# if yes then skip following steps | ||
URL="https://registry.hub.docker.com/v2/repositories/sagemath/$REPO/tags?page_size=32" | ||
LATEST_TAGS=$(curl -L -s $URL | jq '."results"[]["name"]') | ||
JOB_DONE=false | ||
for i in $LATEST_TAGS; do if [[ $i == \"$TAG_NAME\" ]]; then JOB_DONE=true; break; fi done | ||
echo "JOB_DONE=$JOB_DONE" >> $GITHUB_ENV | ||
|
||
if [[ $JOB_DONE == 'false' ]] | ||
then | ||
TAG="sagemath/$REPO:$TAG_NAME" | ||
TAG_LIST="$TAG, sagemath/$REPO:develop" | ||
BASE="sagemath/sagemath-dev:$TAG_NAME" | ||
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | ||
echo "TAG=$TAG" >> $GITHUB_ENV | ||
echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV | ||
echo "BASE=$BASE" >> $GITHUB_ENV | ||
fi | ||
df -h | ||
|
||
- name: Update Tag List | ||
id: upd_tag_list | ||
run: | | ||
REPO=${{ inputs.dockerhub_repository }} | ||
TAG_LIST="${{ env.TAG_LIST }}, sagemath/$REPO:latest" | ||
echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV | ||
if: "env.JOB_DONE == 'false' && !contains(env.TAG_NAME, 'beta') && !contains(env.TAG_NAME, 'rc')" | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
if: env.JOB_DONE == 'false' | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
if: env.JOB_DONE == 'false' | ||
|
||
- name: Build and push make-build | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: docker/Dockerfile | ||
target: ${{ inputs.dockerfile_target }} | ||
build-args: | | ||
MAKE_BUILD=${{ env.BASE }} | ||
push: true | ||
tags: ${{ env.TAG_LIST }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
if: env.JOB_DONE == 'false' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to use a pattern that matches our release tags only, as we do in https://github.com/sagemath/sage/blob/develop/.github/workflows/dist.yml#L6
(I frequently push other tags to my repository for triggering CI runs, and currently this triggers a failing Docker Hub workflow.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!