generated from cybozu-go/neco-template
-
Notifications
You must be signed in to change notification settings - Fork 22
126 lines (112 loc) · 4.09 KB
/
build-mysql-container.yaml
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
name: "Build mysql container"
on:
pull_request:
paths:
- "containers/mysql/**"
- ".github/workflows/build-mysql-container.yaml"
- "!**.md"
push:
branches:
- 'main'
paths:
- "containers/mysql/**"
- ".github/workflows/build-mysql-container.yaml"
- "!**.md"
jobs:
filter:
runs-on: ubuntu-20.04
outputs:
mysql-versions: ${{ steps.filter.outputs.mysql-versions }}
steps:
- uses: actions/checkout@v3
- name: filter
id: filter
working-directory: containers
run: |
array=()
for dir in $(find ./mysql -mindepth 1 -type d -printf '%f\n'); do
result=$(./tag_exists moco/mysql "mysql/$dir")
if [ "$result" = ng ]; then
array+=( "$dir" )
fi
done
json_output=$(printf '%s\n' "${array[@]}" | jq -R . | jq -s . | jq -c .)
echo "mysql-versions=$json_output" >> "$GITHUB_OUTPUT"
tests:
if: github.event_name == 'pull_request'
needs: filter
runs-on: ${{ vars.IMAGE_BUILD_RUNNER || 'ubuntu-20.04' }}
strategy:
matrix:
mysql-version: ${{ fromJson(needs.filter.outputs.mysql-versions) }}
k8s-version: [ "1.27.1" ]
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
with:
driver: docker # refs: https://github.com/docker/build-push-action/issues/321
- name: Check TAG file
working-directory: containers
run: |
result="$(./tag_exists moco/mysql mysql/${{ matrix.mysql-version }})"
if [ "$result" = ok ]; then
exit 1
fi
echo "TAG=$(cat ./mysql/${{ matrix.mysql-version }}/TAG)" >> $GITHUB_ENV
- uses: docker/build-push-action@v4
with:
context: containers/mysql/${{ matrix.mysql-version }}/.
push: false
load: true
tags: |
ghcr.io/cybozu-go/moco/mysql:${{ env.TAG }}
ghcr.io/cybozu-go/moco/mysql:${{ matrix.mysql-version }}
- name: Install Container Structure Tests
run: |
VERSION=v1.15.0
curl -LO "https://storage.googleapis.com/container-structure-test/$VERSION/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
- name: Run Container Structure Tests
run: |
container-structure-test test --image ghcr.io/cybozu-go/moco/mysql:${{ matrix.mysql-version }} --config ./containers/mysql/${{ matrix.mysql-version }}/container-structure-test.yaml
- uses: ./.github/workflows/e2e.yaml
with:
k8s-version: ${{ matrix.k8s-version }}
mysql-version: ${{ matrix.mysql-version }}
use-local-mysql-image: true
build:
if: github.ref == 'refs/heads/main'
needs: filter
runs-on: ${{ vars.IMAGE_BUILD_RUNNER || 'ubuntu-20.04' }}
strategy:
matrix:
mysql-version: ${{ fromJson(needs.filter.outputs.mysql-versions) }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Check TAG file
working-directory: containers
run: |
result="$(./tag_exists moco/mysql mysql/${{ matrix.mysql-version }})"
if [ "$result" = ok ]; then
exit 1
fi
echo "TAG=$(cat ./mysql/${{ matrix.mysql-version }}/TAG)" >> $GITHUB_ENV
- uses: docker/build-push-action@v4
with:
context: containers/mysql/${{ matrix.mysql-version }}/.
platforms: linux/amd64,linux/arm64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/cybozu-go/moco/mysql:${{ env.TAG }}
ghcr.io/cybozu-go/moco/mysql:${{ matrix.mysql-version }}