8
8
env :
9
9
IMAGE_NAME : " ${{ secrets.DOCKER_ORG }}/nansat_base"
10
10
jobs :
11
- build_standard_docker_image :
11
+ build_docker_images :
12
12
runs-on : ' ubuntu-20.04'
13
13
strategy :
14
14
matrix :
15
- versions :
16
- - {'python': '3.7', 'extra_tags': ['latest']}
17
- - {'python': '3.8', 'extra_tags': []}
18
- - {'python': '3.9', 'extra_tags': []}
19
- - {'python': '3.10', 'extra_tags': []}
15
+ image :
16
+ - dockerfile : Dockerfile
17
+ tag_suffix : ' '
18
+ multi_stage : false
19
+ - dockerfile : Dockerfile_slim
20
+ tag_suffix : ' -slim'
21
+ multi_stage : true
22
+ version :
23
+ - {'python': '3.7', 'latest': true}
24
+ - {'python': '3.8', 'latest': false}
25
+ - {'python': '3.9', 'latest': false}
26
+ - {'python': '3.10', 'latest': false}
20
27
steps :
21
28
- name : ' Checkout repository'
22
29
uses : actions/checkout@v4
@@ -25,11 +32,11 @@ jobs:
25
32
id : get_version
26
33
run : |
27
34
if [[ $GITHUB_REF == refs/tags/* ]];then
28
- TAG="${GITHUB_REF#refs/tags/}-python${{ matrix.versions.python }} "
35
+ TAG="${GITHUB_REF#refs/tags/}"
29
36
else
30
- TAG='tmp-python${{ matrix.versions.python }} '
37
+ TAG='tmp'
31
38
fi
32
- echo "::set-output name= VERSION:: ${TAG}"
39
+ echo "VERSION= ${TAG}" >> $GITHUB_OUTPUT
33
40
34
41
- name : Set up Docker Buildx
35
42
uses : docker/setup-buildx-action@v3
@@ -38,90 +45,44 @@ jobs:
38
45
uses : actions/cache@v3
39
46
with :
40
47
path : /tmp/.buildx-cache
41
- key : ${{ runner.os }}-buildx-standard- python${{ matrix.versions .python }}-${{ github.sha }}
48
+ key : ${{ runner.os }}-buildx${{ matrix.image.tag_suffix }}- python${{ matrix.version .python }}-${{ github.sha }}
42
49
restore-keys : |
43
- ${{ runner.os }}-buildx-standard- python${{ matrix.versions .python }}-
50
+ ${{ runner.os }}-buildx${{ matrix.image.tag_suffix }}- python${{ matrix.version .python }}-
44
51
45
52
- name : Login to DockerHub
46
53
uses : docker/login-action@v3
47
54
with :
48
55
username : ${{ secrets.DOCKER_USER }}
49
56
password : ${{ secrets.DOCKER_PASS }}
50
57
51
- - name : Build docker image
58
+ - name : Build builder image for multi-stage builds
59
+ if : ${{ matrix.image.multi_stage }}
52
60
uses : docker/build-push-action@v5
53
61
with :
54
62
context : .
55
- file : Dockerfile
56
- build-args : ' PYTHON_VERSION=${{ matrix.versions.python }}'
57
- push : ${{ startsWith(github.ref, 'refs/tags/') }}
63
+ file : ${{ matrix.image.dockerfile }}
64
+ build-args : ' PYTHON_VERSION=${{ matrix.version.python }}'
65
+ target : builder
66
+ push : false
58
67
tags : |
59
- ${{ env.IMAGE_NAME }}:latest-python${{ matrix.versions.python }}
60
- ${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}
61
- ${{ join(matrix.versions.extra_tags, '\n') }}
68
+ ${{ env.IMAGE_NAME }}:builder-${{ steps.get_version.outputs.VERSION }}${{ matrix.image.tag_suffix }}-python${{ matrix.version.python }}
62
69
cache-from : type=local,src=/tmp/.buildx-cache
63
70
cache-to : type=local,dest=/tmp/.buildx-cache-new
64
71
65
- # Temp fix
66
- # https://github.com/docker/build-push-action/issues/252
67
- # https://github.com/moby/buildkit/issues/1896
68
- - name : Move cache
69
- run : |
70
- rm -rf /tmp/.buildx-cache
71
- mv /tmp/.buildx-cache-new /tmp/.buildx-cache
72
-
73
- build_slim_docker_image :
74
- runs-on : ' ubuntu-20.04'
75
- strategy :
76
- matrix :
77
- versions :
78
- - {'python': '3.7', 'extra_tags': ['latest-slim']}
79
- - {'python': '3.8', 'extra_tags': []}
80
- - {'python': '3.9', 'extra_tags': []}
81
- - {'python': '3.10', 'extra_tags': []}
82
- steps :
83
- - name : ' Checkout repository'
84
- uses : actions/checkout@v4
85
-
86
- - name : " Extract tag name"
87
- id : get_version
88
- run : |
89
- if [[ $GITHUB_REF == refs/tags/* ]];then
90
- TAG="${GITHUB_REF#refs/tags/}-python${{ matrix.versions.python }}"
91
- else
92
- TAG='tmp-python${{ matrix.versions.python }}'
93
- fi
94
- echo "::set-output name=VERSION::${TAG}"
95
-
96
- - name : Set up Docker Buildx
97
- uses : docker/setup-buildx-action@v3
98
-
99
- - name : Cache Docker layers
100
- uses : actions/cache@v3
101
- with :
102
- path : /tmp/.buildx-cache
103
- key : ${{ runner.os }}-buildx-slim-python${{ matrix.versions.python }}-${{ github.sha }}
104
- restore-keys : |
105
- ${{ runner.os }}-buildx-slim-python${{ matrix.versions.python }}-
106
-
107
- - name : Login to DockerHub
108
- uses : docker/login-action@v3
109
- with :
110
- username : ${{ secrets.DOCKER_USER }}
111
- password : ${{ secrets.DOCKER_PASS }}
112
-
113
72
- name : Build docker image
114
73
uses : docker/build-push-action@v5
115
74
with :
116
75
context : .
117
- file : Dockerfile_slim
118
- build-args : ' PYTHON_VERSION=${{ matrix.versions .python }}'
76
+ file : ${{ matrix.image.dockerfile }}
77
+ build-args : ' PYTHON_VERSION=${{ matrix.version .python }}'
119
78
push : ${{ startsWith(github.ref, 'refs/tags/') }}
120
79
tags : |
121
- ${{ env.IMAGE_NAME }}:latest-slim-python${{ matrix.versions.python }}
122
- ${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}-slim
123
- ${{ join(matrix.versions.extra_tags, '\n') }}
124
- cache-from : type=local,src=/tmp/.buildx-cache
80
+ ${{ env.IMAGE_NAME }}:latest${{ matrix.image.tag_suffix }}-python${{ matrix.version.python }}
81
+ ${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}${{ matrix.image.tag_suffix }}-python${{ matrix.version.python }}
82
+ ${{ matrix.version.latest && format('latest{0}', matrix.image.tag_suffix) || '' }}
83
+ cache-from : |
84
+ type=local,src=/tmp/.buildx-cache
85
+ ${{ matrix.image.multi_stage && format('{0}:builder-{1}{2}-python{3}', env.IMAGE_NAME, steps.get_version.outputs.VERSION, matrix.image.tag_suffix, matrix.version.python) || '' }}
125
86
cache-to : type=local,dest=/tmp/.buildx-cache-new
126
87
127
88
# Temp fix
0 commit comments