#############
# BUILD STAGE
#############
FROM registry.redhat.io/ubi8/go-toolset AS builder

# Define the work directory
WORKDIR /opt/app-root/src

# Clone repository
RUN git clone --branch 1.1 --depth 1 --single-branch --no-tags --config http.sslVerify=false https://code.engineering.redhat.com/gerrit/rhi-operator.git

# Move to project directory
WORKDIR /opt/app-root/src/rhi-operator

# Build the operator
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go

# Copy and run licenses script
COPY licenses.sh .
RUN [ "sh", "-x", "licenses.sh" ]

#############
# FINAL STAGE
#############
FROM registry.redhat.io/ubi8/ubi-minimal

LABEL com.redhat.component="rhi-operator-container"
LABEL io.k8s.description="Red Hat® Integration is a comprehensive set of integration and messaging technologies to connect applications and data across hybrid infrastructures. The Red Hat® Integration operator will install underling components across Data, API Management, Messaging and Enterprise Integration Patterns."
LABEL io.k8s.display-name="Red Hat Integration Operator"
LABEL io.openshift.tags="integration"
LABEL maintainer="Alexandre B. Kieling <abrianik@redhat.com>"
LABEL name="integration/rh-integration-rhel8-operator"
LABEL summary="Red Hat Integration Operator"
LABEL version="1.1"

# Define the work directory
WORKDIR /

# Copy files from builder iamge
COPY --from=builder /opt/app-root/src/rhi-operator/manager /manager
COPY --from=builder /opt/app-root/src/rhi-operator/licenses /licenses

# Support arbitrary user ids
# https://docs.openshift.com/container-platform/4.7/openshift_images/create-images.html#use-uid_create-images
RUN chgrp 0 /manager
RUN chmod g=u /manager

# Define the user
USER 1001

# Define entrypoint
ENTRYPOINT ["/manager"]
