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.5.0.tar.gz -C /go/src/github.com/vmware-tanzu/velero
RUN tar --strip-components=1 -xvf velero-deps.tar.gz -C  /go/src/github.com/vmware-tanzu/velero
RUN cd /go/src/github.com/vmware-tanzu/velero \
&& GO111MODULE=auto CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static" -X github.com/vmware-tanzu/velero/pkg/buildinfo.Version=v1.6.0-MTC' -mod=vendor ./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.5.0.tar.gz -C /go/src/github.com/restic/restic
RUN tar --strip-components=1 -xvf restic-deps.tar.gz -C /go/src/github.com/restic/restic
RUN cd /go/src/github.com/restic/restic \
&& GO111MODULE=auto CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -mod=vendor ./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.5.0" \
        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="8a8af88e59b76774e16aa61ffb9672f79e38af51" \
        io.openshift.build.source-location="https://github.com/konveyor/velero" \
        io.openshift.build.commit.url="https://github.com/konveyor/velero/commit/8a8af88e59b76774e16aa61ffb9672f79e38af51"
