Skip to content

Commit

Permalink
✨ Add git commit to the to the images (stolostron#1169)
Browse files Browse the repository at this point in the history
* add git commit to the to the image and container

Signed-off-by: myan <[email protected]>

* add image

Signed-off-by: myan <[email protected]>

* replace the env

Signed-off-by: myan <[email protected]>

---------

Signed-off-by: myan <[email protected]>
  • Loading branch information
yanmxa authored Oct 17, 2024
1 parent 0c5fe6a commit 9b3e845
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ REGISTRY ?= quay.io/stolostron
IMAGE_TAG ?= latest
TMP_BIN ?= /tmp/cr-tests-bin
GO_TEST ?= go test -v
GIT_COMMIT := $(shell git rev-parse --short HEAD)

.PHONY: vendor ##download all third party libraries and puts them inside vendor directory
vendor:
Expand All @@ -22,7 +23,7 @@ clean-vendor:

build-operator-image: vendor
cd operator && make
docker build -t ${REGISTRY}/multicluster-global-hub-operator:${IMAGE_TAG} . -f operator/Dockerfile
docker build -t ${REGISTRY}/multicluster-global-hub-operator:${IMAGE_TAG} . -f operator/Dockerfile --build-arg GIT_COMMIT=$(GIT_COMMIT)

push-operator-image:
docker push ${REGISTRY}/multicluster-global-hub-operator:${IMAGE_TAG}
Expand All @@ -35,14 +36,14 @@ undeploy-operator:

build-manager-image: vendor
cd manager && make
docker build -t ${REGISTRY}/multicluster-global-hub-manager:${IMAGE_TAG} . -f manager/Dockerfile
docker build -t ${REGISTRY}/multicluster-global-hub-manager:${IMAGE_TAG} . -f manager/Dockerfile --build-arg GIT_COMMIT=$(GIT_COMMIT)

push-manager-image:
docker push ${REGISTRY}/multicluster-global-hub-manager:${IMAGE_TAG}

build-agent-image: vendor
cd agent && make
docker build -t ${REGISTRY}/multicluster-global-hub-agent:${IMAGE_TAG} . -f agent/Dockerfile
docker build -t ${REGISTRY}/multicluster-global-hub-agent:${IMAGE_TAG} . -f agent/Dockerfile --build-arg GIT_COMMIT=$(GIT_COMMIT)

push-agent-image:
docker push ${REGISTRY}/multicluster-global-hub-agent:${IMAGE_TAG}
Expand Down
2 changes: 2 additions & 0 deletions agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ RUN go build -o bin/agent ./agent/cmd/main.go

# Stage 2: Copy the binaries from the image builder to the base image
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
ARG GIT_COMMIT
ENV USER_UID=1001
ENV USER_NAME=agent
ENV GIT_COMMIT=${GIT_COMMIT}

# install operator binary
COPY --from=builder /workspace/bin/agent /usr/local/bin/agent
Expand Down
7 changes: 4 additions & 3 deletions manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ RUN go build -o bin/manager ./manager/cmd/manager/main.go

# Stage 2: Copy the binaries from the image builder to the base image
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
ARG GIT_COMMIT
ENV USER_UID=1001
ENV USER_NAME=manager
ENV GIT_COMMIT=${GIT_COMMIT}

# install operator binary
COPY --from=builder /workspace/bin/manager /usr/local/bin/manager

COPY ./manager/scripts/user_setup /usr/local/scripts/user_setup
RUN /usr/local/scripts/user_setup
RUN /usr/local/scripts/user_setup

RUN microdnf update -y && \
microdnf clean all
RUN microdnf update -y && microdnf clean all

USER ${USER_UID}
ENTRYPOINT ["/usr/local/bin/manager"]
10 changes: 6 additions & 4 deletions operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ RUN CGO_ENABLED=1 go build -a -installsuffix cgo -o bin/multicluster-global-hub-

# Stage 2: Copy the binaries from the image builder to the base image
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest

ARG GIT_COMMIT
ENV OPERATOR=/usr/local/bin/multicluster-global-hub-operator \
USER_UID=1001 \
USER_NAME=operator
USER_UID=1001 \
USER_NAME=operator
ENV GIT_COMMIT=${GIT_COMMIT}


# install operator binary
COPY --from=builder /workspace/bin/multicluster-global-hub-operator ${OPERATOR}

RUN microdnf update -y && \
microdnf clean all
microdnf clean all

USER ${USER_UID}
ENTRYPOINT ["/usr/local/bin/multicluster-global-hub-operator"]
1 change: 1 addition & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
func PrintVersion(log logr.Logger) {
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
log.Info(fmt.Sprintf("Git Commit: %s", os.Getenv("GIT_COMMIT")))
}

func CtrlZapOptions() zap.Options {
Expand Down

0 comments on commit 9b3e845

Please sign in to comment.