-
Notifications
You must be signed in to change notification settings - Fork 573
111 lines (92 loc) · 3.43 KB
/
CI.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
name: CI
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
workflow_dispatch:
branches: ["**"]
jobs:
collect-solutions:
runs-on: ubuntu-20.04
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: "Find Dockerfiles"
id: "solutions"
run: |
RESULTS=()
for DIR in $(find Prime* -type f -name Dockerfile ! -exec dirname {} \; | sort | sed -e 's|^./||'); do
[ -f "${DIR}/build-no" ] && continue
RESULTS+=( "${DIR}" )
done
SOLUTIONS=$(printf '%s\n' "${RESULTS[@]}" | jq -R . | jq -sc .)
echo "solutions=${SOLUTIONS}" >> $GITHUB_OUTPUT
outputs:
solutions: ${{ steps.solutions.outputs.solutions }}
build:
env:
ENABLE_DOCKER_PUSH: ${{ github.repository_owner == 'PlummersSoftwareLLC' && github.ref == 'refs/heads/drag-race' }}
runs-on: "ubuntu-20.04"
needs: ["collect-solutions"]
strategy:
fail-fast: false
matrix:
solution: ${{ fromJson(needs.collect-solutions.outputs.solutions) }}
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: "Normalize solution name"
id: solution-name
run: |
NAME=$(echo "${{ matrix.solution }}" | sed -r 's/\//-/g' | tr '[:upper:]' '[:lower:]' | sed -r 's/(prime|solution_)//g')
echo "normalized=${NAME}" >> $GITHUB_OUTPUT
- name: Select arm64 build for solutions with arm64 flag file
id: arch-arm64
run: |
if [[ -f "${{ matrix.solution }}/arch-arm64" ]]; then
echo "build=true" >> $GITHUB_OUTPUT
fi
- name: Select amd64 build for solutions with amd64 or no flag file
id: arch-amd64
run: |
if [[ -f "${{ matrix.solution }}/arch-amd64" || ! -f "${{ matrix.solution }}/arch-arm64" ]]; then
echo "build=true" >> $GITHUB_OUTPUT
fi
- name: Lint Dockerfile
uses: jbergstroem/hadolint-gh-action@v1
with:
dockerfile: "${{ matrix.solution }}/Dockerfile"
output_format: tty
error_level: 0
config_file: ./config/hadolint.yml
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
if: ${{ env.ENABLE_DOCKER_PUSH == 'true' }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build amd64
if: steps.arch-amd64.outputs.build
uses: docker/build-push-action@v3
with:
tags: primeimages/primes:${{ steps.solution-name.outputs.normalized }}
context: ${{ matrix.solution }}
platforms: linux/amd64
push: ${{ env.ENABLE_DOCKER_PUSH }}
cache-from: type=registry,ref=primeimages/primes:${{ steps.solution-name.outputs.normalized }}
cache-to: type=inline
- name: Build arm64
if: steps.arch-arm64.outputs.build
uses: docker/build-push-action@v3
with:
tags: primeimages/primes:${{ steps.solution-name.outputs.normalized }}
context: ${{ matrix.solution }}
platforms: linux/arm64
push: ${{ env.ENABLE_DOCKER_PUSH }}
cache-from: type=registry,ref=primeimages/primes:${{ steps.solution-name.outputs.normalized }}
cache-to: type=inline