forked from nansencenter/docker-nansat-base
-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (83 loc) · 3.02 KB
/
build_images.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
---
name: "Build Docker images"
on:
push:
branches: ['**']
release:
types: [released]
env:
IMAGE_NAME: "${{ secrets.DOCKER_ORG }}/nansat_base"
jobs:
build_docker_images:
runs-on: 'ubuntu-20.04'
strategy:
matrix:
version:
- {'python': '3.7', 'latest': true}
- {'python': '3.8', 'latest': false}
- {'python': '3.9', 'latest': false}
- {'python': '3.10', 'latest': false}
steps:
- name: 'Checkout repository'
uses: actions/checkout@v4
- name: "Extract tag name"
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]];then
TAG="${GITHUB_REF#refs/tags/}"
else
TAG='tmp'
fi
echo "VERSION=${TAG}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-python${{ matrix.version.python }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-python${{ matrix.version.python }}-
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Build standard docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
target: 'standard'
build-args: 'PYTHON_VERSION=${{ matrix.version.python }}'
push: ${{ startsWith(github.ref, 'refs/tags/') }}
tags: |
${{ env.IMAGE_NAME }}:latest-python${{ matrix.version.python }}
${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}-python${{ matrix.version.python }}
${{ matrix.version.latest && format('{0}:latest', env.IMAGE_NAME) || '' }}
cache-from: |
type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Build slim docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
target: 'slim'
build-args: 'PYTHON_VERSION=${{ matrix.version.python }}'
push: ${{ startsWith(github.ref, 'refs/tags/') }}
tags: |
${{ env.IMAGE_NAME }}:latest-slim-python${{ matrix.version.python }}
${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}-slim-python${{ matrix.version.python }}
${{ matrix.version.latest && format('{0}:latest-slim', env.IMAGE_NAME) || '' }}
cache-from: |
type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
...