Skip to content

Commit

Permalink
This change ensures the openstack-ansibleee-operator is built with FI…
Browse files Browse the repository at this point in the history
…PS compliance

* Changed the address of the builder image using fqdn
* Added the GO_BUILD_EXTRA_ENV_ARGS build argument to allow
  custom build arguments at build time. It defaults to
  "CGO_ENABLED=1 GO111MODULE=on"
* Those default parameters have been added to enable FIPS compliance
* Fixed indentation
* Removed TARGETOS and TARGETARCH env vars
* Added DOCKER_BUILD_ARGS variable in Makefile to pass custom parameters
  during `podman build`

Closes: https://issues.redhat.com/browse/OSPRH-3396

Signed-off-by: Roberto Alfieri <[email protected]>
  • Loading branch information
rebtoor committed Jan 30, 2024
1 parent ba3c70f commit 5082a45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
21 changes: 10 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GOLANG_BUILDER=golang:1.19
ARG GOLANG_BUILDER=quay.io/projectquay/golang:1.19
ARG OPERATOR_BASE_IMAGE=gcr.io/distroless/static:nonroot

# Build the manager binary
Expand All @@ -12,9 +12,8 @@ ARG REMOTE_SOURCE_DIR=/remote-source
ARG REMOTE_SOURCE_SUBDIR=
ARG DEST_ROOT=/dest-root

ARG TARGETOS
ARG TARGETARCH
ARG GO_BUILD_EXTRA_ARGS=
ARG GO_BUILD_EXTRA_ENV_ARGS="CGO_ENABLED=1 GO111MODULE=on"

COPY $REMOTE_SOURCE $REMOTE_SOURCE_DIR
WORKDIR $REMOTE_SOURCE_DIR/$REMOTE_SOURCE_SUBDIR
Expand All @@ -26,7 +25,7 @@ RUN mkdir -p ${DEST_ROOT}/usr/local/bin/
RUN if [ ! -f $CACHITO_ENV_FILE ]; then go mod download ; fi

# Build manager
RUN if [ -f $CACHITO_ENV_FILE ] ; then source $CACHITO_ENV_FILE ; fi ; CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} GO111MODULE=on go build ${GO_BUILD_EXTRA_ARGS} -a -o ${DEST_ROOT}/manager main.go
RUN if [ -f $CACHITO_ENV_FILE ] ; then source $CACHITO_ENV_FILE ; fi ; env ${GO_BUILD_EXTRA_ENV_ARGS} go build ${GO_BUILD_EXTRA_ARGS} -a -o ${DEST_ROOT}/manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand All @@ -49,16 +48,16 @@ ARG IMAGE_TAGS="cn-openstack openstack"

# Labels required by upstream and osbs build system
LABEL com.redhat.component="${IMAGE_COMPONENT}" \
name="${IMAGE_NAME}" \
version="${IMAGE_VERSION}" \
summary="${IMAGE_SUMMARY}" \
io.k8s.name="${IMAGE_NAME}" \
io.k8s.description="${IMAGE_DESC}" \
io.openshift.tags="${IMAGE_TAGS}"
name="${IMAGE_NAME}" \
version="${IMAGE_VERSION}" \
summary="${IMAGE_SUMMARY}" \
io.k8s.name="${IMAGE_NAME}" \
io.k8s.description="${IMAGE_DESC}" \
io.openshift.tags="${IMAGE_TAGS}"
### DO NOT EDIT LINES ABOVE

ENV USER_UID=$USER_ID \
OPERATOR_TEMPLATES=/usr/share/ansibleee-operator/templates/
OPERATOR_TEMPLATES=/usr/share/ansibleee-operator/templates/

WORKDIR /

Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

# Extra vars which will be passed to the Docker-build
DOCKER_BUILD_ARGS ?=

.PHONY: all
all: build

Expand Down Expand Up @@ -141,7 +144,7 @@ run: manifests generate fmt vet ## Run a controller from your host.

.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
podman build -t ${IMG} .
podman build -t ${IMG} . ${DOCKER_BUILD_ARGS}

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
Expand Down

0 comments on commit 5082a45

Please sign in to comment.