generated from cybozu-go/neco-template
-
Notifications
You must be signed in to change notification settings - Fork 22
142 lines (128 loc) · 4.87 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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@v4
- 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=$(echo "${array[@]}" | jq -Rc 'split(" ")')
echo "GITHUB_OUTPUT: mysql-versions=$json_output"
echo "mysql-versions=$json_output" >> "$GITHUB_OUTPUT"
tests:
if: ${{ (github.event_name == 'pull_request') && (needs.filter.outputs.mysql-versions != '[]') }}
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@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- uses: docker/setup-buildx-action@v3
with:
driver: docker # refs: https://github.com/docker/build-push-action/issues/321
- name: Export TAG file
id: tag
working-directory: containers
run: |
TAG=$(cat ./mysql/${{ matrix.mysql-version }}/TAG)
echo "tag: $TAG"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- uses: docker/build-push-action@v5
with:
context: containers/mysql/${{ matrix.mysql-version }}/.
push: false
load: true
tags: |
ghcr.io/cybozu-go/moco/mysql:${{ steps.tag.outputs.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
- run: |
swapon > swapon.txt
sudo swapoff -a
cat swapon.txt | tail -n+2 | awk '$2=="file" {print $1}' | sudo xargs --no-run-if-empty rm
- run: sudo mkdir /mnt/local-path-provisioner0 /mnt/local-path-provisioner1 /mnt/local-path-provisioner2
- name: Setup test cluster with local mysql image
run: make start KUBERNETES_VERSION=${{ matrix.k8s-version }} MYSQL_VERSION=${{ matrix.mysql-version }} KIND_CONFIG=kind-config_actions.yaml USE_LOCAL_MYSQL_IMAGE=1
working-directory: e2e
- run: make test
working-directory: e2e
- run: make logs
working-directory: e2e
if: always()
- uses: actions/upload-artifact@v3
if: always()
with:
name: logs-${{ matrix.k8s-version }}-${{ matrix.mysql-version }}.tar.gz
path: e2e/logs.tar.gz
build:
if: ${{ (github.ref == 'refs/heads/main') && (needs.filter.outputs.mysql-versions != '[]') }}
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@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Export TAG file
id: tag
working-directory: containers
run: |
TAG=$(cat ./mysql/${{ matrix.mysql-version }}/TAG)
echo "tag: $TAG"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- uses: docker/build-push-action@v5
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:${{ steps.tag.outputs.tag }}
ghcr.io/cybozu-go/moco/mysql:${{ matrix.mysql-version }}