#@follow_tag(registry.redhat.io/rhel8-2-els/rhel)
FROM registry.redhat.io/rhel8-2-els/rhel:8.2-7 AS builder

ENV GOPATH=/go

RUN echo -e "[go-toolset]\nname=go-toolset\nprofiles=\nstate=enabled\nstream=rhel8" > /etc/dnf/modules.d/go-toolset.module \
    && dnf install -y git sed go-compilers-golang-compiler tar gzip

COPY kubevirt-template-validator-6ff89fc61ba848220c3225a6b7bebf6561655b5d.tar.gz /
RUN mkdir -p /go/src/github.com/fromanirh/kubevirt-template-validator && \
    tar -xzf /kubevirt-template-validator-6ff89fc61ba848220c3225a6b7bebf6561655b5d.tar.gz --strip-components 1 \
        -C /go/src/github.com/fromanirh/kubevirt-template-validator
WORKDIR ${GOPATH}/src/github.com/fromanirh/kubevirt-template-validator

RUN ./hack/build/build.sh v0.7.0

#@follow_tag(registry.redhat.io/rhel8-2-els/rhel)
FROM registry.redhat.io/rhel8-2-els/rhel:8.2-7
RUN mkdir -p /etc/webhook/certs
COPY --from=builder /go/src/github.com/fromanirh/kubevirt-template-validator/cmd/kubevirt-template-validator/kubevirt-template-validator /usr/sbin/kubevirt-template-validator
ENTRYPOINT [ "/usr/sbin/kubevirt-template-validator" ]

LABEL com.redhat.component="kubevirt-template-validator-container" \
      name="container-native-virtualization/kubevirt-template-validator" \
      version="v2.5.3" \
      upstream-version="v0.7.0" \
      summary="validating webhook to check templates sent to the cluster" \
      upstream-vcs-type="git" \
      io.openshift.expose-services="" \
      io.openshift.tags="cnv,kubevirt,template,validation" \
      io.k8s.display-name="kubevirt-template-validator" \
      maintainer="The KubeVirt Project <kubevirt-dev@googlegroups.com" \
      description="kubevirt-template-validator is a kubevirt addon to check the annotations on templates and reject them if unvalid. It is implemented using a validating webhook."
