FROM openshift/golang-builder:1.16 AS velero-builder
ADD . .
RUN mkdir -p /go/src/github.com/vmware-tanzu/velero
RUN tar --strip-components=1 -xvf release-1.4.6.tar.gz -C /go/src/github.com/vmware-tanzu/velero
RUN cd /go/src/github.com/vmware-tanzu/velero \
&& CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static" -X github.com/vmware-tanzu/velero/pkg/buildinfo.Version=v1.5.2-MTC' ./cmd/velero

FROM openshift/golang-builder:1.16 AS restic-builder
ADD . .
RUN mkdir -p /go/src/github.com/restic/restic
RUN tar --strip-components=1 -xvf restic-release-1.4.6.tar.gz -C /go/src/github.com/restic/restic
RUN cd /go/src/github.com/restic/restic \
&& CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' ./cmd/restic

FROM registry.redhat.io/ubi8/ubi-minimal
RUN microdnf -y install nmap-ncat procps-ng && microdnf clean all
COPY --from=velero-builder /go/src/github.com/vmware-tanzu/velero/velero velero
COPY --from=restic-builder /go/src/github.com/restic/restic/restic /usr/bin/restic

USER nobody:nobody

ENTRYPOINT ["/velero"]

LABEL \
        com.redhat.component="openshift-migration-velero-container" \
        version="v1.4.6" \
        name="rhmtc/openshift-migration-velero" \
        summary="Migration Toolkit for Containers Velero Controller" \
        maintainer="Migration Team <ocp-migrate-team@redhat.com>" \
        License="BSD 2-Clause" \
        io.k8s.display-name="Migration Toolkit for Containers" \
        io.openshift.tags="migration" \
        io.k8s.description="Migration Toolkit for Containers Velero Controller" \
        io.openshift.build.commit.id="04aef5a6f1cd6cdf7226e3f9075e913617378d3d" \
        io.openshift.build.source-location="https://github.com/konveyor/velero" \
        io.openshift.build.commit.url="https://github.com/konveyor/velero/commit/04aef5a6f1cd6cdf7226e3f9075e913617378d3d"
