# Build the manager binary
FROM openshift/golang-builder@sha256:21aab8ec0f5d119e4f6dab12f7ad6a1cec15d5f9071ae0c7431be760f29d4c71 AS builder
ENV __doozer=update BUILD_RELEASE=202203081819.p0.gf6ed01a.assembly.stream BUILD_VERSION=v4.9.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=9 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.9.0-202203081819.p0.gf6ed01a.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge OS_GIT_COMMIT=f6ed01a OS_GIT_VERSION=4.9.0-202203081819.p0.gf6ed01a.assembly.stream-f6ed01a SOURCE_DATE_EPOCH=1636753303 SOURCE_GIT_COMMIT=f6ed01a0aaaab6cb565cf7f2a30fd3cd884f6733 SOURCE_GIT_TAG=f6ed01a SOURCE_GIT_URL=https://github.com/openshift/special-resource-operator 

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
# RUN go mod download

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/

COPY pkg/ pkg/
COPY vendor/ vendor/

# Build
RUN CGO_ENABLED=0 GO111MODULE=on go build -mod=vendor -a -o manager main.go

FROM openshift/ose-base:v4.9.0.20220308.190656
ENV __doozer=update BUILD_RELEASE=202203081819.p0.gf6ed01a.assembly.stream BUILD_VERSION=v4.9.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=9 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.9.0-202203081819.p0.gf6ed01a.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge OS_GIT_COMMIT=f6ed01a OS_GIT_VERSION=4.9.0-202203081819.p0.gf6ed01a.assembly.stream-f6ed01a SOURCE_DATE_EPOCH=1636753303 SOURCE_GIT_COMMIT=f6ed01a0aaaab6cb565cf7f2a30fd3cd884f6733 SOURCE_GIT_TAG=f6ed01a SOURCE_GIT_URL=https://github.com/openshift/special-resource-operator 
WORKDIR /
COPY --from=builder /workspace/manager .

COPY charts/ /charts/
COPY manifests /manifests

RUN useradd  -r -u 499 nonroot
RUN getent group nonroot || groupadd -o -g 499 nonroot

ENTRYPOINT ["/manager"]

LABEL \
        io.k8s.display-name="OpenShift Special Resource Operator" \
        io.k8s.description="This is a component of OpenShift and manages the lifecycle of out-of-tree drivers with enablement stack." \
        name="openshift/special-resource-rhel8-operator" \
        com.redhat.component="special-resource-operator-container" \
        io.openshift.maintainer.product="OpenShift Container Platform" \
        io.openshift.maintainer.component="Special Resource Operator" \
        release="202203081819.p0.gf6ed01a.assembly.stream" \
        io.openshift.build.commit.id="f6ed01a0aaaab6cb565cf7f2a30fd3cd884f6733" \
        io.openshift.build.source-location="https://github.com/openshift/special-resource-operator" \
        io.openshift.build.commit.url="https://github.com/openshift/special-resource-operator/commit/f6ed01a0aaaab6cb565cf7f2a30fd3cd884f6733" \
        version="v4.9.0"

