From 3d604f3094e358f69fb675a516f779ae50adece3 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Thu, 26 Mar 2020 14:21:54 +0200 Subject: [PATCH 1/5] ci: run unit tests in GitHub Actions --- .circleci/config.yml | 1 + .github/workflows/ci.yaml | 119 ++++++++++++++++++++++++++++++++++++++ Makefile | 3 + test/e2e/run-gh.bash | 37 ++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100755 test/e2e/run-gh.bash diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a063a354..373125ea4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -101,6 +101,7 @@ jobs: - run: make test TEST_FLAGS="-race -tags integration -timeout 5m" - run: make check-generated - run: make all + #- run: E2E_KIND_CLUSTER_NUM=4 make e2e - run: E2E_KIND_CLUSTER_NUM=4 make e2e - save_cache: key: cache-{{ checksum "Makefile" }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..bd01ed695 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,119 @@ +name: ci + +on: + pull_request: + push: + branches: + - master + tags-ignore: + - v.* + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: niden/actions-memcached@v7 + - name: Restore Cache + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Setup Go + uses: actions/setup-go@v2-beta + with: + go-version: 1.14.x + - name: Run unit tests + run: make test TEST_FLAGS="-race -tags integration -timeout 5m" + - name: Check codegen + run: make check-generated + - name: Build containers + run: make all + e2e-1: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v2 + - uses: engineerd/setup-kind@v0.3.0 + - name: Restore Cache + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Setup Go + uses: actions/setup-go@v2-beta + with: + go-version: 1.14.x + - name: Build containers + run: make all + - name: Run tests + run: | + E2E_TESTS='10_* 11_* 12_*' make e2e-gh + + e2e-2: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v2 + - uses: engineerd/setup-kind@v0.3.0 + - name: Restore Cache + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Setup Go + uses: actions/setup-go@v2-beta + with: + go-version: 1.14.x + - name: Build containers + run: make all + - name: Run tests + run: E2E_TESTS='13_* 14_* 15_*' make e2e-gh + e2e-3: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v2 + - uses: engineerd/setup-kind@v0.3.0 + - name: Restore Cache + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Setup Go + uses: actions/setup-go@v2-beta + with: + go-version: 1.14.x + - name: Build containers + run: make all + - name: Run tests + run: E2E_TESTS='16_* 17_*' make e2e-gh + e2e-4: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v2 + - uses: engineerd/setup-kind@v0.3.0 + - name: Restore Cache + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Setup Go + uses: actions/setup-go@v2-beta + with: + go-version: 1.14.x + - name: Build containers + run: make all + - name: Run tests + run: E2E_TESTS='20_* 21_* 22_*' make e2e-gh diff --git a/Makefile b/Makefile index 31db11037..5f06ef969 100644 --- a/Makefile +++ b/Makefile @@ -65,6 +65,9 @@ test: test/bin/helm test/bin/kubectl test/bin/sops test/bin/kustomize $(GENERATE e2e: lint-e2e test/bin/helm test/bin/kubectl test/bin/sops test/bin/crane test/e2e/bats $(GOBIN)/fluxctl build/.flux.done PATH="${PWD}/test/bin:${PATH}" CURRENT_OS_ARCH=$(CURRENT_OS_ARCH) test/e2e/run.bash +e2e-gh: lint-e2e test/bin/helm test/bin/kubectl test/bin/sops test/bin/crane test/e2e/bats $(GOBIN)/fluxctl build/.flux.done + PATH="${PWD}/test/bin:${PATH}" CURRENT_OS_ARCH=$(CURRENT_OS_ARCH) test/e2e/run-gh.bash + E2E_BATS_FILES := test/e2e/*.bats E2E_BASH_FILES := test/e2e/run.bash test/e2e/lib/* SHFMT_DIFF_CMD := test/bin/shfmt -i 2 -sr -d diff --git a/test/e2e/run-gh.bash b/test/e2e/run-gh.bash new file mode 100755 index 000000000..3e7ed98f4 --- /dev/null +++ b/test/e2e/run-gh.bash @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -o errexit + +# This script runs the bats tests + +# Directory paths we need to be aware of +FLUX_ROOT_DIR="$(git rev-parse --show-toplevel)" +E2E_DIR="${FLUX_ROOT_DIR}/test/e2e" +CACHE_DIR="${FLUX_ROOT_DIR}/cache/$CURRENT_OS_ARCH" + +KIND_VERSION=v0.7.0 +KUBE_VERSION=v1.14.10 +GITSRV_VERSION=v1.0.0 +KIND_CACHE_PATH="${CACHE_DIR}/kind-$KIND_VERSION" +KIND_CLUSTER_PREFIX=flux-e2e +BATS_EXTRA_ARGS="" + +sudo mv "$(go env GOPATH)/bin/fluxctl" "/usr/local/bin/fluxctl" + +# shellcheck disable=SC1090 +source "${E2E_DIR}/lib/defer.bash" +trap run_deferred EXIT + +mkdir -p "${FLUX_ROOT_DIR}/cache" +curl -sL "https://github.com/fluxcd/gitsrv/releases/download/${GITSRV_VERSION}/known_hosts.txt" > "${FLUX_ROOT_DIR}/cache/known_hosts" + +kind load docker-image 'docker.io/fluxcd/flux:latest' + +echo '>>> Running the tests' +# Run all tests by default but let users specify which ones to run, e.g. with E2E_TESTS='11_*' make e2e +E2E_TESTS=${E2E_TESTS:-.} +( + cd "${E2E_DIR}" + # shellcheck disable=SC2086 + "${E2E_DIR}/bats/bin/bats" -t ${BATS_EXTRA_ARGS} ${E2E_TESTS} +) From 650c61ce7c2c02d32dca3262d34a5791a7839988 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Thu, 26 Mar 2020 19:38:37 +0200 Subject: [PATCH 2/5] ci: add probes to gitsrv to avoid random failures --- test/e2e/fixtures/kustom/base/gitsrv/gitsrv.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/e2e/fixtures/kustom/base/gitsrv/gitsrv.yaml b/test/e2e/fixtures/kustom/base/gitsrv/gitsrv.yaml index 48ae31565..4dc807937 100644 --- a/test/e2e/fixtures/kustom/base/gitsrv/gitsrv.yaml +++ b/test/e2e/fixtures/kustom/base/gitsrv/gitsrv.yaml @@ -27,6 +27,16 @@ spec: - containerPort: 22 name: ssh protocol: TCP + readinessProbe: + tcpSocket: + port: 22 + initialDelaySeconds: 20 + periodSeconds: 10 + livenessProbe: + tcpSocket: + port: 22 + initialDelaySeconds: 20 + periodSeconds: 10 volumeMounts: - mountPath: /git-server/repos name: git-server-data From 1cd900a71706cbef735dd1c08a597a704c5665b6 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Thu, 26 Mar 2020 20:05:20 +0200 Subject: [PATCH 3/5] ci: run e2e tests in GitHub Actions - use 4 Kubernetes Kind cluster for e2e tests - store Flux container image and cache dir in artifacts - download artifacts in e2e jobs to avoid rebuilding binaries and containers - cleanup artifacts daily --- .github/workflows/ci-cleanup.yaml | 19 ++++ .github/workflows/ci.yaml | 102 +++++------------- .../workflows/{check-links.yaml => docs.yaml} | 12 ++- Makefile | 4 +- test/e2e/run-gh.bash | 4 - 5 files changed, 58 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/ci-cleanup.yaml rename .github/workflows/{check-links.yaml => docs.yaml} (89%) diff --git a/.github/workflows/ci-cleanup.yaml b/.github/workflows/ci-cleanup.yaml new file mode 100644 index 000000000..cf43f139e --- /dev/null +++ b/.github/workflows/ci-cleanup.yaml @@ -0,0 +1,19 @@ +name: artifacts-cleanup + +on: + schedule: + # Every day at 1am + - cron: '0 1 * * *' + +jobs: + remove-old-artifacts: + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Remove old artifacts + uses: c-hive/gha-remove-artifacts@v1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + age: '1 day' + skip-tags: false diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bd01ed695..e6a3437e0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,16 +5,14 @@ on: push: branches: - master - tags-ignore: - - v.* jobs: - build: + unit-testing: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: niden/actions-memcached@v7 - - name: Restore Cache + - name: Restore Go cache uses: actions/cache@v1 with: path: ~/go/pkg/mod @@ -25,63 +23,31 @@ jobs: uses: actions/setup-go@v2-beta with: go-version: 1.14.x - - name: Run unit tests + - name: Run tests run: make test TEST_FLAGS="-race -tags integration -timeout 5m" - name: Check codegen run: make check-generated - - name: Build containers - run: make all - e2e-1: - runs-on: ubuntu-latest - needs: build - steps: - - uses: actions/checkout@v2 - - uses: engineerd/setup-kind@v0.3.0 - - name: Restore Cache - uses: actions/cache@v1 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Setup Go - uses: actions/setup-go@v2-beta - with: - go-version: 1.14.x - - name: Build containers + - name: Build binaries run: make all - - name: Run tests + - name: Prepare cache run: | - E2E_TESTS='10_* 11_* 12_*' make e2e-gh - - e2e-2: - runs-on: ubuntu-latest - needs: build - steps: - - uses: actions/checkout@v2 - - uses: engineerd/setup-kind@v0.3.0 - - name: Restore Cache - uses: actions/cache@v1 + cp "$(go env GOPATH)/bin/fluxctl" cache/fluxctl + docker save -o cache/flux-latest.tar fluxcd/flux:latest + - name: Upload cache + uses: actions/upload-artifact@v1 with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Setup Go - uses: actions/setup-go@v2-beta - with: - go-version: 1.14.x - - name: Build containers - run: make all - - name: Run tests - run: E2E_TESTS='13_* 14_* 15_*' make e2e-gh - e2e-3: + name: cache + path: cache + e2e-testing: runs-on: ubuntu-latest - needs: build + needs: unit-testing + strategy: + matrix: + test: ['10_* 11_* 12_*', '13_* 14_*', '15_* 16_* 17_*', '20_* 21_* 22_*'] steps: - uses: actions/checkout@v2 - uses: engineerd/setup-kind@v0.3.0 - - name: Restore Cache + - name: Restore Go cache uses: actions/cache@v1 with: path: ~/go/pkg/mod @@ -92,28 +58,16 @@ jobs: uses: actions/setup-go@v2-beta with: go-version: 1.14.x - - name: Build containers - run: make all - - name: Run tests - run: E2E_TESTS='16_* 17_*' make e2e-gh - e2e-4: - runs-on: ubuntu-latest - needs: build - steps: - - uses: actions/checkout@v2 - - uses: engineerd/setup-kind@v0.3.0 - - name: Restore Cache - uses: actions/cache@v1 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Setup Go - uses: actions/setup-go@v2-beta + - name: Download cache + uses: actions/download-artifact@v1 with: - go-version: 1.14.x - - name: Build containers - run: make all + name: cache + - name: Load cache + run: | + chmod +x cache/fluxctl + sudo mv cache/fluxctl /usr/local/bin/fluxctl + docker load --input cache/flux-latest.tar -q + kind load docker-image fluxcd/flux:latest - name: Run tests - run: E2E_TESTS='20_* 21_* 22_*' make e2e-gh + run: | + E2E_TESTS='${{ matrix.test }}' make e2e-gh diff --git a/.github/workflows/check-links.yaml b/.github/workflows/docs.yaml similarity index 89% rename from .github/workflows/check-links.yaml rename to .github/workflows/docs.yaml index 5638aaf2f..d752a8d2a 100644 --- a/.github/workflows/check-links.yaml +++ b/.github/workflows/docs.yaml @@ -1,7 +1,13 @@ -on: [push, pull_request] -name: Check links +name: docs + +on: + pull_request: + push: + branches: + - master + jobs: - linkChecker: + link-checker: runs-on: ubuntu-latest strategy: matrix: diff --git a/Makefile b/Makefile index 5f06ef969..bc0967878 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ BUILD_DATE:=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') GENERATED_TEMPLATES_FILE=pkg/install/generated_templates.gogen.go -all: $(GOBIN)/fluxctl $(GOBIN)/fluxd build/.flux.done +all: $(GOBIN)/fluxctl build/.flux.done release-bins: $(GENERATED_TEMPLATES_FILE) for arch in amd64; do \ @@ -65,7 +65,7 @@ test: test/bin/helm test/bin/kubectl test/bin/sops test/bin/kustomize $(GENERATE e2e: lint-e2e test/bin/helm test/bin/kubectl test/bin/sops test/bin/crane test/e2e/bats $(GOBIN)/fluxctl build/.flux.done PATH="${PWD}/test/bin:${PATH}" CURRENT_OS_ARCH=$(CURRENT_OS_ARCH) test/e2e/run.bash -e2e-gh: lint-e2e test/bin/helm test/bin/kubectl test/bin/sops test/bin/crane test/e2e/bats $(GOBIN)/fluxctl build/.flux.done +e2e-gh: lint-e2e test/bin/helm test/bin/kubectl test/bin/sops test/bin/crane test/e2e/bats PATH="${PWD}/test/bin:${PATH}" CURRENT_OS_ARCH=$(CURRENT_OS_ARCH) test/e2e/run-gh.bash E2E_BATS_FILES := test/e2e/*.bats diff --git a/test/e2e/run-gh.bash b/test/e2e/run-gh.bash index 3e7ed98f4..e8ebeb619 100755 --- a/test/e2e/run-gh.bash +++ b/test/e2e/run-gh.bash @@ -16,8 +16,6 @@ KIND_CACHE_PATH="${CACHE_DIR}/kind-$KIND_VERSION" KIND_CLUSTER_PREFIX=flux-e2e BATS_EXTRA_ARGS="" -sudo mv "$(go env GOPATH)/bin/fluxctl" "/usr/local/bin/fluxctl" - # shellcheck disable=SC1090 source "${E2E_DIR}/lib/defer.bash" trap run_deferred EXIT @@ -25,8 +23,6 @@ trap run_deferred EXIT mkdir -p "${FLUX_ROOT_DIR}/cache" curl -sL "https://github.com/fluxcd/gitsrv/releases/download/${GITSRV_VERSION}/known_hosts.txt" > "${FLUX_ROOT_DIR}/cache/known_hosts" -kind load docker-image 'docker.io/fluxcd/flux:latest' - echo '>>> Running the tests' # Run all tests by default but let users specify which ones to run, e.g. with E2E_TESTS='11_*' make e2e E2E_TESTS=${E2E_TESTS:-.} From 36deaa877555cb2692b28739e425c48ee45504aa Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Fri, 27 Mar 2020 15:40:51 +0200 Subject: [PATCH 4/5] ci: disable e2e tests in CircleCI --- .circleci/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 373125ea4..b1e7af044 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -101,8 +101,6 @@ jobs: - run: make test TEST_FLAGS="-race -tags integration -timeout 5m" - run: make check-generated - run: make all - #- run: E2E_KIND_CLUSTER_NUM=4 make e2e - - run: E2E_KIND_CLUSTER_NUM=4 make e2e - save_cache: key: cache-{{ checksum "Makefile" }} paths: From 61b5ce82705da27236e5ba16b936f29ddd855a5d Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Fri, 27 Mar 2020 16:30:31 +0200 Subject: [PATCH 5/5] ci: disable unit tests in CircleCI --- .circleci/config.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b1e7af044..eb1a88e40 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -97,9 +97,6 @@ jobs: keys: - go-mod-{{ checksum "go.mod" }} - go-mod- - # Note that the test timeout is per Go package - - run: make test TEST_FLAGS="-race -tags integration -timeout 5m" - - run: make check-generated - run: make all - save_cache: key: cache-{{ checksum "Makefile" }}