From cd08ad33abf7891c7ae218b0505289219f1b7591 Mon Sep 17 00:00:00 2001 From: zhu733756 Date: Tue, 12 Oct 2021 11:55:19 +0800 Subject: [PATCH] add main workflow actions Signed-off-by: zhu733756 --- .github/workflows/main.yaml | 92 +++++++++++++++++++++++++++++++++++++ Makefile | 15 ++++-- hack/update-codegen.sh | 2 +- hack/verify-crds.sh | 36 +++++++++++++++ 4 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/main.yaml create mode 100755 hack/verify-crds.sh diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 000000000..616fce7a2 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,92 @@ +name: Main CI WorkFlow + +on: + push: + branches: + - 'master' + - 'release-*' + tags: + - 'v*' + pull_request: + branches: + - 'master' + - 'release-*' + +jobs: + test: + runs-on: ubuntu-18.04 + timeout-minutes: 30 + name: Basic test and verify + env: + GO111MODULE: "on" + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.16.x + + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + + - name: Install kubebuilder-2.3.2 + run: | + curl -L "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.2/kubebuilder_2.3.2_linux_amd64.tar.gz" | tar -xz -C /tmp/ + sudo mv /tmp/kubebuilder_2.3.2_linux_amd64 /usr/local/kubebuilder + + - name: Run basic test + run: make test + + - name: Run verify crds test + run: make verify + + build: + runs-on: ubuntu-18.04 + timeout-minutes: 30 + name: Binary build + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.16.x + + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - run: make binary + name: Run build all binaries + + docker_build: + runs-on: ubuntu-18.04 + timeout-minutes: 30 + name: Docker image build + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.16.x + + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - run: make build-amd64 diff --git a/Makefile b/Makefile index 7bbaa3700..97a4aae2f 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,15 @@ test: generate fmt vet manifests manager: generate fmt vet go build -o bin/manager cmd/manager/main.go +binary: + go build -o bin/manager cmd/manager/main.go + go build -o bin/watcher cmd/fluent-bit-watcher/main.go + +verify: verify-crds + +verify-crds: + sudo chmod a+x ./hack/verify-crds.sh && ./hack/verify-crds.sh + # Run against the configured Kubernetes cluster in ~/.kube/config run: generate fmt vet manifests go run cmd/manager/main.go @@ -71,14 +80,14 @@ build-op: test docker buildx build --push --platform linux/amd64,linux/arm64 -f cmd/manager/Dockerfile . -t ${OP_IMG} # Build all amd64 docker images -build-amd64: build-op-amd64 +build-amd64: build-op-amd64 build-fb-amd64 # Build amd64 Fluent Bit container image build-fb-amd64: docker build -f cmd/fluent-bit-watcher/Dockerfile . -t ${FB_IMG}${AMD64} # Build amd64 Fluent Bit Operator container image -build-op-amd64: test +build-op-amd64: docker build -f cmd/manager/Dockerfile . -t ${OP_IMG}${AMD64} # Push the amd64 docker image @@ -94,7 +103,7 @@ ifeq (, $(shell which controller-gen)) CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ cd $$CONTROLLER_GEN_TMP_DIR ;\ go mod init tmp ;\ - go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1 ;\ + go install -v sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1 ;\ rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ } CONTROLLER_GEN=$(GOBIN)/controller-gen diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index b7c0f3622..a426add5b 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -9,7 +9,7 @@ set -o pipefail SCRIPT_ROOT=$(git rev-parse --show-toplevel) # Grab code-generator version from go.sum. -CODEGEN_VERSION="v0.18.2" +CODEGEN_VERSION=$(grep 'k8s.io/code-generator' go.sum | awk '{print $2}' | head -1) CODEGEN_PKG=$(echo `go env GOPATH`"/pkg/mod/k8s.io/code-generator@${CODEGEN_VERSION}") # code-generator does work with go.mod but makes assumptions about diff --git a/hack/verify-crds.sh b/hack/verify-crds.sh new file mode 100755 index 000000000..466408ed0 --- /dev/null +++ b/hack/verify-crds.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/.. +CRD_OPTIONS="crd:trivialVersions=true" + +DIFFROOT="${SCRIPT_ROOT}/config/crd/bases" +TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/config/crd/bases" +_tmp="${SCRIPT_ROOT}/_tmp" + +cleanup() { + rm -rf "${_tmp}" +} +trap "cleanup" EXIT SIGINT + +cleanup + +mkdir -p "${TMP_DIFFROOT}" +cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}" + +$(which controller-gen) ${CRD_OPTIONS} rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases +echo "diffing ${DIFFROOT} against freshly generated crds" +ret=0 +diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? +cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}" +if [[ $ret -eq 0 ]] +then + echo "${DIFFROOT} up to date." +else + echo "${DIFFROOT} is out of date. Please rerun make manifests" + exit 1 +fi +