-
Notifications
You must be signed in to change notification settings - Fork 125
126 lines (106 loc) · 5.63 KB
/
test-PR-dockerfiles.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
##### --------------------------------------------------------------------------- #####
##### This workflow looks for new dockefiles and builds them to the test target. #####
##### This in intended to start on a pull request (PR) #####
##### Ana06 is being used instead of jitterbit because of the filter option #####
##### --------------------------------------------------------------------------- #####
name: Test New Dockerfiles
on: pull_request
jobs:
find_new_dockerfiles:
runs-on: ubuntu-latest
outputs:
json: ${{ steps.files.outputs.added_modified }}
steps:
- uses: actions/checkout@v4
- id: files
uses: Ana06/[email protected]
with:
format: 'json'
filter: 'Dockerfile'
- run: "echo ${{ steps.files.outputs.all }}"
build_to_test:
needs: find_new_dockerfiles
if: needs.find_new_dockerfiles.outputs.json != '[]'
runs-on: ubuntu-latest
strategy:
matrix:
added_modified: ${{ fromJson(needs.find_new_dockerfiles.outputs.json) }}
steps:
- name: parse file path
id: parse
run: |
tool=$(echo "${{ matrix.added_modified }}" | cut -f 1 -d "/" )
version=$(echo "${{ matrix.added_modified }}" | cut -f 2 -d "/" )
echo "tool=$tool" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
##### --------------------------------------------------------------------------- #####
##### Workflows still cannot be run in parrallel as of 2022-12-01 #####
##### --------------------------------------------------------------------------- #####
# - name: test files
# uses: ./.github/workflows/build-to-test.yml
# with:
# path_to_context: "./${{ steps.parse.outputs.tool }}/${{ steps.parse.outputs.version }}"
# cache: ${{ steps.parse.outputs.tool }}
##### --------------------------------------------------------------------------- #####
##### The steps of ./.github/workflows/build-to-test.yml are copied here. #####
##### --------------------------------------------------------------------------- #####
- name: Checkout
uses: actions/checkout@v4
- name: Layer check
run: |
#checking layers
warning=''
app_layer=$(grep FROM ./${{ steps.parse.outputs.tool }}/${{ steps.parse.outputs.version }}/Dockerfile | grep -E "as app|AS app")
tst_layer=$(grep FROM ./${{ steps.parse.outputs.tool }}/${{ steps.parse.outputs.version }}/Dockerfile | grep -E "as test|AS test")
if [ -z "$app_layer" ] ; then echo "FATAL : app layer is missing" ; warning='warning' ; fi
if [ -z "$tst_layer" ] ; then echo "FATAL : test layer is missing" ; warning='warning' ; fi
if [ -n "$warning" ] ; then echo "Please see template for recommended format https://github.com/StaPH-B/docker-builds/blob/master/dockerfile-template/Dockerfile" ; exit 1 ; fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache-${{ steps.parse.outputs.tool }}
key: ${{ runner.os }}-buildx-${{ steps.parse.outputs.tool }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ steps.parse.outputs.tool }}
- name: Build to test
id: docker_build_to_test
uses: docker/build-push-action@v5
with:
context: ./${{ steps.parse.outputs.tool }}/${{ steps.parse.outputs.version }}
file: ./${{ steps.parse.outputs.tool }}/${{ steps.parse.outputs.version }}/Dockerfile
target: test
tags: ${{ steps.parse.outputs.tool }}:${{ steps.parse.outputs.version }}
load: true
push: false
cache-from: type=local,src=/tmp/.buildx-cache-${{ steps.parse.outputs.tool }}
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-${{ steps.parse.outputs.tool }}-new
- name: Check labels
run: |
# checking labels
warning=''
for label in base.image dockerfile.version software software.version description website maintainer maintainer.email
do
value=$(docker inspect --format '{{ index .Config.Labels "'$label'"}}' ${{ steps.parse.outputs.tool }}:${{ steps.parse.outputs.version }} )
if [ -z "$value" ] ; then warning='warning' ; echo "FATAL : $label label not found in ${{ steps.parse.outputs.tool }}:${{ steps.parse.outputs.version }}" ; fi
done
if [ -z "$(docker inspect --format '{{.Config.WorkingDir}}' ${{ steps.parse.outputs.tool }}:${{ steps.parse.outputs.version }} )" ] ;
then
warning='warning'
echo "FATAL : WORKDIR not set."
fi
if [ -n "$warning" ] ; then echo "Please see template for recommended format https://github.com/StaPH-B/docker-builds/blob/master/dockerfile-template/Dockerfile" ; exit 1 ; fi
- name: Check commonly overlooked commands
run: |
# checking commands
docker run ${{ steps.parse.outputs.tool }}:${{ steps.parse.outputs.version }} ps --help
- name: Move cache # apparently prevents the cache from growing in size forever
run: |
rm -rf /tmp/.buildx-cache-${{ steps.parse.outputs.tool }}
mv /tmp/.buildx-cache-${{ steps.parse.outputs.tool }}-new /tmp/.buildx-cache-${{ steps.parse.outputs.tool }}
- name: Image digest
run: echo ${{ steps.docker_build_to_test.outputs.digest }}