Skip to content

Commit

Permalink
Add version flag
Browse files Browse the repository at this point in the history
Add the version flag to the command flags
and also update Dockerfile to accept the
version build-arg using the

	git describe --tags --always

so we can populate the version with
either the last git tag or the last
git tag with the current SHA.

Also updates the Makefile and the
Github action script

Signed-off-by: Raymond Etornam <retornam@users.noreply.github.com>
  • Loading branch information
ddl-retornam committed Aug 23, 2024
1 parent 0721c50 commit 10f3fcb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .github/actions/push-docker-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ outputs:
runs:
using: composite
steps:
- id: git_tag
name: Get the Git tag
shell: bash
run: |
echo "VERSION_BUILDARG=$(git describe --tags --always)" >> $GITHUB_ENV
- name: Login to container registry
uses: docker/login-action@v3
with:
Expand All @@ -49,6 +54,8 @@ runs:
with:
context: .
platforms: ${{ inputs.platforms }}
build-args: |
VERSION=${{ env.VERSION_BUILDARG }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM golang:1.22-alpine AS build
FROM golang:1.23-alpine AS build
ARG VERSION=dev
ENV VERSION=${VERSION}
WORKDIR /app
COPY go.mod .
COPY go.sum .
Expand All @@ -7,7 +9,7 @@ COPY cmd ./cmd
COPY pkg ./pkg
COPY deployments/crds ./deployments/crds
ENV CGO_ENABLED=0 GOOS=linux
RUN go build -o hephaestus-controller ./cmd/controller
RUN go build -ldflags="-X 'main.Version=${VERSION}'" -o hephaestus-controller ./cmd/controller

FROM gcr.io/distroless/static:nonroot
WORKDIR /
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
SHELL:=/bin/bash
VERSION=$(git describe --tags --always)

##@ Development

.PHONY: build
build: ## Build controller binary
go build -v -o bin/hephaestus-controller ./cmd/controller/
go build -ldflags="-X 'main.Version=${VERSION}'" -o hephaestus-controller ./cmd/controller

docker: ## Build docker image
docker build -t ghcr.io/dominodatalab/hephaestus:latest .
docker build --build-arg VERSION=${VERSION} -t ghcr.io/dominodatalab/hephaestus:latest .

.PHONY: test
test: ## Run test suite
Expand Down
13 changes: 13 additions & 0 deletions pkg/cmd/controller/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/dominodatalab/hephaestus/pkg/crd"
)

var Version = "dev"

func NewCommand() *cobra.Command {
var cfgFile string

Expand All @@ -26,11 +28,22 @@ func NewCommand() *cobra.Command {
newStartCommand(),
newCRDApplyCommand(),
newCRDDeleteCommand(),
versionCommand(),
)

return cmd
}

func versionCommand() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "prints version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(Version)
},
}
}

func newStartCommand() *cobra.Command {
return &cobra.Command{
Use: "start",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine AS build
FROM golang:1.23-alpine AS build
WORKDIR /app
RUN echo -e 'package main\n\
import "fmt"\n\
Expand Down

0 comments on commit 10f3fcb

Please sign in to comment.