This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
235 lines (230 loc) · 9.34 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Reusable workflow for Docker-based portability CI
on:
workflow_call:
inputs:
targets_pre:
default: build/make/Makefile
type: string
targets:
default: build/make/Makefile
type: string
targets_optional:
default: build/make/Makefile
type: string
tox_system_factors:
description: 'Stringified JSON object listing tox system factors'
type: string
default: >-
["ubuntu-trusty-toolchain-gcc_9",
"ubuntu-xenial-toolchain-gcc_9",
"ubuntu-bionic-gcc_8",
"ubuntu-focal",
"ubuntu-jammy",
"ubuntu-kinetic",
"debian-buster",
"debian-bullseye",
"debian-bookworm",
"debian-sid",
"linuxmint-19-gcc_8",
"linuxmint-19.3-gcc_8",
"linuxmint-20.1",
"linuxmint-20.2",
"linuxmint-20.3",
"linuxmint-21",
"fedora-29",
"fedora-30",
"fedora-31",
"fedora-32",
"fedora-33",
"fedora-34",
"fedora-35",
"fedora-36",
"fedora-37",
"centos-7-devtoolset-gcc_11",
"centos-stream-8",
"centos-stream-9",
"gentoo-python3.9",
"gentoo-python3.10",
"archlinux-latest",
"opensuse-15.3-gcc_11",
"opensuse-15.4-gcc_11",
"opensuse-tumbleweed",
"conda-forge",
"ubuntu-bionic-i386",
"manylinux-2_24-i686",
"debian-buster-i386",
]
tox_packages_factors:
description: 'Stringified JSON object listing tox packages factors'
type: string
default: >-
["minimal",
"standard",
]
max_parallel:
type: number
default: 24
#
# Publishing to GitHub Packages
#
docker_push_repository:
required: false
type: string
#
# Incremental builds
#
docker_targets:
default: "with-system-packages configured with-targets-pre with-targets with-targets-optional"
type: string
incremental:
default: false
type: boolean
from_docker_repository:
required: false
type: string
from_docker_target:
required: false
type: string
from_docker_tag:
required: false
default: "$BUILD_TAG"
type: string
#
# For use in upstream CIs
#
upstream_artifact:
required: false
type: string
sage_repo:
required: false
type: string
sage_trac_git:
required: false
type: string
sage_trac_ticket:
required: false
type: string
sage_ref:
required: false
type: string
jobs:
linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: ${{ inputs.max_parallel }}
matrix:
tox_system_factor: ${{ fromJson(inputs.tox_system_factors) }}
tox_packages_factor: ${{ fromJson(inputs.tox_packages_factors) }}
env:
TOX_ENV: "docker-${{ matrix.tox_system_factor }}-${{ matrix.tox_packages_factor }}${{ inputs.incremental && '-incremental' || '' }}"
LOGS_ARTIFACT_NAME: logs-commit-${{ github.sha }}-tox-docker-${{ matrix.tox_system_factor }}-${{ matrix.tox_packages_factor }}
DOCKER_TARGETS: ${{ inputs.docker_targets }}
TARGETS_PRE: ${{ inputs.targets_pre }}
TARGETS: ${{ inputs.targets }}
TARGETS_OPTIONAL: ${{ inputs.targets_optional }}
FROM_DOCKER_REPOSITORY: ${{ inputs.from_docker_repository }}
FROM_DOCKER_TARGET: ${{ inputs.from_docker_target }}
FROM_DOCKER_TAG: ${{ inputs.from_docker_tag }}
steps:
- name: Check out SageMath
uses: actions/checkout@v2
with:
repository: ${{ inputs.sage_repo }}
ref: ${{ inputs.sage_ref }}
fetch-depth: 2000
- name: fetch tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: free disk space
run: |
df -h
sudo swapoff -a
sudo rm -f /swapfile
sudo apt-get clean
docker rmi $(docker image ls -aq)
echo "Largest packages:"
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 50
sudo apt-get --fix-broken --yes remove $(dpkg-query -f '${Package}\n' -W | grep -E '^(ghc-|google-cloud-sdk|google-chrome|firefox|mysql-server|dotnet-sdk|hhvm|mono)') || echo "(error ignored)"
df -h
- name: Check out git-trac-command
uses: actions/checkout@v2
with:
repository: sagemath/git-trac-command
path: git-trac-command
if: inputs.sage_trac_git != ''
- name: Check out SageMath from trac.sagemath.org
shell: bash {0}
# Random sleep and retry to limit the load on trac.sagemath.org
run: |
git config --global user.email "ci-sage@example.com"
git config --global user.name "ci-sage workflow"
if [ ! -d .git ]; then git init; fi; git remote add trac ${{ inputs.sage_trac_git }} && x=1 && while [ $x -le 5 ]; do x=$(( $x + 1 )); sleep $(( $RANDOM % 60 + 1 )); if git-trac-command/git-trac fetch ${{ inputs.sage_trac_ticket }}; then git merge FETCH_HEAD || echo "(ignored)"; exit 0; fi; sleep 40; done; exit 1
if: inputs.sage_trac_git != ''
- name: Download upstream artifact
uses: actions/download-artifact@v2
with:
path: upstream
name: ${{ inputs.upstream_artifact }}
if: inputs.upstream_artifact
- name: Install test prerequisites
run: |
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install tox
sudo apt-get clean
df -h
- name: Update Sage packages from upstream artifact
run: |
(export PATH=$(pwd)/build/bin:$PATH; (cd upstream && bash -x update-pkgs.sh) && sed -i.bak '/upstream/d' .dockerignore && echo "/:toolchain:/i ADD upstream upstream" | sed -i.bak -f - build/bin/write-dockerfile.sh && git diff)
if: inputs.upstream_artifact
- name: Try to login to ghcr.io
if: inputs.docker_push_repository != ''
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
run: |
TOKEN="${{ secrets.DOCKER_PKG_GITHUB_TOKEN }}"
if [ -z "$TOKEN" ]; then
TOKEN="${{ secrets.GITHUB_TOKEN }}"
fi
if echo "$TOKEN" | docker login ghcr.io -u ${{ github.actor }} --password-stdin; then
echo "DOCKER_PUSH_REPOSITORY=${{ inputs.docker_push_repository }}" >> $GITHUB_ENV
echo "DOCKER_CONFIG_FILE=$HOME/.docker/config.json" >> $GITHUB_ENV
fi
# From the docker documentation via .ci/update-env.sh:
# "A tag name must be valid ASCII and may
# contain lowercase and uppercase letters, digits, underscores, periods and
# dashes. A tag name may not start with a period or a dash and may contain a
# maximum of 128 characters."
EXTRA_DOCKER_TAGS=`echo $GITHUB_REF_NAME | tr -d '[:space:]' | tr -c '[:alnum:]_.-' '-' | sed 's/^[-.]*//' | cut -c1-128`
shopt -s extglob
case "$GITHUB_REF_NAME" in
+([0-9]).+([0-9])?(.+([0-9])) )
EXTRA_DOCKER_TAGS="latest dev $EXTRA_DOCKER_TAGS";;
+([0-9]).+([0-9])?(.+([0-9]))?(.)@(a|alpha|b|beta|rc)+([0-9]) )
EXTRA_DOCKER_TAGS="dev $EXTRA_DOCKER_TAGS";;
esac
echo "EXTRA_DOCKER_TAGS=$EXTRA_DOCKER_TAGS" >> $GITHUB_ENV
- name: Configure and build Sage distribution within a Docker container
run: |
set -o pipefail; EXTRA_DOCKER_BUILD_ARGS="--build-arg NUMPROC=4 --build-arg USE_MAKEFLAGS=\"-k V=0 SAGE_NUM_THREADS=3\"" tox -e $TOX_ENV -- $TARGETS 2>&1 | sed "/^configure: notice:/s|^|::warning file=artifacts/$LOGS_ARTIFACT_NAME/config.log::|;/^configure: warning:/s|^|::warning file=artifacts/$LOGS_ARTIFACT_NAME/config.log::|;/^configure: error:/s|^|::error file=artifacts/$LOGS_ARTIFACT_NAME/config.log::|;"
- name: Copy logs from the Docker image or build container
run: |
mkdir -p "artifacts/$LOGS_ARTIFACT_NAME"
cp -r .tox/$TOX_ENV/Dockerfile .tox/$TOX_ENV/log "artifacts/$LOGS_ARTIFACT_NAME"
if [ -f .tox/$TOX_ENV/Dockertags ]; then CONTAINERS=$(docker create $(tail -1 .tox/$TOX_ENV/Dockertags) /bin/bash || true); fi
if [ -n "$CONTAINERS" ]; then for CONTAINER in $CONTAINERS; do for ARTIFACT in /sage/logs; do docker cp $CONTAINER:$ARTIFACT artifacts/$LOGS_ARTIFACT_NAME && HAVE_LOG=1; done; if [ -n "$HAVE_LOG" ]; then break; fi; done; fi
if: always()
- uses: actions/upload-artifact@v2
with:
path: artifacts
name: ${{ env.LOGS_ARTIFACT_NAME }}
if: always()
- name: Print out logs for immediate inspection
# and markup the output with GitHub Actions logging commands
run: |
.github/workflows/scan-logs.sh "artifacts/$LOGS_ARTIFACT_NAME"
if: always()
- name: List docker images
run: |
if [ -f .tox/$TOX_ENV/Dockertags ]; then
cat .tox/$TOX_ENV/Dockertags
fi
if: always()