-
Notifications
You must be signed in to change notification settings - Fork 68
116 lines (113 loc) · 3.29 KB
/
test-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
name: Docker Workflow
on: [pull_request,push]
jobs:
docker_test_and_deploy:
runs-on: ubuntu-latest
steps:
-
name: remove all docker images
run: |
docker rmi $(docker images -a -q)
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
-
name: Set environment variables
run: |
repo_owner=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
echo UNSTABLE_IMG=ghcr.io/${repo_owner}/pliers:unstable >> $GITHUB_ENV
echo EXEC_IMG=ghcr.io/${repo_owner}/pliersci:ci_exec >> $GITHUB_ENV
echo BUILDER_IMG=ghcr.io/${repo_owner}/pliersci:ci_build >> $GITHUB_ENV
echo DOC_IMG=ghcr.io/${repo_owner}/pliersci:ci_docs >> $GITHUB_ENV
echo TEST_IMG=ghcr.io/${repo_owner}/pliersci:ci_tests >> $GITHUB_ENV
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: check space and docker environment
run: |
df -h
docker images
-
name: Build the base image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/Dockerfile
target: builder
build-args: |
BUILDKIT_INLINE_CACHE=1
cache-from: |
type=registry,ref=${{ env.BUILDER_IMG }}
load: true
tags: ${{ env.BUILDER_IMG }}
-
name: check space and docker environment
run: |
df -h
docker images
-
name: Build executable image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/Dockerfile
target: executable
build-args: |
BUILDKIT_INLINE_CACHE=1
cache-from: |
type=registry,ref=${{ env.UNSTABLE_IMG }}
load: true
tags: |
${{ env.EXEC_IMG }}
${{ env.UNSTABLE_IMG }}
-
name: check space and docker environment
run: |
df -h
docker images
-
name: Build testing image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/Dockerfile
target: tests
build-args: |
BUILDKIT_INLINE_CACHE=1
cache-from: |
${{ env.EXEC_IMG }}
${{ env.BUILDER_IMG }}
load: true
tags: |
${{ env.TEST_IMG }}
-
name: check space and docker environment
run: |
df -h
docker images
-
name: Run tests
run: |
docker run ${{ env.TEST_IMG }}
-
name: Push to registry (if not pull request)
env:
CR_PAT: ${{ secrets.CR_PAT }}
run: |
if [ "${GITHUB_EVENT_NAME}" == "push" ] && [ ! -z "${CR_PAT}" ]; then
echo "${CR_PAT}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
docker push ${UNSTABLE_IMG} # push image for users
docker push ${BUILDER_IMG} # push image for build cache
# check if this is a release
ref_name=${GITHUB_REF##*/}
if [[ "${ref_name}" == v* ]]; then
release=${UNSTABLE_IMG/unstable/${ref_name}}
docker tag ${UNSTABLE_IMG} ${release}
docker push ${release}
fi
else
echo "pull request, not pushing"
fi