FROM openshift/golang-builder:1.16 AS build-env

# cachito
COPY $REMOTE_SOURCE $REMOTE_SOURCE_DIR
WORKDIR $REMOTE_SOURCE_DIR/app

ENV GOOS=linux
ENV CGO_ENABLED=0
ENV BROKER_NAME=amq-broker

RUN export
RUN which go
RUN go version
RUN go build -v -o bin/${BROKER_NAME}-operator ${REMOTE_SOURCE_DIR}/app/main.go


FROM registry.redhat.io/ubi8:8.6-754 AS base-env

ENV BROKER_NAME=amq-broker
ENV OPERATOR=/home/${BROKER_NAME}-operator/bin/${BROKER_NAME}-operator
ENV USER_UID=1000
ENV USER_NAME=${BROKER_NAME}-operator
ENV CGO_ENABLED=0
ENV JBOSS_IMAGE_NAME="amq7/amq-broker-rhel8-operator"
ENV JBOSS_IMAGE_VERSION="7.10.0.OPR.1.CR4"

WORKDIR /
RUN mkdir -p /home/${BROKER_NAME}-operator/bin
COPY --from=build-env $REMOTE_SOURCE_DIR/app/entrypoint/entrypoint /home/${BROKER_NAME}-operator/bin
COPY --from=build-env $REMOTE_SOURCE_DIR/app/bin/${BROKER_NAME}-operator /home/${BROKER_NAME}-operator/bin

RUN chown -R `id -u`:0 /home/${BROKER_NAME}-operator/bin && chmod -R 755 /home/${BROKER_NAME}-operator/bin

USER ${USER_UID}
ENTRYPOINT ["/home/${BROKER_NAME}-operator/bin/entrypoint"]

LABEL \
      com.redhat.component="amq-broker-rhel8-operator-container"  \
      description="Red Hat AMQ Broker 7.10 Operator"  \
      io.k8s.description="An associated operator that handles broker installation, updates and scaling."  \
      io.k8s.display-name="Red Hat AMQ Broker 7.10 Operator"  \
      io.openshift.expose-services=""  \
      io.openshift.s2i.scripts-url="image:///usr/local/s2i"  \
      io.openshift.tags="messaging,amq,integration,operator,golang"  \
      maintainer="Roddie Kieley <rkieley@redhat.com>"  \
      name="amq7/amq-broker-rhel8-operator" \
      summary="Red Hat AMQ Broker 7.10 Operator"  \
      version="7.10"

