FROM openshift3/golang-builder AS builder

ENV HAWTIO_OPERATOR_VERSION=1.0.0.fuse-770012-redhat-00002 \
    HAWTIO_OPERATOR_TAG=c4005d9057503fb7482b3add0c36596218290683

COPY hawtio-operator-$HAWTIO_OPERATOR_TAG.tar.gz /
RUN tar zxf /hawtio-operator-$HAWTIO_OPERATOR_TAG.tar.gz -C /

COPY gen-licenses.sh /

RUN [ "/bin/bash", "-lc", "mkdir -p /go/src/github.com/hawtio/ \
    && mv /hawtio-operator-$HAWTIO_OPERATOR_TAG /go/src/github.com/hawtio/hawtio-operator \
    && cd /go/src/github.com/hawtio/hawtio-operator \
    && go build -o /hawtio-operator -ldflags \"-X github.com/hawtio/hawtio-operator/pkg/controller/hawtio.ImageRepository=registry.redhat.io/fuse7/fuse-console -X 'github.com/hawtio/hawtio-operator/pkg/controller/hawtio.LegacyServingCertificateMountVersion=< 1.5.0'\" ./cmd/manager/main.go" ]

# Generate licenses directory
RUN cd /go/src/github.com/hawtio/hawtio-operator \
    && /gen-licenses.sh

# Productise template
RUN sed -i '/hawtconfig.json/,/apiVersion/s/"title": "Hawtio Console"/"title": "Red Hat Fuse Console"/' /go/src/github.com/hawtio/hawtio-operator/templates/deployment.yaml \
    && sed -i '/hawtconfig.json/,/apiVersion/s/"additionalInfo": ".*"/"additionalInfo": "The Red Hat Fuse Console eases the discovery and management of Fuse applications deployed on OpenShift."/' /go/src/github.com/hawtio/hawtio-operator/templates/deployment.yaml \
    && sed -i '/hawtconfig.json/,/apiVersion/s/"copyright": ""/"copyright": "",/' /go/src/github.com/hawtio/hawtio-operator/templates/deployment.yaml \
    && sed -i '/"copyright"/a\          "imgSrc": "..\/online\/img\/Logo-RedHat-A-Reverse-RGB.png"' /go/src/github.com/hawtio/hawtio-operator/templates/deployment.yaml \
    && sed -i '/hawtconfig.json/,/apiVersion/s/"appName": "Hawtio Console"/"appName": "Fuse Console"/' /go/src/github.com/hawtio/hawtio-operator/templates/deployment.yaml \
    && sed -i '/hawtconfig.json/,/apiVersion/s/"appLogoUrl": ".*"/"appLogoUrl": "..\/online\/img\/Logo-Red_Hat-Fuse-A-Reverse-RGB.png"/' /go/src/github.com/hawtio/hawtio-operator/templates/deployment.yaml \
    && sed -i '/hawtconfig.json/,/apiVersion/s/"disabledRoutes": \[\]/"disabledRoutes": \["\/camel\/source","\/diagnostics","\/jvm\/discover","\/jvm\/local"\]/' /go/src/github.com/hawtio/hawtio-operator/templates/deployment.yaml \
    && sed -i 's/\/usr\/share\/nginx\/html\/online\/hawtconfig.json/\/opt\/app-root\/src\/online\/hawtconfig.json/' /go/src/github.com/hawtio/hawtio-operator/templates/deployment.yaml \
    && sed -i 's/\/usr\/share\/nginx\/html\/integration\/hawtconfig.json/\/opt\/app-root\/src\/integration\/hawtconfig.json/' /go/src/github.com/hawtio/hawtio-operator/templates/deployment.yaml



# ----------------------------------------------------------------------------

FROM ubi7-minimal:7-released

LABEL name="fuse7/fuse-console-operator" \
      version="1.7" \
      maintainer="Otavio Piske <opiske@redhat.com>" \
      summary="A Kubernetes operator based on the Operator SDK that installs and maintains Hawtio Online on a cluster." \
      description="A Kubernetes operator based on the Operator SDK that installs and maintains Hawtio Online on a cluster." \
      com.redhat.component="fuse-console-operator-container" \
      io.k8s.display-name="Red Hat Fuse - Hawtio Operator" \
      io.openshift.tags="fuse,hawtio,operator" \
      com.redhat.delivery.appregistry="true"

USER 998

COPY --from=builder /hawtio-operator /usr/local/bin/hawtio-operator

COPY --from=builder /go/src/github.com/hawtio/hawtio-operator/templates /templates

COPY --from=builder /go/src/github.com/hawtio/hawtio-operator/licenses /root/licenses/fuse-hawtio-operator/licenses

ADD manifests /manifests
