Skip to content

Commit

Permalink
Add workflow for tag push
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Kosegi <[email protected]>
  • Loading branch information
rkosegi committed Feb 1, 2024
1 parent 61a09e8 commit 4050b03
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/tag_push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: Push container image on tag push

on:
push:
tags:
- '*'
workflow_dispatch:

env:
REGISTRY: ghcr.io

jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}

- name: Get build timestamp
run: echo "{now}=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT

- name: Build and push Docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
context: .
push: true
platforms: linux/amd64
build-args: |
GIT_COMMIT=${{ github.sha }}
VERSION=${{ github.ref_name }}
BUILD_DATE=${{ steps.build-timestamp.outputs.now }}
tags: ${{ env.REGISTRY }}/${{ github.repository }}:${{ github.ref_name }}
labels: ${{ steps.meta.outputs.labels }}
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
ARG GOVERSION=1.21

FROM golang:${GOVERSION} as builder
ARG GOARCH
ENV GOARCH=${GOARCH}

WORKDIR /build
COPY . /build

RUN make build-local

FROM gcr.io/distroless/static:latest-${GOARCH}
FROM gcr.io/distroless/static:latest
ARG VERSION
ARG BUILD_DATE
ARG GIT_COMMIT
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ USER ?= $(shell id -u -n)
HOST ?= $(shell hostname)

bump-patch-version:
@echo Current: $(VER_CURRENT)
@echo Current: $(VERSION)
@echo Next: $(VER_NEXT_PATCH)
@echo "$(VER_NEXT_PATCH)" > VERSION
sed -i 's/^appVersion: .*/appVersion: $(VER_NEXT_PATCH)/g' chart/Chart.yaml
sed -i 's/^version: .*/version: $(VER_NEXT_PATCH)/g' chart/Chart.yaml
git add -- Makefile chart/Chart.yaml
git add -- VERSION Makefile chart/Chart.yaml
git commit -sm "Bump version to $(VER_NEXT_PATCH)"

git-tag:
git tag -am "Release $(VERSION)" $(VERSION)

new-release: bump-patch-version git-tag

update-go-deps:
@for m in $$(go list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
go get -d $$m; \
Expand All @@ -68,10 +70,8 @@ build-local:
build-docker:
$(DOCKER) build -t $(IMAGE):$(VERSION) \
--build-arg GOVERSION=$(GO_VERSION) \
--build-arg GOARCH=$(ARCH) \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
.

.PHONY: build-local build-docker clean lint test gen-docs update-go-deps bump-patch-version

0 comments on commit 4050b03

Please sign in to comment.