Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes incorrect logic in determining ImageVersion from LDFlags variable #84

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
phantomjinx marked this conversation as resolved.
Show resolved Hide resolved

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 ?= 1.0.0
HAWTIO_ONLINE_VERSION ?= latest
HAWTIO_ONLINE_IMAGE_NAME ?= docker.io/${ORG}/hawtio
DEBUG ?= false
LAST_RELEASED_IMAGE_NAME := hawtio-operator
LAST_RELEASED_VERSION ?= 0.5.0
Expand Down Expand Up @@ -60,7 +62,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
2 changes: 2 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
// Go build-time variables
var (
ImageRepository string
ImageVersion string
LegacyServingCertificateMountVersion string
ProductName string
ServerRootDirectory string
Expand Down Expand Up @@ -128,6 +129,7 @@ func operatorRun(namespace string, cfg *rest.Config) error {
// Setup all Controllers
bv := util.BuildVariables{
ImageRepository: ImageRepository,
ImageVersion: ImageVersion,
LegacyServingCertificateMountVersion: LegacyServingCertificateMountVersion,
ProductName: ProductName,
ServerRootDirectory: ServerRootDirectory,
Expand Down
2 changes: 1 addition & 1 deletion deploy/setup/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Kustomization
namespace: hawtio

resources:
- ../crd/hawtio_v1alpha1_hawtio_crd.yaml
- ../crd
- ../cluster_role.yaml
- ../cluster_role_binding.yaml
- ../role.yaml
Expand Down
9 changes: 6 additions & 3 deletions pkg/resources/deployment.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resources

import (
"fmt"
"os"
"path"

Expand Down Expand Up @@ -237,11 +238,13 @@ func getServingCertificateMountPath(version string, legacyServingCertificateMoun
}

func getVersion(buildVariables util.BuildVariables) string {
fmt.Println("Getting version from IMAGE_VERSION environment variable ...")
version := os.Getenv("IMAGE_VERSION")
if version == "" {
if len(version) > 0 {
version = buildVariables.ImageVersion
} else {
fmt.Println("Getting version from build variable ImageVersion")
version = buildVariables.ImageVersion
if len(version) == 0 {
fmt.Println("Defaulting to version being latest")
version = "latest"
}
}
Expand Down
Loading