# syntax = docker/dockerfile:experimental
# Interim container so we can copy pulumi binaries
# Must be defined first
ARG PULUMI_VERSION=latest
ARG PULUMI_IMAGE=pulumi/pulumi-base
FROM ${PULUMI_IMAGE}:${PULUMI_VERSION} as pulumi

# Build container
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest AS builder

# Set go versions
ARG RUNTIME_VERSION=1.16.2

WORKDIR /golang
RUN microdnf install -y \
      curl \
      make \
      gcc \
      git \
      tar \
      gcc-c++
RUN curl -fsSLo /tmp/go.tgz https://golang.org/dl/go${RUNTIME_VERSION}.linux-amd64.tar.gz; \
    mkdir -p bin; \
    tar -C /golang -xzf /tmp/go.tgz; \
    rm /tmp/go.tgz; \
    export PATH="/golang/go/bin:${PATH}"; \
    go version

# The runtime container
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
WORKDIR /pulumi/projects

# Install needed tools, like git
RUN microdnf install -y \
    git \
    tar \
    ca-certificates; \
    mkdir -p /go

# Uses the workdir
COPY --from=builder /golang/go /usr/local
# Uses the workdir, copies from pulumi interim container
COPY --from=pulumi /pulumi/bin/pulumi /pulumi/bin/pulumi
COPY --from=pulumi /pulumi/bin/pulumi-language-go /pulumi/bin/pulumi-language-go
COPY --from=pulumi /pulumi/bin/pulumi-analyzer-policy /pulumi/bin/pulumi-analyzer-policy
ENV GOPATH=/go
ENV PATH "/pulumi/bin:${PATH}"

CMD ["pulumi"]
