# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
#   Red Hat, Inc. - initial API and implementation
#

# https://access.redhat.com/containers/?tab=tags#/registry.access.redhat.com/rhel8/go-toolset
FROM rhel8/go-toolset:1.13.15-1 as builder

ENV GOPATH=/go/

USER root

WORKDIR /web-terminal

# copy the rest of the sources code
COPY . .

# compile workspace controller binaries
RUN CGO_ENABLED=0 GOOS=linux go build \
  -mod=vendor \
  -o _output/bin/devworkspace-controller \
  -gcflags all=-trimpath=/ \
  -asmflags all=-trimpath=/ \
  cmd/manager/main.go

# Compile webhook binaries
RUN CGO_ENABLED=0 GOOS=linux go build \
  -mod=vendor \
  -o _output/bin/webhook-server \
  -gcflags all=-trimpath=/ \
  -asmflags all=-trimpath=/ \
  webhook/main.go

# https://access.redhat.com/containers/?tab=tags#/registry.access.redhat.com/ubi8-minimal
FROM ubi8-minimal:8.2-349
COPY --from=builder /web-terminal/_output/bin/devworkspace-controller /usr/local/bin/devworkspace-controller
COPY --from=builder /web-terminal/_output/bin/webhook-server /usr/local/bin/webhook-server
COPY --from=builder /web-terminal/internal-registry  internal-registry

ENV USER_UID=1001 \
    USER_NAME=web-terminal

COPY build/bin /usr/local/bin
RUN  /usr/local/bin/user_setup

USER ${USER_UID}

ENTRYPOINT ["/usr/local/bin/entrypoint"]
CMD /usr/local/bin/devworkspace-controller

# append Brew metadata here
ENV SUMMARY="Web Terminal - Operator container" \
    DESCRIPTION="Web Terminal - Operator container" \
    PRODNAME="web-terminal" \
    COMPNAME="operator"

LABEL summary="$SUMMARY" \
      description="$DESCRIPTION" \
      io.k8s.description="$DESCRIPTION" \
      io.k8s.display-name="$DESCRIPTION" \
      io.openshift.tags="$PRODNAME,$COMPNAME" \
      com.redhat.component="$PRODNAME-$COMPNAME-container" \
      name="$PRODNAME/$COMPNAME" \
      version="1.1" \
      license="EPLv2" \
      maintainer="Joshua Pinkney <jpinkney@redhat.com>" \
      io.openshift.expose-services="" \
      usage=""