-
Notifications
You must be signed in to change notification settings - Fork 3
184 lines (159 loc) · 6.22 KB
/
build-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
name: 🐳 Build Docker images for current branches
# on commits to this file, schedule and dispatch runs, the workflow will build the 3 different Docker images (master, PR, LTR)
# on tags, it will build only the image of the given tag
# this is made by using a matrix defined in a dedicated job
on:
push:
tags:
- final-*
branches:
- master
paths:
- .github/workflows/build-docker.yml
schedule:
# runs every day
- cron: '0 0 * * *'
workflow_dispatch:
# POST https://api.github.com/repos/qgis/QGIS/actions/workflows/2264135/dispatches:
permissions:
contents: read
jobs:
define-strategy:
permissions:
contents: none
if: github.repository_owner == 'qgis'
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- id: matrix
run: |
if [[ "${GITHUB_REF}" =~ ^refs/tags ]]; then
echo "matrix={\"branch\":[\"${GITHUB_REF##*/}\"]}" >> $GITHUB_OUTPUT
else
echo "matrix={\"branch\":[\"master\", \"release-3_30\", \"release-3_28\"]}" >> $GITHUB_OUTPUT
fi
build-docker:
if: github.repository_owner == 'qgis'
runs-on: ubuntu-latest
needs: define-strategy
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
CC: /usr/lib/ccache/gcc
CXX: /usr/lib/ccache/g++ # Building SIP binding freezes with Clang in Docker, maybe a SIP issue, maybe not
DOCKER_BUILD_DEPS_FILE: qgis3-qt5-build-deps.dockerfile
strategy:
fail-fast: false
matrix: ${{ fromJSON( needs.define-strategy.outputs.matrix ) }}
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
tool-cache: true
large-packages: true
docker-images: false
swap-storage: true
- name: Free additional space
run: |
df -h
rm -rf /tmp/workspace
rm -rf /usr/share/dotnet/sdk
sudo apt remove llvm-* ghc-* google-chrome-* dotnet-sdk-*
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 100
du -a /usr/share | sort -n -r | head -n 10
du -a /usr/local/share | sort -n -r | head -n 10
df -h
sudo apt clean
df -h
- name: Cache
id: cache
uses: actions/[email protected]
with:
path: ~/.ccache
key: docker-build-${{ matrix.branch }}-${{ github.sha }}
restore-keys: |
docker-build-${{ matrix.branch }}-
docker-build-master-
- name: checkout ${{ matrix.branch }}
uses: actions/checkout@v3
with:
ref: ${{ matrix.branch }}
- name: Define vars
env:
branch: ${{ matrix.branch }}
run: |
export DOCKER_TAG=${branch//master/latest}
export DOCKER_DEPS_TAG=${DOCKER_TAG}
# add vars for next steps
echo "DOCKER_TAG=${DOCKER_TAG}" >> $GITHUB_ENV
echo "DOCKER_DEPS_TAG=${DOCKER_DEPS_TAG}" >> $GITHUB_ENV
echo "branch: ${branch}"
echo "docker tag: ${DOCKER_TAG}"
echo "docker deps tag: ${DOCKER_DEPS_TAG}"
- name: Copy cache
run: |
[[ -d ~/.ccache ]] && echo "cache directory (~/.ccache) exists" || mkdir -p ~/.ccache
# copy ccache dir within QGIS source so it can be accessed from docker
cp -r ~/.ccache/. ./.ccache_image_build
- name: QGIS deps Docker pull/rebuild
run: |
cd .docker
docker --version
docker pull "qgis/qgis3-build-deps:${DOCKER_DEPS_TAG}" || true
docker build --cache-from "qgis/qgis3-build-deps:${DOCKER_DEPS_TAG}" -t "qgis/qgis3-build-deps:${DOCKER_DEPS_TAG}" -f ${DOCKER_BUILD_DEPS_FILE} .
echo "push to qgis/qgis3-build-deps:${DOCKER_DEPS_TAG}"
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
docker push "qgis/qgis3-build-deps:${DOCKER_DEPS_TAG}"
- name: Docker QGIS build
run: |
cd .docker
DOCKER_BUILD_ARGS="--build-arg DOCKER_DEPS_TAG --build-arg CC --build-arg CXX"
docker build ${DOCKER_BUILD_ARGS} \
--cache-from "qgis/qgis:${DOCKER_TAG}" \
-t "qgis/qgis:BUILDER" \
-f qgis.dockerfile ..
- name: Tag container and copy cache
run: |
docker run --name qgis_container qgis/qgis:BUILDER /bin/true
docker cp qgis_container:/QGIS/build_exit_value ./build_exit_value
if [[ $(cat ./build_exit_value) != "OK" ]]; then
echo "Build failed, not pushing image"
exit 1
fi
echo "Copy build cache from Docker container to Travis cache directory"
rm -rf ~/.ccache/*
mkdir -p ~/.ccache
docker cp qgis_container:/QGIS/.ccache_image_build/. ~/.ccache
echo "Cache size: "$(du -sh ~/.ccache)
- name: Finalize image
run: |
cd .docker
# enable experimental features in Docker to squash
echo '{ "experimental": true}' | sudo tee /etc/docker/daemon.json
sudo service docker restart
docker build ${DOCKER_BUILD_ARGS} \
--cache-from "qgis/qgis:BUILDER" \
--squash \
-t "qgis/qgis:${DOCKER_TAG}" \
-f qgis.dockerfile ..
- name: Pushing image to docker hub
run: |
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
docker push "qgis/qgis:${DOCKER_TAG}"
- name: Trigger PyQGIS API docs build for ${{ matrix.branch }}
if: success() && !startsWith(github.ref, 'refs/tags/')
env:
branch: ${{ matrix.branch }}
run: |
body='{
"ref": "master",
"inputs": {"qgis_branch": "__QGIS_VERSION_BRANCH__"}
}'
body=$(sed "s/__QGIS_VERSION_BRANCH__/${branch}/;" <<< $body)
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${GH_TOKEN}" \
https://api.github.com/repos/qgis/pyqgis/actions/workflows/2246440/dispatches \
-d "${body}"