Skip to content

Commit

Permalink
Run E2E test when testing mysql image
Browse files Browse the repository at this point in the history
Signed-off-by: d-kuro <[email protected]>
  • Loading branch information
d-kuro committed Jul 26, 2023
1 parent 1d6ae3a commit c9d5a5e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 45 deletions.
104 changes: 61 additions & 43 deletions .github/workflows/build-mysql-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,53 @@ on:
- "!**.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
echo "${array[@]}"
echo "$dir"
done
if [ "${#array[@]}" -eq 0 ]; then
json_output="[]"
else
json_output=$(printf '%s\n' "${array[@]}" | jq -R . | jq -s . | jq -c .)
fi
echo "GITHUB_OUTPUT: mysql-versions=$json_output"
echo "mysql-versions=$json_output" >> "$GITHUB_OUTPUT"
tests:
if: github.event_name == 'pull_request'
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: [ "8.0.18", "8.0.25", "8.0.26", "8.0.27", "8.0.28", "8.0.30", "8.0.31", "8.0.32" ]
mysql-version: ${{ fromJson(needs.filter.outputs.mysql-versions) }}
k8s-version: [ "1.27.1" ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: true
- uses: docker/setup-buildx-action@v2
with:
driver: docker # refs: https://github.com/docker/build-push-action/issues/321
Expand Down Expand Up @@ -56,54 +94,34 @@ jobs:
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
- name: Create kind cluster
run: kind create cluster --name=moco --config=./e2e/kind-config_actions.yaml --image=kindest/node:v${{ matrix.k8s-version }} --wait 1m
- 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: Load mysqld image
run: kind load docker-image ghcr.io/cybozu-go/moco/mysql:${{ matrix.mysql-version }} --name moco
- name: Setup test cluster with local mysql image
run: make start KUBERNETES_VERSION=${{ inputs.k8s-version }} MYSQL_VERSION=${{ inputs.mysql-version }} KIND_CONFIG=kind-config_actions.yaml USE_LOCAL_MYSQL_IMAGE=1
working-directory: e2e

- name: Install MOCO
run: |
kubectl apply -f https://github.com/jetstack/cert-manager/releases/latest/download/cert-manager.yaml
kubectl -n cert-manager wait --for=condition=available --timeout=180s --all deployments
kubectl apply -f https://github.com/cybozu-go/moco/releases/latest/download/moco.yaml
kubectl -n moco-system wait --for=condition=available --timeout=180s --all deployments
- name: Create MySQLCluster
run: |
cat > mycluster.yaml <<'EOF'
apiVersion: moco.cybozu.com/v1beta1
kind: MySQLCluster
metadata:
namespace: default
name: test
spec:
replicas: 3
podTemplate:
spec:
containers:
- name: mysqld
image: ghcr.io/cybozu-go/moco/mysql:${{ matrix.mysql-version }}
volumeClaimTemplates:
- metadata:
name: mysql-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
EOF
kubectl apply -f mycluster.yaml
- name: Wait for MySQLCluster
run: kubectl wait -n default --for=condition=Available mysqlcluster/test --timeout=180s
- run: make test
working-directory: e2e
- run: make logs
working-directory: e2e
if: always()
- uses: actions/upload-artifact@v3
if: always()
with:
name: logs-${{ inputs.k8s-version }}-${{ inputs.mysql-version }}.tar.gz
path: e2e/logs.tar.gz

build:
if: github.ref == 'refs/heads/main'
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: [ "8.0.18", "8.0.25", "8.0.26", "8.0.27", "8.0.28", "8.0.30", "8.0.31", "8.0.32" ]
mysql-version: ${{ fromJson(needs.filter.outputs.mysql-versions) }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:
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
- run: make start KUBERNETES_VERSION=${{ inputs.k8s-version }} MYSQL_VERSION=${{ inputs.mysql-version }} KIND_CONFIG=kind-config_actions.yaml
- name: Setup test cluster
run: make start KUBERNETES_VERSION=${{ inputs.k8s-version }} MYSQL_VERSION=${{ inputs.mysql-version }} KIND_CONFIG=kind-config_actions.yaml
working-directory: e2e
- run: make test
working-directory: e2e
Expand Down
2 changes: 1 addition & 1 deletion containers/mysql/8.0.32/TAG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0.32.1
8.0.32.2
6 changes: 6 additions & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export MYSQL_VERSION KUBECTL KUBECONFIG
AGENT_DIR =
AGENT_IMAGE := ghcr.io/cybozu-go/moco-agent:$(shell awk '/moco-agent/ {print substr($$2, 2)}' ../go.mod)

## to test development version of mysqld, run make with USE_LOCAL_MYSQL_IMAGE=1
USE_LOCAL_MYSQL_IMAGE =

## We need to switch the configuration of kind on GitHub Actions
KIND_CONFIG = kind-config.yaml

Expand All @@ -36,6 +39,9 @@ start: $(KIND) $(KUBECTL) $(KUSTOMIZE) $(KUBECTL_MOCO)
ifdef AGENT_DIR
cd $(AGENT_DIR); docker buildx build --load --no-cache -t $(AGENT_IMAGE) .
$(KIND) load docker-image $(AGENT_IMAGE) --name=moco
endif
ifdef USE_LOCAL_MYSQL_IMAGE
$(KIND) load docker-image ghcr.io/cybozu-go/moco/mysql:$(MYSQL_VERSION) --name=moco
endif
$(KUBECTL) apply -f https://github.com/jetstack/cert-manager/releases/download/v$(CERT_MANAGER_VERSION)/cert-manager.yaml
$(KUBECTL) -n cert-manager wait --for=condition=available --timeout=180s --all deployments
Expand Down

0 comments on commit c9d5a5e

Please sign in to comment.