-
Notifications
You must be signed in to change notification settings - Fork 2
135 lines (120 loc) · 3.94 KB
/
dockerimage.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
name: Docker Image CI
on:
push:
branches:
- master
tags:
- release.*
env:
GIT_SHA: ${{ github.sha }}
REG_HOST: ${{ secrets.DOCKER_REGISTRY_HOST }}
REG_PATH: ${{ secrets.DOCKER_REGISTRY_PATH }}
REG_USER: ${{ secrets.DOCKER_USERNAME }}
REG_PASS: ${{ secrets.DOCKER_PASSWORD }}
#REG_HOST: ghcr.io
#REG_PATH: ${{ github.repository }}
#REG_USER: ${{ github.actor }}
#REG_PASS: ${{ secrets.GITHUB_TOKEN }}
jobs:
needs-ghcr:
runs-on: ubuntu-latest
outputs:
also_ghcr: ${{ steps.check.outputs.also_ghcr }}
steps:
- id: check
env:
MY_KEY: ${{ secrets.ALSO_GHCR }}
if: "${{ env.MY_KEY != '' }}"
run: echo "also_ghcr=true" >> $GITHUB_OUTPUT
modified-folders:
runs-on: ubuntu-latest
env:
OUTFILE: folders.txt
outputs:
need_updates: ${{ steps.check_need_updates.outputs.need_updates }}
steps:
- uses: actions/checkout@v1
- name: create file list
run: python .github/modified-images.py
- name: Calculate number of folders
id: check_need_updates
run: |
[ -s "$OUTFILE" ] && echo "need_updates=1">>$GITHUB_OUTPUT || echo "need_updates=0">>$GITHUB_OUTPUT
- name: Upload folder list
uses: actions/upload-artifact@v1
with:
name: folder-list
path: folders.txt
modified-folders-ghcr:
runs-on: ubuntu-latest
needs: [needs-ghcr, modified-folders]
env:
OUTFILE: folders1.txt
REG_HOST: ghcr.io
REG_PATH: ${{ github.repository }}
REG_USER: ${{ github.actor }}
REG_PASS: ${{ secrets.GITHUB_TOKEN }}
if: needs.needs-ghcr.outputs.also_ghcr == 'true'
#outputs:
# need_updates: ${{ steps.check_need_updates.outputs.need_updates }}
steps:
- uses: actions/checkout@v1
- uses: actions/download-artifact@v1
with:
name: folder-list
- name: create file list
run: python .github/modified-images.py
#- name: Calculate number of folders
# id: check_need_updates
# run: |
# [ -s "$OUTFILE" ] && echo "::set-output name=need_updates::1" || echo "::set-output name=need_updates::0"
- name: merge folder lists
run: |
cat folder-list/folders.txt folders1.txt > folders.txt
- name: upload folder list
uses: actions/upload-artifact@v1
with:
name: folder-list
path: folders.txt
build:
runs-on: ubuntu-latest
needs: [ "modified-folders", "modified-folders-ghcr", "needs-ghcr"]
#if: needs.modified-folders.outputs.need_updates==1
steps:
- uses: actions/checkout@v1
- uses: actions/download-artifact@v1
with:
name: folder-list
- name: Login to GitHub Docker Registry
if: needs.needs-ghcr.outputs.also_ghcr == 'true'
uses: docker/login-action@v1
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to registry
uses: docker/login-action@v1
with:
registry: ${{ env.REG_HOST }}
username: ${{ env.REG_USER }}
password: ${{ env.REG_PASS }}
- name: Build the images
run: |
echo '===================================================='
echo "Will build these directories:"
cat folder-list/folders.txt
echo '===================================================='
while read f TAG VER; do
echo Folder $f, will be tagged as $TAG:$VER
if docker build $f/ --tag $TAG:$VER --tag $TAG:latest ; then
docker history $TAG:$VER
docker push $TAG:$VER
docker push $TAG:latest
else
echo "BUILD FAILED"
echo $f $TAG $VER >> errors.txt
fi
echo '===================================================='
done < folder-list/folders.txt
- run: |
[ -e "errors.txt" ] && (echo "ERRORS!" && cat errors.txt) || true