-
Notifications
You must be signed in to change notification settings - Fork 16
141 lines (121 loc) · 4.47 KB
/
docker-base-image.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
name: Check docker image
on:
schedule:
- cron: '20 4 * * *' # every day at 420 am
workflow_dispatch:
env:
IMAGE_NAME: gnzsnz/jupyter-quant
BASE_IMAGE: python
PLATFORMS: linux/amd64,linux/arm64
jobs:
check_base:
runs-on: ubuntu-latest
outputs:
needs-updating: ${{ steps.check.outputs.needs-updating }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get enviroment variables
run: |
grep -v '#' .env-dist | grep '=' > .env
while IFS= read -r line; do
echo $line >> $GITHUB_ENV ;
done < .env
- name: Check if update available
id: check
uses: lucacome/docker-image-update-checker@v1
with:
base-image: ${{ env.BASE_IMAGE }}:${{ env.PYTHON_VERSION }}-slim
image: ${{ env.IMAGE_NAME}}:${{ env.IMAGE_VERSION }}
platforms: ${{ env.PLATFORMS }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ env.PLATFORMS }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME }}
ghcr.io/${{ env.IMAGE_NAME }}
flavor: |
latest=true
- name: Build Docker image
uses: docker/build-push-action@v5
with:
push: false
load: false
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
build-args: |
USER=${{ env.USER }}
USER_ID=${{ env.USER_ID }}
USER_GID=${{ env.USER_GID }}
PYTHON_VERSION=${{ env.PYTHON_VERSION}}
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_VERSION }}
labels: ${{ steps.meta.outputs.labels }}
build:
runs-on: ubuntu-latest
needs: check_base
if: needs.check_base.outputs.needs-updating == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get enviroment variables
run: |
grep -v '#' .env-dist | grep '=' > .env
while IFS= read -r line; do
echo $line >> $GITHUB_ENV ;
done < .env
- name: Create issue
id: create_issue
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
title="Base images updates found for ${{ env.IMAGE_NAME }}:${{ env.IMAGE_VERSION }}"
body="A new build&publish might be needed."
exists=$(gh issue list -S "is:issue state:open in:title $title" | wc -l)
if [ -n "$exists" ] && [ "$exists" -gt 0 ]; then
echo "dup_issue=yes" >> $GITHUB_OUTPUT
else
gh issue create -t "$title" -b "$body"
echo "dup_issue=no" >> $GITHUB_OUTPUT
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
if: ${{ steps.create_issue.outputs.dup_issue == 'no' }}
with:
platforms: ${{ env.PLATFORMS }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
if: ${{ steps.create_issue.outputs.dup_issue == 'no' }}
- name: Docker metadata
id: meta
if: ${{ steps.create_issue.outputs.dup_issue == 'no' }}
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME }}
ghcr.io/${{ env.IMAGE_NAME }}
flavor: |
latest=true
- name: Build Docker image
uses: docker/build-push-action@v5
if: ${{ steps.create_issue.outputs.dup_issue == 'no' }}
with:
push: false
load: false
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
build-args: |
USER=${{ env.USER }}
USER_ID=${{ env.USER_ID }}
USER_GID=${{ env.USER_GID }}
PYTHON_VERSION=${{ env.PYTHON_VERSION}}
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_VERSION }}
labels: ${{ steps.meta.outputs.labels }}