Skip to content

Commit

Permalink
ci: add docker images to GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hypnoglow committed Aug 23, 2022
1 parent e37b0fc commit 72ebdee
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 124 deletions.
115 changes: 0 additions & 115 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -99,61 +59,13 @@ jobs:
if [ -n "$CIRCLE_TAG" ]; then
curl -sL https://git.io/goreleaser | bash
fi
docker-helm-2_17:
docker:
- image: circleci/buildpack-deps:stretch
steps:
- attach_workspace:
at: .
- setup_remote_docker:
version: 18.06.0-ce
- build_push_docker_image:
helm_version: 2.17.0
docker-helm-3_8:
docker:
- image: circleci/buildpack-deps:stretch
steps:
- attach_workspace:
at: .
- setup_remote_docker:
version: 18.06.0-ce
- build_push_docker_image:
helm_version: 3.8.2
docker-helm-3_9:
docker:
- image: circleci/buildpack-deps:stretch
steps:
- attach_workspace:
at: .
- setup_remote_docker:
version: 18.06.0-ce
- build_push_docker_image:
helm_version: 3.9.3
workflows:
version: 2
# test-pipeline runs on each push and merge, and does not run on tags.
test-pipeline:
jobs:
- dep
- docker-helm-2_17:
requires:
- dep
filters:
branches:
only: master
- docker-helm-3_8:
requires:
- dep
filters:
branches:
only: master
- docker-helm-3_9:
requires:
- dep
filters:
branches:
only: master
- test-install:
filters:
branches:
Expand All @@ -167,36 +79,9 @@ workflows:
only: /.*/
branches:
ignore: /.*/
- docker-helm-2_17:
requires:
- dep
filters:
tags:
only: /.*/
branches:
ignore: /.*/
- docker-helm-3_8:
requires:
- dep
filters:
tags:
only: /.*/
branches:
ignore: /.*/
- docker-helm-3_9:
requires:
- dep
filters:
tags:
only: /.*/
branches:
ignore: /.*/
- release:
requires:
- dep
- docker-helm-2_17
- docker-helm-3_8
- docker-helm-3_9
filters:
tags:
only: /.*/
Expand Down
30 changes: 24 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,23 +32,30 @@ 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.48
args: --verbose
# See: https://github.com/golangci/golangci-lint-action/issues/244
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/helm-s3
test-e2e:
name: Run end-to-end tests
needs:
- build
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -76,16 +84,18 @@ 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
run: |
go mod download -x
go mod vendor
- name: Install helm
run: |
Expand Down Expand Up @@ -135,3 +145,11 @@ jobs:
- name: Run tests
run: |
go test -v ./tests/e2e/...
docker-images:
needs:
- test-e2e
uses: ./.github/workflows/reusable-docker-images.yml
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
97 changes: 97 additions & 0 deletions .github/workflows/reusable-docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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.8.2
- 3.9.3
env:
IMAGE_NAME: hypnoglow/helm-s3
HELM_VERSION: ${{ matrix.helm }}
steps:

- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2

- name: Setup Go
uses: actions/setup-go@b22fbbc2921299758641fab08929b4ac52b32923 # v3.2.0
with:
cache: true
go-version-file: 'go.mod'

- name: Download dependencies
run: |
go mod download -x
- 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 # v4.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 }},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: true # TODO: only push on master and tags.
9 changes: 7 additions & 2 deletions hack/build.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion hack/install.sh
Original file line number Diff line number Diff line change
@@ -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."
Expand Down

0 comments on commit 72ebdee

Please sign in to comment.