Skip to content

Commit 25b79aa

Browse files
author
Andrei Alexandru
authored
Merge pull request #2 from aalexandru/devel-build-workflow
Release workflow to build and push docker images
2 parents bbbf8e6 + 7ac1778 commit 25b79aa

File tree

6 files changed

+109
-2
lines changed

6 files changed

+109
-2
lines changed

.github/workflows/release.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'release-*'
8+
tags:
9+
- 'v*'
10+
11+
jobs:
12+
publish-docker-image-to-ghcr:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
- name: Import environment variables from file
18+
run: cat ".github/env" >> $GITHUB_ENV
19+
- name: Install Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: '${{ env.golang-version }}'
23+
- name: Login to ghcr.io
24+
if: github.event_name != 'pull_request'
25+
uses: docker/login-action@v1
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
- name: Build and push Docker images
31+
run: make release

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
docker/
1010

1111
# build artifacts
12-
cluster-registry
12+
cluster-registry*
1313
kubeconfig
1414
.dynamodb
15+
.hack*
1516

1617
# Binaries for programs and plugins
1718
bin

Makefile

+31-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,37 @@ clean:
4646
############
4747

4848
.PHONY: build
49-
build: # TODO
49+
build: build-api build-cc
50+
51+
.PHONY: build-api
52+
build-api:
53+
$(GO_BUILD_RECIPE) -o cluster-registry-api cmd/api/api.go
54+
55+
.PHONY: build-cc
56+
build-cc:
57+
$(GO_BUILD_RECIPE) -o cluster-registry-client cmd/cc/client.go
58+
59+
.PHONY: release
60+
release:
61+
./hack/release.sh
62+
63+
.PHONY: image
64+
image: .hack-api-image .hack-cc-image
65+
66+
.hack-api-image: cmd/api/Dockerfile build-api
67+
docker build -t $(IMAGE_API):$(TAG) -f cmd/api/Dockerfile .
68+
touch $@
69+
70+
.hack-cc-image: cmd/cc/Dockerfile build-cc
71+
docker build -t $(IMAGE_CC):$(TAG) -f cmd/cc/Dockerfile .
72+
touch $@
73+
74+
.PHONY: update-go-deps
75+
update-go-deps:
76+
for m in $$(go list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
77+
go get $$m; \
78+
done
79+
@echo "Don't forget to run 'make tidy'"
5080

5181

5282
##############

cmd/api/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM alpine
2+
RUN apk add --update --no-cache ca-certificates
3+
ADD cluster-registry-api /bin/api
4+
USER nobody
5+
EXPOSE 8080
6+
ENTRYPOINT ["/bin/api"]

cmd/cc/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM alpine
2+
RUN apk add --update --no-cache ca-certificates
3+
ADD cluster-registry-client /bin/client
4+
USER nobody
5+
ENTRYPOINT ["/bin/client"]

hack/release.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
# exit immediately when a command fails
3+
set -e
4+
# only exit with zero if all commands of the pipeline exit successfully
5+
set -o pipefail
6+
7+
REGISTRY="ghcr.io"
8+
9+
export IMAGE_API="${IMAGE_API:-"adobe/cluster-registry-api"}"
10+
export IMAGE_CC="${IMAGE_CC:-"adobe/cluster-registry-client"}"
11+
export TAG="${GITHUB_REF##*/}"
12+
13+
IMAGE_SUFFIX="-dev"
14+
15+
if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+ ]] || [ "${TAG}" == "main" ]; then
16+
IMAGE_SUFFIX=""
17+
else
18+
TAG="v$(cat "$(git rev-parse --show-toplevel)/VERSION")-$(git rev-parse --short HEAD)"
19+
fi
20+
21+
API="${REGISTRY}/${IMAGE_API}${IMAGE_SUFFIX}"
22+
CC="${REGISTRY}/${IMAGE_CC}${IMAGE_SUFFIX}"
23+
24+
for img in ${API} ${CC}; do
25+
echo "Building image: $img:$TAG"
26+
done
27+
28+
make --always-make image TAG="${TAG}"
29+
30+
docker tag "${IMAGE_API}:${TAG}" "${API}:${TAG}"
31+
docker tag "${IMAGE_CC}:${TAG}" "${CC}:${TAG}"
32+
33+
docker push "${API}:${TAG}"
34+
docker push "${CC}:${TAG}"

0 commit comments

Comments
 (0)