Skip to content

Commit

Permalink
fix: Adds support for LDflags in Dockerfile for testing #83
Browse files Browse the repository at this point in the history
* Dockerfile / Makefile
  * Provides support for adding LDflags for IMAGE_VERSION and
    IMAGE_REPOSITORY to go build command
  * Default added for args in case Dockerfile is used to be built without
    specifying args
  • Loading branch information
phantomjinx authored and tadayosi committed Nov 28, 2023
1 parent 14fa575 commit 4af0c40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
FROM golang:1.20-alpine3.18 AS builder

ARG HAWTIO_ONLINE_VERSION=latest
ARG HAWTIO_ONLINE_IMAGE_NAME=docker.io/hawtio/hawtio

ENV IMAGE_VERSION_FLAG="-X main.ImageVersion=${HAWTIO_ONLINE_VERSION}"
ENV IMAGE_REPOSITORY_FLAG="-X main.ImageRepository=${HAWTIO_ONLINE_IMAGE_NAME}"

ENV GOLDFLAGS="${IMAGE_VERSION_FLAG} ${IMAGE_REPOSITORY_FLAG}"

RUN apk update
RUN apk add git make

WORKDIR /hawtio-operator

COPY . .

RUN make build
RUN GOLDFLAGS=${GOLDFLAGS} make build

FROM alpine:3.18

Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
ORG = hawtio
NAMESPACE ?= hawtio
PROJECT = operator
DEFAULT_IMAGE := docker.io/hawtio/operator
DEFAULT_IMAGE := docker.io/${ORG}/${PROJECT}
IMAGE ?= $(DEFAULT_IMAGE)
DEFAULT_TAG := latest
TAG ?= $(DEFAULT_TAG)
VERSION ?= 0.5.0
HAWTIO_ONLINE_VERSION ?= latest
HAWTIO_ONLINE_IMAGE_NAME ?= docker.io/${ORG}/hawtio
DEBUG ?= false

CONTROLLER_GEN_VERSION := v0.6.1
Expand Down Expand Up @@ -54,7 +56,10 @@ endef
default: image

image:
docker build -t docker.io/${ORG}/${PROJECT}:${TAG} .
docker build -t ${IMAGE}:${TAG} \
--build-arg HAWTIO_ONLINE_IMAGE_NAME=${HAWTIO_ONLINE_IMAGE_NAME} \
--build-arg HAWTIO_ONLINE_VERSION=${HAWTIO_ONLINE_VERSION} \
.

build: go-generate compile test

Expand Down

0 comments on commit 4af0c40

Please sign in to comment.