Skip to content

Commit 478c0ef

Browse files
committed
workflow_docker_hub initial
1 parent 0fd5967 commit 478c0ef

File tree

2 files changed

+149
-5
lines changed

2 files changed

+149
-5
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# This workflow replaces $SAGE_ROOT/.gitlab-ci.yml which has been
2+
# used formerly to make Docker images available on DockerHub.
3+
# The new workflow uses the same $SAGE_ROOT/docker/Dockerfile and
4+
# is based on docker/build-push-action@v4.
5+
#
6+
# A replacement has become neccessary because the GitLab runners
7+
# stopped to create new images since release 9.7.
8+
#
9+
# Concerning the images placed in the sagemath-dev repository you
10+
# should note the following difference to the releases build before
11+
# 9.8: They are no longer build on target sagemath-dev since this
12+
# causes a "No space left on device" error. Instead they are build
13+
# on target make-build, now. The main difference is the missing
14+
# documentation and that it enters in a bash shell.
15+
#
16+
# Sebastian Oehms, August 2023
17+
18+
name: Build Docker images and push to DockerHub
19+
20+
on:
21+
workflow_dispatch:
22+
# Allow to run manually
23+
branches:
24+
- 'develop'
25+
- 'docker_hub_gha'
26+
push:
27+
tags:
28+
# Just create image on pushing a tag
29+
- '*'
30+
31+
jobs:
32+
sagemath-dev:
33+
name: Build Docker image on target make-build and push to DockerHub sagemath-dev
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v3
38+
39+
- name: Set tag
40+
# docker/metadata-action@v4 is not used since we need to distinguish
41+
# between latest and develop tags
42+
id: set_tag
43+
run: |
44+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
45+
TAG_NAME=$(git tag --sort=v:refname | tail -1)
46+
TAG="sagemath/sagemath-dev:$TAG_NAME"
47+
TAG_LIST="$TAG, sagemath/sagemath-dev:develop"
48+
TAG_LIST="$TAG" # don't tag develop until meaning of sagemath-dev is clear
49+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
50+
echo "TAG=$TAG" >> $GITHUB_ENV
51+
echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV
52+
53+
- name: Update Tag List
54+
id: upd_tag_list
55+
run: |
56+
TAG_LIST="${{ env.TAG_LIST }}, sagemath/sagemath-dev:latest"
57+
TAG_LIST="${{ env.TAG_LIST }}" # don't tag latest until meaning of sagemath-dev is clear
58+
echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV
59+
if: "!contains(env.TAG_NAME, 'beta') && !contains(env.TAG_NAME, 'rc')"
60+
61+
- name: Check env
62+
run: |
63+
echo ${{ env.TAG_NAME }}
64+
echo ${{ env.TAG }}
65+
echo ${{ env.TAG_LIST }}
66+
67+
- name: Set up QEMU
68+
uses: docker/setup-qemu-action@v2
69+
70+
- name: Set up Docker Buildx
71+
uses: docker/setup-buildx-action@v2
72+
73+
- name: Login to Docker Hub
74+
uses: docker/login-action@v2
75+
with:
76+
username: ${{ secrets.DOCKERHUB_USERNAME }}
77+
password: ${{ secrets.DOCKERHUB_TOKEN }}
78+
79+
- name: Build and push make-build
80+
uses: docker/build-push-action@v4
81+
with:
82+
context: .
83+
file: docker/Dockerfile
84+
target: make-build # see the corresponding header-note
85+
push: true
86+
tags: ${{ env.TAG_LIST }}
87+
cache-from: type=gha
88+
cache-to: type=gha,mode=max
89+
90+
sagemath:
91+
needs: sagemath-dev
92+
name: Build Docker image on target sagemath and push to DockerHub sagemath
93+
runs-on: ubuntu-latest
94+
steps:
95+
- name: Checkout
96+
uses: actions/checkout@v3
97+
98+
- name: Set tag
99+
# docker/metadata-action@v4 is not used since we need to distinguish
100+
# between latest and develop tags
101+
id: set_tag
102+
run: |
103+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
104+
TAG_NAME=$(git tag --sort=v:refname | tail -1)
105+
TAG="sagemath/sagemath:$TAG_NAME"
106+
TAG_LIST="$TAG, sagemath/sagemath:develop"
107+
BASE="sagemath/sagemath-dev:$TAG_NAME"
108+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
109+
echo "TAG=$TAG" >> $GITHUB_ENV
110+
echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV
111+
echo "BASE=$BASE" >> $GITHUB_ENV
112+
113+
- name: Update Tag List
114+
id: upd_tag_list
115+
run: |
116+
TAG_LIST="${{ env.TAG_LIST }}, sagemath/sagemath:latest"
117+
echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV
118+
if: "!contains(env.TAG_NAME, 'beta') && !contains(env.TAG_NAME, 'rc')"
119+
120+
- name: Set up QEMU
121+
uses: docker/setup-qemu-action@v2
122+
123+
- name: Set up Docker Buildx
124+
uses: docker/setup-buildx-action@v2
125+
126+
- name: Login to Docker Hub
127+
uses: docker/login-action@v2
128+
with:
129+
username: ${{ secrets.DOCKERHUB_USERNAME }}
130+
password: ${{ secrets.DOCKERHUB_TOKEN }}
131+
132+
- name: Build and push sagemath
133+
uses: docker/build-push-action@v4
134+
with:
135+
context: .
136+
file: docker/Dockerfile
137+
build-args: |
138+
MAKE_BUILD=${{ env.BASE }}
139+
target: sagemath
140+
push: true
141+
tags: ${{ env.TAG_LIST }}
142+
cache-from: type=gha
143+
cache-to: type=gha,mode=max

docker/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@
7070

7171

7272
ARG ARTIFACT_BASE=source-clean
73+
ARG MAKE_BUILD=make-build
7374

7475
################################################################################
7576
# Image containing the run-time dependencies for Sage #
7677
################################################################################
77-
FROM ubuntu:jammy as run-time-dependencies
78+
FROM ubuntu:latest as run-time-dependencies
7879
LABEL maintainer="Erik M. Bray <[email protected]>, Julian Rüth <[email protected]>"
7980
# Set sane defaults for common environment variables.
8081
ENV LC_ALL C.UTF-8
@@ -122,7 +123,7 @@ ARG SAGE_ROOT=/home/sage/sage
122123
RUN mkdir -p "$SAGE_ROOT"
123124
WORKDIR $SAGE_ROOT
124125
RUN git init
125-
RUN git remote add trac https://gitlab.com/sagemath/dev/tracmirror.git
126+
RUN git remote add upstream https://github.com/sagemath/sage.git
126127

127128
################################################################################
128129
# Image with the build context added, i.e., the directory from which `docker #
@@ -155,10 +156,10 @@ WORKDIR $SAGE_ROOT
155156
# We create a list of all files present in the artifact-base (with a timestamp
156157
# of now) so we can find out later which files were added/changed/removed.
157158
RUN find . \( -type f -or -type l \) > $HOME/artifact-base.manifest
158-
RUN git fetch "$HOME/sage-context" HEAD \
159+
RUN git fetch --update-shallow "$HOME/sage-context" HEAD \
159160
&& if [ -e docker/.commit ]; then \
160161
git reset `cat docker/.commit` \
161-
|| ( echo "Could not find commit `cat docker/.commit` in your local Git history. Please merge in the latest built develop branch to fix this: git fetch trac && git merge `cat docker/.commit`." && exit 1 ) \
162+
|| ( echo "Could not find commit `cat docker/.commit` in your local Git history. Please merge in the latest built develop branch to fix this: git fetch upstream && git merge `cat docker/.commit`." && exit 1 ) \
162163
else \
163164
echo "You are building from $ARTIFACT_BASE which has no docker/.commit file. That's a bug unless you are building from source-clean or something similar." \
164165
&& git reset FETCH_HEAD \
@@ -203,7 +204,7 @@ RUN make build
203204
################################################################################
204205
# Image with a full build of sage and its documentation. #
205206
################################################################################
206-
FROM make-build as make-all
207+
FROM $MAKE_BUILD as make-all
207208
# The docbuild needs quite some RAM (as of May 2018). It sometimes calls
208209
# os.fork() to spawn an external program which then exceeds easily the
209210
# overcommit limit of the system (no RAM is actually used, but this limit is

0 commit comments

Comments
 (0)