FROM node:18-bullseye-slim

ARG YQ_VERSION='4.31.2'

RUN apt-get update
RUN apt-get install -y \
  python3 \
  bash \
  git \
  curl \
  gettext \
  build-essential \
  git-lfs \
  chromium \
  dnsutils \
  jq \
  unzip \
  rsync

# Install yq
RUN curl -LJO https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64 \
  && mv yq_linux_amd64 /usr/bin/yq \
  && chmod +x /usr/bin/yq

# Install bun
RUN curl -fsSL https://bun.sh/install | bash
ENV BUN_INSTALL="$HOME/.bun"
ENV PATH="$BUN_INSTALL/bin:$PATH"

# Install GCP SDK
RUN curl -sSL https://sdk.cloud.google.com | bash
ENV PATH $PATH:/root/google-cloud-sdk/bin

# This line is to tell chrome-launcher or puppeteer where
# chromium was downloaded and installed to.
ENV CHROME_BIN /usr/bin/chromium

# Tell Puppeteer to skip installing Chrome.
# We'll be using the installed package instead.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV NODE_CHROMIUM_SKIP_INSTALL true

# Install Kubectl
RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" \
  && chmod +x kubectl \
  && mv kubectl /usr/local/bin/kubectl \
  && kubectl version --client

RUN echo '#!/usr/bin/env bash\nnode /app/src/index.js "$@"' > /usr/bin/opsctl && \
  chmod +x /usr/bin/opsctl

RUN echo '#!/usr/bin/env bash\nnode /app/src/index.js "$@"' > /usr/bin/pipe && \
  chmod +x /usr/bin/pipe

ENTRYPOINT [ "opsctl" ]
VOLUME [ "/src" ]
WORKDIR /app
RUN npm install -g yamljs
COPY package.json yarn.lock /app/
RUN yarn

COPY ./src /app/src

