FROM ubuntu:latest

RUN groupadd -r layerops && useradd --no-log-init -r -g layerops layerops

RUN apt-get update && apt-get install -y curl software-properties-common unzip
RUN curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add -
RUN apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" 
RUN add-apt-repository --yes ppa:ansible/ansible 
RUN apt-get update
RUN apt-get install -y \
      ansible
RUN apt-get install -y cloud-image-utils \
      jq \
      packer \
      python3 \
      python3-pip \
      qemu-kvm
RUN curl https://rclone.org/install.sh | bash \
  && curl -sL https://aka.ms/InstallAzureCLIDeb | bash \
  && pip install importlib_metadata && pip install python-openstackclient \
  && apt-get remove -y unzip software-properties-common && apt-get -y autoremove \
  && rm -fR /tmp/* /var/lib/apt/lists/*

RUN pip install osc-sdk

RUN mkdir /.ssh \
      && echo 'HostKeyAlgorithms ssh-rsa' >> /.ssh/config \
      && echo 'PubkeyAcceptedKeyTypes ssh-rsa' >> /.ssh/config

WORKDIR /home/layerops
RUN chown layerops:layerops /home/layerops

USER layerops

RUN packer plugins install github.com/scaleway/scaleway
RUN packer plugins install github.com/outscale/outscale

RUN mkdir -p ./client ./orchestrator ./ansible ./.osc
COPY --chown=layerops:layerops client ./client
COPY --chown=layerops:layerops orchestrator ./orchestrator
COPY --chown=layerops:layerops ansible ./ansible

RUN mkdir ~/.ssh \
      && echo 'HostKeyAlgorithms ssh-rsa' >> ~/.ssh/config \
      && echo 'PubkeyAcceptedKeyTypes ssh-rsa' >> ~/.ssh/config
