From f713d5a5109edb295ebbfd34d88464e89a807c67 Mon Sep 17 00:00:00 2001 From: Igor Zibarev Date: Sun, 29 May 2022 20:20:49 +0300 Subject: [PATCH] ci: add docker images to GitHub Actions --- .circleci/config.yml | 118 ------------------- .github/workflows/main.yml | 29 ++++- .github/workflows/release.yml | 19 +++ .github/workflows/reusable-docker-images.yml | 87 ++++++++++++++ Dockerfile | 2 +- hack/build.sh | 9 +- hack/install.sh | 6 +- 7 files changed, 142 insertions(+), 128 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/reusable-docker-images.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index 59cfe6f9..5fe02e73 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,46 +2,6 @@ # Ref: https://circleci.com/docs/2.0/configuration-reference/ version: 2.1 -commands: - build_push_docker_image: - description: "Builds and pushes Docker image" - parameters: - helm_version: - type: string - image_name: - type: string - default: hypnoglow/helm-s3 - steps: - - run: - name: Build & push Docker image - command: | - HELM_VERSION="<< parameters.helm_version >>" - IMAGE_NAME="<< parameters.image_name >>" - - PLUGIN_VERSION="commit.${CIRCLE_SHA1}" - if [ "${CIRCLE_BRANCH}" == "master" ]; then - PLUGIN_VERSION="master" - fi - if [ -n "${CIRCLE_TAG}" ]; then - PLUGIN_VERSION="${CIRCLE_TAG#v*}" - fi - - docker build \ - --build-arg HELM_VERSION=${HELM_VERSION} \ - --build-arg PLUGIN_VERSION=${PLUGIN_VERSION} \ - --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ - --build-arg VCS_REF=$(git rev-parse --short HEAD) \ - -t ${IMAGE_NAME}:local . - - echo "${DOCKERHUB_PASSWORD}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin - - IMAGE_TAG="${PLUGIN_VERSION}-helm${HELM_VERSION}" - docker tag ${IMAGE_NAME}:local ${IMAGE_NAME}:${IMAGE_TAG} - docker push ${IMAGE_NAME}:${IMAGE_TAG} - - IMAGE_TAG_HELM_MINOR="${PLUGIN_VERSION}-helm${HELM_VERSION%*.*}" - docker tag ${IMAGE_NAME}:local ${IMAGE_NAME}:${IMAGE_TAG_HELM_MINOR} - docker push ${IMAGE_NAME}:${IMAGE_TAG_HELM_MINOR} jobs: dep: docker: @@ -102,39 +62,6 @@ jobs: if [ -n "$CIRCLE_TAG" ]; then curl -sL https://git.io/goreleaser | bash fi - docker-helm-2_17: - docker: - - image: circleci/buildpack-deps:stretch - working_directory: ~/workspace/helm-s3 - steps: - - attach_workspace: - at: ~/workspace - - setup_remote_docker: - version: 18.06.0-ce - - build_push_docker_image: - helm_version: 2.17.0 - docker-helm-3_4: - docker: - - image: circleci/buildpack-deps:stretch - working_directory: ~/workspace/helm-s3 - steps: - - attach_workspace: - at: ~/workspace - - setup_remote_docker: - version: 18.06.0-ce - - build_push_docker_image: - helm_version: 3.4.2 - docker-helm-3_5: - docker: - - image: circleci/buildpack-deps:stretch - working_directory: ~/workspace/helm-s3 - steps: - - attach_workspace: - at: ~/workspace - - setup_remote_docker: - version: 18.06.0-ce - - build_push_docker_image: - helm_version: 3.5.2 workflows: version: 2 @@ -142,24 +69,6 @@ workflows: test-pipeline: jobs: - dep - - docker-helm-2_17: - requires: - - dep - filters: - branches: - only: master - - docker-helm-3_4: - requires: - - dep - filters: - branches: - only: master - - docker-helm-3_5: - requires: - - dep - filters: - branches: - only: master - test-install: filters: branches: @@ -173,36 +82,9 @@ workflows: only: /.*/ branches: ignore: /.*/ - - docker-helm-2_17: - requires: - - dep - filters: - tags: - only: /.*/ - branches: - ignore: /.*/ - - docker-helm-3_4: - requires: - - dep - filters: - tags: - only: /.*/ - branches: - ignore: /.*/ - - docker-helm-3_5: - requires: - - dep - filters: - tags: - only: /.*/ - branches: - ignore: /.*/ - release: requires: - dep - - docker-helm-2_17 - - docker-helm-3_4 - - docker-helm-3_5 filters: tags: only: /.*/ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8170f042..f2376a2d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,11 +15,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@b22fbbc2921299758641fab08929b4ac52b32923 # v3.2.0 with: + cache: true go-version-file: 'go.mod' - name: Download dependencies @@ -31,10 +32,10 @@ jobs: go test -v -race -coverprofile=coverage.txt -covermode=atomic $(go list ./... | grep -v e2e) - name: Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 - name: Run linters - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@537aa1903e5d359d0b27dbc19ddd22c5087f3fbc # v3.2.0 with: version: v1.31 args: --verbose @@ -42,12 +43,19 @@ jobs: skip-pkg-cache: true skip-build-cache: true + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@94e0aab03ca135d11a35e5bfc14e6746dc56e7e9 # v1.1.0 + with: + severity: warning + - name: Build run: | go build -v -o ./bin/helm-s3 ./cmd/helms3 test-e2e: name: Run end-to-end tests + needs: + - build runs-on: ubuntu-latest strategy: matrix: @@ -76,10 +84,10 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@b22fbbc2921299758641fab08929b4ac52b32923 # v3.2.0 with: go-version-file: 'go.mod' @@ -135,3 +143,12 @@ jobs: - name: Run tests run: | go test -v ./tests/e2e/... + + docker-images: + needs: + - test-e2e + # TODO: if branch = master + uses: ./.github/workflows/reusable-docker-images.yml + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..3dd445ab --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,19 @@ +name: release + +on: + push: + tags: + - '*' + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 + + - name: TODO + run: | + echo "TODO" diff --git a/.github/workflows/reusable-docker-images.yml b/.github/workflows/reusable-docker-images.yml new file mode 100644 index 00000000..a093a706 --- /dev/null +++ b/.github/workflows/reusable-docker-images.yml @@ -0,0 +1,87 @@ +name: docker-images + +on: + workflow_call: + secrets: + DOCKERHUB_USERNAME: + required: true + DOCKERHUB_TOKEN: + required: true + +jobs: + docker-images: + name: Publish docker images + runs-on: ubuntu-latest + strategy: + matrix: + helm: + - 2.17.0 + - 3.4.2 + - 3.5.4 + env: + IMAGE_NAME: hypnoglow/helm-s3 + HELM_VERSION: ${{ matrix.helm }} + steps: + + - name: Checkout + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 + + - name: Prepare variables + id: vars + uses: actions/github-script@7a5c598405937d486b0331594b5da2b14db670da # v6.1.0 + with: + script: | + const { GITHUB_REF_NAME, GITHUB_REF_TYPE, GITHUB_SHA } = process.env + + let helm_version_minor = "${{ matrix.helm }}".split('.').slice(0, -1).join('.') + + let plugin_version = `commit.${context.sha}` + if (GITHUB_REF_TYPE === "branch" && GITHUB_REF_NAME === "master") { + plugin_version = "master" + } + if (GITHUB_REF_TYPE === "tag") { + plugin_version = GITHUB_REF_NAME.replace(/^v/, "") + } + + let build_date = new Date().toISOString() + + core.setOutput('helm_version_minor', helm_version_minor) + core.setOutput('plugin_version', plugin_version) + core.setOutput('build_date', build_date) + core.setOutput('vcs_ref', context.sha) + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a # v.4.0.1 + with: + images: | + hypnoglow/helm-s3 + tags: | + type=semver,pattern={{ version }},suffix=-helm${{ matrix.helm }} + type=semver,pattern={{ version }},suffix=-helm${{ steps.vars.outputs.helm_version_minor }} + type=ref,event=branch,enable={{ is_default_branch }},suffix=-helm${{ matrix.helm }} + type=ref,event=branch,enable={{ is_default_branch }},suffix=-helm${{ steps.vars.outputs.helm_version_minor }} + type=raw,value=commit.{{ sha }},suffix=-helm${{ matrix.helm }} + type=raw,value=commit.{{ sha }},enable={{}},suffix=-helm${{ steps.vars.outputs.helm_version_minor }} + + - name: Login to Docker Hub + uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b # v2.0.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@dc7b9719a96d48369863986a06765841d7ea23f6 # v2.0.0 + + - name: Build and push + uses: docker/build-push-action@e551b19e49efd4e98792db7592c17c09b89db8d8 # v3.0.0 + with: + context: . + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + HELM_VERSION=${{ matrix.helm }} + PLUGIN_VERSION=${{ steps.vars.outputs.plugin_version }} + BUILD_DATE=${{ steps.vars.outputs.build_date }} + VCS_REF=${{ steps.vars.outputs.vcs_ref }} + push: false # TODO diff --git a/Dockerfile b/Dockerfile index e6e6761b..1163c100 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ ARG HELM_VERSION -FROM golang:1.15-alpine as build +FROM golang:1.16-alpine as build ARG PLUGIN_VERSION diff --git a/hack/build.sh b/hack/build.sh index 8df07ebc..9a81b194 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -1,4 +1,9 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash + +set \ + -o errexit \ + -o nounset \ + -o pipefail # This emulates GOPATH presence for go tool. # This is need because helm installs plugins into ~/.helm/plugins. @@ -7,7 +12,7 @@ projectRoot="$1" pkg="$2" if [ ! -e "${GOPATH}/src/${pkg}" ]; then - mkdir -p $(dirname "${GOPATH}/src/${pkg}") + mkdir -p "$(dirname "${GOPATH}/src/${pkg}")" ln -sfn "${projectRoot}" "${GOPATH}/src/${pkg}" fi diff --git a/hack/install.sh b/hack/install.sh index 0151e175..8a6bc056 100755 --- a/hack/install.sh +++ b/hack/install.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash -set -euo pipefail + +set \ + -o errexit \ + -o nounset \ + -o pipefail if [ -n "${HELM_S3_PLUGIN_NO_INSTALL_HOOK:-}" ]; then echo "Development mode: not downloading versioned release."