# Installs workflow-generator, kubectl and argo. Runs workflow-generator on the machine-config
# stored in the environment variable MACHINE_CONFIG, or if that is empty, the file
# /code/config.yml, which is then the callers responsibility to mount in.
ARG BASE_IMAGE=gordo/base:latest
FROM $BASE_IMAGE

ARG HTTPS_PROXY
ARG KUBECTL_VERSION="v1.16.9"
ARG ARGO_VERSION="v2.8.2"

RUN apt-get update && apt-get install -y \
    curl \
    jq \
 && rm -rf /var/lib/apt/lists/*

#donwload & install kubectl
RUN curl -sSL -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl &&\
  chmod +x /usr/local/bin/kubectl

#download & install argo
RUN curl -sSL -o /usr/local/bin/argo https://github.com/argoproj/argo/releases/download/$ARGO_VERSION/argo-linux-amd64 &&\
  chmod +x /usr/local/bin/argo

COPY ./run_workflow_and_argo.sh ${HOME}/run_workflow_and_argo.sh

# Baking in example configs for running tests, as docker.client.containers.run
# bind doesn't seem to work correctly for non-root users
# volumes={repo_dir: {"bind": "/home/gordo", "mode": "ro"}},
COPY ./examples ${HOME}/examples
COPY ./resources ${HOME}/resources

# Switch user
USER gordo

CMD ["bash", "./run_workflow_and_argo.sh"]
