From c9d5a5e571ce77ac53264c6b59c55e39f1fd2cf8 Mon Sep 17 00:00:00 2001 From: d-kuro Date: Sat, 22 Jul 2023 15:46:53 +0900 Subject: [PATCH] Run E2E test when testing mysql image Signed-off-by: d-kuro --- .github/workflows/build-mysql-container.yaml | 104 +++++++++++-------- .github/workflows/e2e.yaml | 3 +- containers/mysql/8.0.32/TAG | 2 +- e2e/Makefile | 6 ++ 4 files changed, 70 insertions(+), 45 deletions(-) diff --git a/.github/workflows/build-mysql-container.yaml b/.github/workflows/build-mysql-container.yaml index e97fba2c1..2eca893b3 100644 --- a/.github/workflows/build-mysql-container.yaml +++ b/.github/workflows/build-mysql-container.yaml @@ -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 @@ -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 diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index c8b8726fa..35c899ee0 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -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 diff --git a/containers/mysql/8.0.32/TAG b/containers/mysql/8.0.32/TAG index 7d85f56b2..904793163 100644 --- a/containers/mysql/8.0.32/TAG +++ b/containers/mysql/8.0.32/TAG @@ -1 +1 @@ -8.0.32.1 +8.0.32.2 diff --git a/e2e/Makefile b/e2e/Makefile index 512955cf0..41fbb9426 100644 --- a/e2e/Makefile +++ b/e2e/Makefile @@ -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 @@ -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