133 lines (117 loc) · 5.1 KB
/
nightly.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
name: Build All Docker Images
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
inputs:
logLevel:
description: 'reason'
required: true
default: ''
tags:
description: 'forced manual rebuild'
jobs:
provide_images_json:
# see json juggling: https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#example-6
# see https://stackoverflow.com/a/62953566/1348344
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: get docker json list
id: output_data
run: |
echo "::set-output name=matrix::$(python -c 'import json, sys; print(json.dumps([v for v in sys.argv[1:]]))' $(find . -name Dockerfile))"
# this step is needed, so the output gets to the next defined job
outputs:
matrix: ${{ steps.output_data.outputs.matrix }}
build_and_push:
needs: provide_images_json
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
dockerfile: ${{fromJson(needs.provide_images_json.outputs.matrix)}}
steps:
- name: Clone Main Repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Init env vars
run: |
fullDockerfilePath=${{ matrix.dockerfile }}
folder=${fullDockerfilePath%"/Dockerfile"}
TMP_IMAGE_ARRAY=($(echo $folder | tr "/" "\n"))
IMAGE_NAME=${TMP_IMAGE_ARRAY[1]}
IMAGE_NAME_ESCAPED=${IMAGE_NAME/-/--}
TAG=${TMP_IMAGE_ARRAY[2]}
IMAGE_TAG_ESCAPED=${TAG/-/--}
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
echo "IMAGE_NAME_ESCAPED=$IMAGE_NAME_ESCAPED" >> $GITHUB_ENV
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
echo "IMAGE_TAG_ESCAPED=$IMAGE_TAG_ESCAPED" >> $GITHUB_ENV
echo "DOCKERFILE_FOLDER=$folder" >> $GITHUB_ENV
- name: Build Docker Images
run: |
curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64 && chmod +x container-structure-test-linux-amd64 && sudo mv container-structure-test-linux-amd64 /usr/local/bin/container-structure-test
folder=${{ env.DOCKERFILE_FOLDER }}
IMAGE_NAME=${{ env.IMAGE_NAME }}
TAG=${{ env.IMAGE_TAG }}
export REGISTRY_TARGET=${{ secrets.AKT_ENG_REGISTRY_DOMAIN }} && ./build.sh --lint=true --test=true --image=$IMAGE_NAME --tag=$TAG
IMAGE_ID=$REGISTRY_TARGET/$IMAGE_NAME
IMAGE_SIZE=`docker images $IMAGE_ID:$TAG --format "{{.Size}}"`
echo "IMAGE_SIZE=$IMAGE_SIZE" >> $GITHUB_ENV
- name: Login to target registry
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v1
with:
registry: https://eu.gcr.io
username: _json_key
password: ${{ secrets.AKT_ENG_REGISTRY_PUBLIC_JSON }}
- name: Push images to GCR only on main branch
if: github.ref == 'refs/heads/main'
run: docker images --format "{{.Repository}}:{{.Tag}}" | grep ${{ secrets.AKT_ENG_REGISTRY_DOMAIN }} | xargs -n 1 docker push
# - name: Create custom badge for image size
# id: badge_size
# if: github.ref == 'refs/heads/main'
# uses: djalal/job-status-badge@main
# with:
# cloudinary_url: ${{ secrets.CLOUDINARY_URL }}
# left_text: "image%20size"
# right_text: ${{ (startsWith(job.status, 'success') && env.IMAGE_SIZE) || 'N/A' }}
# color: ${{ (startsWith(job.status, 'success') && 'blue') || 'gray' }}
# public_id: ${{ env.IMAGE_NAME }}_${{ env.IMAGE_TAG }}-size
#
# - name: Create custom badge for build
# id: badge_build
# if: github.ref == 'refs/heads/main'
# uses: djalal/job-status-badge@main
# with:
# cloudinary_url: ${{ secrets.CLOUDINARY_URL }}
# left_text: ${{ env.IMAGE_NAME_ESCAPED }}%3A${{ env.IMAGE_TAG_ESCAPED }}
# right_text: ${{ (startsWith(job.status, 'success') && 'passing') || 'failed' }}
# color: ${{ (startsWith(job.status, 'success') && 'green') || 'red' }}
# public_id: ${{ env.IMAGE_NAME }}_${{ env.IMAGE_TAG }}-status
purge_camo_badges:
needs: build_and_push
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Purge badges from camo
run: |
PurgeBadgeList() {
while read -t5 URL Badge; do
URL="${URL%\"*}";
Badge="'${Badge#*\"}' "
echo -n "Purging Badge ${Badge}: ";
read -t60 result < <( curl --silent --request 'PURGE' -H 'Content-Type:application/json' --user-agent "$UserAgentString" --output '/dev/stdout' $URL | jq .status )
result="${result//\"/}"
echo "${result:-???}"
done
}
export -f PurgeBadgeList;
PurgeBadgeList < <(cat ./.github/workflows/PURGE.md | grep -o 'https://camo.githubusercontent.com.*alt="[^"]*')