-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (146 loc) · 5.96 KB
/
buildDockerImage.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
name: Build and push Docker image
on:
push:
paths:
- '.github/workflows/buildDockerImage.yml'
- 'Dockerfile'
- 'Dockerfile-base'
- 'Dockerfile-assets/**'
jobs:
buildAndPushImage:
name: Build and push Docker image
if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'allcontributors'"
runs-on: ubuntu-20.04
steps:
# Free disk space
# Inspiration
# - https://github.com/easimon/maximize-build-space/blob/master/action.yml
# - https://githubmemory.com/repo/ros-industrial/industrial_ci/issues/648
# - https://github.community/t/bigger-github-hosted-runners-disk-space/17267/11
- name: Maximize build space
run: |
sudo apt-get -qq purge build-essential ghc*
sudo apt-get clean
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
docker system prune -f
# checkout repository
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
# Build Docker image
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GHCR
uses: docker/login-action@v1
with:
registry: ghcr.io
username: "${{ secrets.DOCKER_REGISTRY_USERNAME }}"
password: "${{ secrets.DOCKER_REGISTRY_TOKEN }}"
- id: get-timestamp
name: Get timestamp
run: |
TIMESTAMP=$(date --rfc-3339=seconds | sed 's/ /T/')
echo "timestamp=$TIMESTAMP" >> $GITHUB_OUTPUT
- name: Copy Dockerfile to Dockerfile-assets
run: |
cp Dockerfile Dockerfile-assets/
cp Dockerfile-base Dockerfile-assets/
- name: Build base image
uses: docker/build-push-action@v2
with:
context: Dockerfile-assets
file: Dockerfile-base
pull: true
load: true
push: false
tags: |
ghcr.io/biosimulators/biosimulators-base:sha-${{github.sha}}
labels: |
org.opencontainers.image.revision=${{github.sha}}
org.opencontainers.image.created=${{steps.get-timestamp.outputs.timestamp}}"
cache-from: type=registry,ref=ghcr.io/biosimulators/biosimulators-base:buildcache
cache-to: type=registry,ref=ghcr.io/biosimulators/biosimulators-base:buildcache,mode=max
- name: Push base Docker image
run: docker image push ghcr.io/biosimulators/biosimulators-base:sha-${{github.sha}}
- name: Label base Docker image
run: docker image tag ghcr.io/biosimulators/biosimulators-base:sha-${{github.sha}} ghcr.io/biosimulators/biosimulators-base:latest
- name: Maximize build space
run: |
docker system prune -f
- name: Build image
uses: docker/build-push-action@v2
with:
context: Dockerfile-assets
file: Dockerfile
pull: false
load: true
push: false
tags: |
ghcr.io/biosimulators/biosimulators:sha-${{github.sha}}
labels: |
org.opencontainers.image.revision=${{github.sha}}
org.opencontainers.image.created=${{steps.get-timestamp.outputs.timestamp}}"
cache-from: type=registry,ref=ghcr.io/biosimulators/biosimulators:buildcache
cache-to: type=registry,ref=ghcr.io/biosimulators/biosimulators:buildcache,mode=max
- name: Push Docker image
run: docker image push ghcr.io/biosimulators/biosimulators:sha-${{github.sha}}
- name: Label Docker image
run: docker image tag ghcr.io/biosimulators/biosimulators:sha-${{github.sha}} ghcr.io/biosimulators/biosimulators:latest
- name: Maximize build space
run: |
docker system prune -f
# Test Docker image
- name: Test Docker image
run: |
cwd=$(pwd)
docker run \
--rm \
--entrypoint bash \
--mount type=bind,source=${cwd},target=/app/Biosimulators \
ghcr.io/biosimulators/biosimulators:latest \
-c "
pipenv install --dev --system --deploy
/bin/bash /xvfb-startup.sh python -m pytest --forked --verbose Biosimulators/tests/
"
# Get version number
- id: get-version-number
name: Get version number
if: startsWith(github.ref, 'refs/tags/')
env:
TAG: ${{ github.ref }}
run: |
version="${TAG/refs\/tags\//}"
echo "version=$version" >> $GITHUB_OUTPUT
# Create GitHub release
- name: Create GitHub release
if: startsWith(github.ref, 'refs/tags/')
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get-version-number.outputs.version }}
release_name: Release ${{ steps.get-version-number.outputs.version }}
# Push Docker image
- name: Push Docker image
if: startsWith(github.ref, 'refs/tags/')
env:
VERSION: ${{ steps.get-version-number.outputs.version }}
run: |
docker image tag ghcr.io/biosimulators/biosimulators-base:sha-${{github.sha}} ghcr.io/biosimulators/biosimulators-base:${VERSION}
docker image tag ghcr.io/biosimulators/biosimulators:sha-${{github.sha}} ghcr.io/biosimulators/biosimulators:${VERSION}
docker push ghcr.io/biosimulators/biosimulators-base:${VERSION}
docker push ghcr.io/biosimulators/biosimulators-base:latest
docker push ghcr.io/biosimulators/biosimulators:${VERSION}
docker push ghcr.io/biosimulators/biosimulators:latest