|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | +FROM ubuntu:21.10 as base |
| 3 | +RUN apt update -y |
| 4 | + |
| 5 | +FROM base as dowloader |
| 6 | + |
| 7 | +RUN apt install curl unzip tar gzip git ca-certificates openssh-client -y |
| 8 | + |
| 9 | +# Terraform download |
| 10 | +ARG TERRAFORM_VER |
| 11 | +RUN cd /tmp && \ |
| 12 | + curl https://releases.hashicorp.com/terraform/${TERRAFORM_VER}/terraform_${TERRAFORM_VER}_linux_amd64.zip --output terraform.zip && \ |
| 13 | + unzip terraform.zip && \ |
| 14 | + mv terraform /usr/bin/ && \ |
| 15 | + rm -rf /tmp/* && \ |
| 16 | + terraform --version |
| 17 | + |
| 18 | +ARG PACKER_VER |
| 19 | +RUN cd /tmp && \ |
| 20 | + curl https://releases.hashicorp.com/packer/${PACKER_VER}/packer_${PACKER_VER}_linux_amd64.zip --output packer.zip && \ |
| 21 | + unzip packer.zip && \ |
| 22 | + mv packer /usr/bin/ && \ |
| 23 | + rm -rf /tmp/* && \ |
| 24 | + packer version |
| 25 | + |
| 26 | +ARG DOCTL_VER |
| 27 | +RUN cd /tmp && \ |
| 28 | + curl -L https://github.com/digitalocean/doctl/releases/download/v${DOCTL_VER}/doctl-${DOCTL_VER}-linux-amd64.tar.gz --output doctl.tar.gz && \ |
| 29 | + ls -la /tmp && \ |
| 30 | + tar xf doctl.tar.gz -C /tmp && \ |
| 31 | + mv /tmp/doctl /usr/bin/doctl && \ |
| 32 | + rm -rf /tmp/* && \ |
| 33 | + doctl version |
| 34 | + |
| 35 | +# Install task (https://taskfile.dev) |
| 36 | +RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/bin \ |
| 37 | + && task --version |
| 38 | + |
| 39 | +# Generate private key |
| 40 | +RUN ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa |
| 41 | + |
| 42 | +# Target |
| 43 | +FROM base |
| 44 | + |
| 45 | +# configure nodejs repository |
| 46 | +RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - |
| 47 | +RUN apt install ca-certificates ssh nodejs ansible -y |
| 48 | + |
| 49 | +# Workdir |
| 50 | +RUN mkdir -p /project |
| 51 | +WORKDIR /project |
| 52 | + |
| 53 | +# Terraform cache |
| 54 | +ENV TF_PLUGIN_CACHE_DIR=/project/.tmp/.terraform.d/plugin-cache |
| 55 | +ENV PACKER_CONFIG_DIR=/project/.tmp/ |
| 56 | +# ENV PACKER_CACHE_DIR=/project/.tmp/.packer.d |
| 57 | + |
| 58 | +# Bash improviments |
| 59 | +RUN echo "alias ll='ls -l'" >> /root/.bashrc && \ |
| 60 | + echo "complete -C /usr/bin/terraform terraform" >> /root/.bashrc && \ |
| 61 | + echo 'PS1="\n\[\e[0;31m\]┌─[\[\e[0m\]\[\e[1;33m\]\u\[\e[0m\] ܁\[\e[1;36m\]\[\e[0m\]\[\e[1;34m\]\w\[\e[0m\]\[\e[0;31m\]]\n\[\e[0;31m\]└─\e[0;31m\]$ \[\e[0m\]"' >> /root/.bashrc |
| 62 | + |
| 63 | +# Copy from downloader stage |
| 64 | +COPY --from=dowloader --chown=root:root /root/.ssh/ /root/.ssh/ |
| 65 | +COPY --from=dowloader --chown=root:root /usr/bin/terraform /usr/bin/terraform |
| 66 | +COPY --from=dowloader --chown=root:root /usr/bin/packer /usr/bin/packer |
| 67 | +COPY --from=dowloader --chown=root:root /usr/bin/doctl /usr/bin/doctl |
| 68 | +COPY --from=dowloader --chown=root:root /usr/bin/task /usr/bin/task |
| 69 | + |
| 70 | +# prepare ssh |
| 71 | +RUN chmod 600 /root/.ssh/id_rsa && \ |
| 72 | + ssh-keyscan -H github.com >> /root/.ssh/known_hosts && \ |
| 73 | + ssh-keyscan -H bitbucket.com >> /root/.ssh/known_hosts && \ |
| 74 | + echo "StrictHostKeyChecking no" >> /root/.ssh/ssh_config |
| 75 | + |
| 76 | +COPY docker-entrypoint.sh /docker-entrypoint.sh |
| 77 | + |
| 78 | +RUN chmod 600 /docker-entrypoint.sh && \ |
| 79 | + chmod +x /docker-entrypoint.sh |
| 80 | + |
| 81 | +ENTRYPOINT ["/docker-entrypoint.sh"] |
| 82 | +CMD ["bash"] |
0 commit comments