-
Notifications
You must be signed in to change notification settings - Fork 6
134 lines (118 loc) · 4.94 KB
/
container_builds_weekly.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
name: Weekly wheel build images
on:
schedule:
- cron: "42 5 * * 1"
workflow_dispatch:
inputs:
use_cache:
description: Use GH Actions cache
type: boolean
required: false
default: true
env:
CONTAINER_REGISTRY: ghcr.io
jobs:
build_wheel_linux_dockers:
name: Build wheel containers
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
# 64-bit linux
- system: "manylinux"
type: "2010"
arch: "x86_64"
py_minors: "7 8 9"
- system: "manylinux"
type: "2014"
arch: "x86_64"
py_minors: "7 8 9 10 11"
- system: "musllinux"
type: "_1_1"
arch: "x86_64"
py_minors: "7 8 9 10 11"
# 32-bit linux
- system: "manylinux"
type: "2010"
arch: "i686"
py_minors: "7 8 9"
- system: "manylinux"
type: "2014"
arch: "i686"
py_minors: "7 8 9"
- system: "musllinux"
type: "_1_1"
arch: "i686"
py_minors: "7 8 9"
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- name: Setup cache
if: github.event_name != 'workflow_dispatch' || fromJSON(github.event.inputs.use_cache)
uses: actions/cache@v3
with:
path: .buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}
key: buildx-cache-${{ matrix.system }}${{ matrix.type }}-${{ matrix.arch }}-${{ github.sha }}
restore-keys: buildx-cache-${{ matrix.system }}${{ matrix.type }}-${{ matrix.arch }}-
- name: Check 'latest' parent image SHA
run: |
IMAGE=quay.io/pypa/${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}:latest
SHA_FILENAME=${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}:latest.sha.txt
docker pull ${IMAGE}
docker images --no-trunc --quiet ${IMAGE} > ${SHA_FILENAME}
CACHE_DIR=.buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}
if [ -f "${CACHE_DIR}/${SHA_FILENAME}" ] && [ "$( cat ${SHA_FILENAME} )" == "$( cat ${CACHE_DIR}/${SHA_FILENAME} )" ]; then
echo "BUILD_NEW_IMAGE=false" >> $GITHUB_ENV
else
echo "BUILD_NEW_IMAGE=true" >> $GITHUB_ENV
fi
- name: Create docker file
if: env.BUILD_NEW_IMAGE == 'true'
run: |
mkdir -p docker_build_wheel
EXTRA_PRE=""
EXTRA_POST=""
if [ "${{ matrix.type }}" == "2010" ]; then
EXTRA_PRE="COPY .github/docker/pgdg-91_${{ matrix.arch }}.repo /etc/yum.repos.d/pgdg-91.repo"
EXTRA_POST="ENV PATH=\$PATH:/usr/pgsql-9.1/bin"
fi
sed \
-e "s|{{ ARCH }}|${{ matrix.arch }}|" \
-e "s|{{ TYPE }}|${{ matrix.type }}|" \
-e "s|{{ EXTRA_PRE }}|${EXTRA_PRE}|" \
-e "s|{{ EXTRA_POST }}|${EXTRA_POST}|" \
.github/docker/Dockerfile-${{ matrix.system }}.template \
> docker_build_wheel/Dockerfile-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}
- name: Login to GitHub Container Registry
if: env.BUILD_NEW_IMAGE == 'true'
uses: docker/login-action@v2
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
if: env.BUILD_NEW_IMAGE == 'true'
uses: docker/build-push-action@v4
with:
context: .
file: docker_build_wheel/Dockerfile-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}
tags: ${{ env.CONTAINER_REGISTRY }}/sintef/dlite-python-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}:latest
push: true
build-args: |
PY_MINORS=${{ matrix.py_minors }}
cache-from: type=local,src=.buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}
cache-to: type=local,dest=.buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}-new,mode=max
# Temporary fix from https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
if: env.BUILD_NEW_IMAGE == 'true'
run: |
rm -rf .buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}
mv .buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}-new .buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}
- name: Add sha.txt to cache
if: env.BUILD_NEW_IMAGE == 'true'
run: mv ${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}:latest.sha.txt .buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}