From 82c0dc8c0f34ec20d98e84a40c1a0ba9fa9c1a76 Mon Sep 17 00:00:00 2001 From: aalexandru Date: Wed, 15 Dec 2021 15:38:43 +0200 Subject: [PATCH 1/4] added release workflow to build and push docker images --- .github/workflows/release.yml | 28 +++++++++++++++++++++++++++ .gitignore | 3 ++- Makefile | 32 ++++++++++++++++++++++++++++++- cmd/api/Dockerfile | 6 ++++++ cmd/cc/Dockerfile | 5 +++++ hack/release.sh | 36 +++++++++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 cmd/api/Dockerfile create mode 100644 cmd/cc/Dockerfile create mode 100755 hack/release.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..05e89bb6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: release + +on: + workflow_dispatch: + push: + branches: + - 'release-*' + tags: + - 'v*' + +jobs: + publish-docker-image-to-ghcr: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Login to ghcr.io + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push Docker images + run: make release \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3e57913a..f2ba5d57 100644 --- a/.gitignore +++ b/.gitignore @@ -9,9 +9,10 @@ docker/ # build artifacts -cluster-registry +cluster-registry* kubeconfig .dynamodb +.hack* # Binaries for programs and plugins bin diff --git a/Makefile b/Makefile index c92224de..690bbd4a 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,37 @@ clean: ############ .PHONY: build -build: # TODO +build: build-api build-cc + +.PHONY: build-api +build-api: + $(GO_BUILD_RECIPE) -o cluster-registry-api cmd/api/api.go + +.PHONY: build-cc +build-cc: + $(GO_BUILD_RECIPE) -o cluster-registry-client cmd/cc/client.go + +.PHONY: release +release: + ./hack/release.sh + +.PHONY: image +image: .hack-api-image .hack-cc-image + +.hack-api-image: cmd/api/Dockerfile build-api + docker build -t $(IMAGE_API):$(TAG) -f cmd/api/Dockerfile . + touch $@ + +.hack-cc-image: cmd/cc/Dockerfile build-cc + docker build -t $(IMAGE_CC):$(TAG) -f cmd/cc/Dockerfile . + touch $@ + +.PHONY: update-go-deps +update-go-deps: + for m in $$(go list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \ + go get $$m; \ + done + @echo "Don't forget to run 'make tidy'" ############## diff --git a/cmd/api/Dockerfile b/cmd/api/Dockerfile new file mode 100644 index 00000000..7c1d4320 --- /dev/null +++ b/cmd/api/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine +RUN apk add --update --no-cache ca-certificates +ADD cluster-registry-api /bin/api +USER nobody +EXPOSE 8080 +ENTRYPOINT ["/bin/api"] diff --git a/cmd/cc/Dockerfile b/cmd/cc/Dockerfile new file mode 100644 index 00000000..431304c8 --- /dev/null +++ b/cmd/cc/Dockerfile @@ -0,0 +1,5 @@ +FROM alpine +RUN apk add --update --no-cache ca-certificates +ADD cluster-registry-client /bin/client +USER nobody +ENTRYPOINT ["/bin/client"] diff --git a/hack/release.sh b/hack/release.sh new file mode 100755 index 00000000..a9f98934 --- /dev/null +++ b/hack/release.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# exit immediately when a command fails +set -e +# only exit with zero if all commands of the pipeline exit successfully +set -o pipefail + +REGISTRY="ghcr.io" + +export IMAGE_API="${IMAGE_API:-"adobe/cluster-registry/api"}" +export IMAGE_CC="${IMAGE_CC:-"adobe/cluster-registry/cc"}" +export TAG="${GITHUB_REF##*/}" + +echo "tag: ${TAG}" + +IMAGE_SUFFIX="-dev" + +if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+ ]] || [ "${TAG}" == "main" ]; then + IMAGE_SUFFIX="" +else + TAG="v$(cat "$(git rev-parse --show-toplevel)/VERSION")-$(git rev-parse --short HEAD)" +fi + +API="${REGISTRY}/${IMAGE_API}${IMAGE_SUFFIX}" +CC="${REGISTRY}/${IMAGE_CC}${IMAGE_SUFFIX}" + +for img in ${API} ${CC}; do + echo "Building image: $img:$TAG" +done + +make --always-make image TAG="${TAG}" + +docker tag "${IMAGE_API}:${TAG}" "${API}:${TAG}" +docker tag "${IMAGE_CC}:${TAG}" "${CC}:${TAG}" + +docker push "${API}:${TAG}" +docker push "${CC}:${TAG}" \ No newline at end of file From 48b2969e44507e11a2a6591fa8ec2095d556ae86 Mon Sep 17 00:00:00 2001 From: aalexandru Date: Wed, 15 Dec 2021 15:48:53 +0200 Subject: [PATCH 2/4] added setup-go step --- .github/workflows/release.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 05e89bb6..4b5204db 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,12 +11,15 @@ on: jobs: publish-docker-image-to-ghcr: runs-on: ubuntu-latest - permissions: - contents: read - packages: write steps: - name: Checkout repository uses: actions/checkout@v2 + - name: Import environment variables from file + run: cat ".github/env" >> $GITHUB_ENV + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: '${{ env.golang-version }}' - name: Login to ghcr.io if: github.event_name != 'pull_request' uses: docker/login-action@v1 From a007bb526332f7d5b1d8d8ab82cef294c534e11b Mon Sep 17 00:00:00 2001 From: aalexandru Date: Wed, 15 Dec 2021 17:23:17 +0200 Subject: [PATCH 3/4] renamed docker images --- hack/release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hack/release.sh b/hack/release.sh index a9f98934..8ae411f0 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -6,8 +6,8 @@ set -o pipefail REGISTRY="ghcr.io" -export IMAGE_API="${IMAGE_API:-"adobe/cluster-registry/api"}" -export IMAGE_CC="${IMAGE_CC:-"adobe/cluster-registry/cc"}" +export IMAGE_API="${IMAGE_API:-"adobe/cluster-registry-api"}" +export IMAGE_CC="${IMAGE_CC:-"adobe/cluster-registry-client"}" export TAG="${GITHUB_REF##*/}" echo "tag: ${TAG}" From 7ac1778dd89fe26ea74ca6fd7821301a64e8b90a Mon Sep 17 00:00:00 2001 From: aalexandru Date: Wed, 15 Dec 2021 17:26:30 +0200 Subject: [PATCH 4/4] removed comment --- hack/release.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/hack/release.sh b/hack/release.sh index 8ae411f0..c41ef5ed 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -10,8 +10,6 @@ export IMAGE_API="${IMAGE_API:-"adobe/cluster-registry-api"}" export IMAGE_CC="${IMAGE_CC:-"adobe/cluster-registry-client"}" export TAG="${GITHUB_REF##*/}" -echo "tag: ${TAG}" - IMAGE_SUFFIX="-dev" if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+ ]] || [ "${TAG}" == "main" ]; then