Skip to content
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
merged 7 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 0 additions & 23 deletions .ci/describe-system.sh

This file was deleted.

40 changes: 0 additions & 40 deletions .ci/protect-secrets.sh

This file was deleted.

91 changes: 91 additions & 0 deletions .github/workflows/docker_hub.yml
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'
112 changes: 16 additions & 96 deletions .github/workflows/push_to_docker_hub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,106 +7,26 @@ on:
- 'develop'
push:
tags:
# Just create image on pushing a tag
# Create images on pushing a tag
- '*'
Copy link
Member

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.)

Copy link
Member Author

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.)

Done!

schedule:
# Recover failed runs each Tuesday and Thursday at one o'clock
- cron: '0 1 * * 2,4'

jobs:
sagemath-dev:
name: Build Docker image on target make-build and push to DockerHub sagemath-dev
# target make-build replaces former sagemath-dev, see https://github.com/sagemath/sage/pull/36047
runs-on: ubuntu-latest
steps:
- 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)
TAG="sagemath/sagemath-dev:$TAG_NAME"
TAG_LIST="$TAG, sagemath/sagemath-dev:develop"
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
echo "TAG=$TAG" >> $GITHUB_ENV
echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV

- name: Update Tag List
id: upd_tag_list
run: |
TAG_LIST="${{ env.TAG_LIST }}, sagemath/sagemath-dev:latest"
echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV
if: "!contains(env.TAG_NAME, 'beta') && !contains(env.TAG_NAME, 'rc')"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push make-build
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
target: make-build # see the corresponding header-note
push: true
tags: ${{ env.TAG_LIST }}
cache-from: type=gha
cache-to: type=gha,mode=max
uses: ./.github/workflows/docker_hub.yml
with:
# Build from scratch
dockerhub_repository: sagemath-dev
dockerfile_target: make-build
secrets: inherit

sagemath:
needs: sagemath-dev
name: Build Docker image on target sagemath and push to DockerHub sagemath
runs-on: ubuntu-latest
steps:
- 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)
TAG="sagemath/sagemath:$TAG_NAME"
TAG_LIST="$TAG, sagemath/sagemath: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

- name: Update Tag List
id: upd_tag_list
run: |
TAG_LIST="${{ env.TAG_LIST }}, sagemath/sagemath:latest"
echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV
if: "!contains(env.TAG_NAME, 'beta') && !contains(env.TAG_NAME, 'rc')"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push sagemath
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
build-args: |
MAKE_BUILD=${{ env.BASE }}
target: sagemath
push: true
tags: ${{ env.TAG_LIST }}
cache-from: type=gha
cache-to: type=gha,mode=max
uses: ./.github/workflows/docker_hub.yml
with:
# Build from sagemath-dev
dockerhub_repository: sagemath
dockerfile_target: sagemath
secrets: inherit