From 74635778331bc91fafe06b233470ad228ba14a55 Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Wed, 15 Jan 2025 21:09:24 +0100 Subject: [PATCH] Add custom user, cleanup apt, set symlinks --- azure/Dockerfile | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/azure/Dockerfile b/azure/Dockerfile index 15b423f..4e9cbc3 100644 --- a/azure/Dockerfile +++ b/azure/Dockerfile @@ -12,8 +12,8 @@ ARG ANSIBLE_VERSION \ TERRAFORM_VERSION \ TFLINT_VERSION -COPY ./ansible_collections.yml /ansible_collections.yml - +RUN groupadd -g 1000 admin && useradd -u 1000 -g 1000 -s /bin/bash -d /home/admin admin +COPY ./ansible_collections.yml /home/admin/ansible_collections.yml # Install dependencies. RUN apt-get update \ @@ -57,8 +57,9 @@ RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 # Create venv and install tools RUN python3.12 -m venv /opt/ansible_virtualenv \ && . /opt/ansible_virtualenv/bin/activate \ - && pip3 install --no-cache-dir --no-compile ansible-core==${ANSIBLE_VERSION} ansible-lint==${ANSIBLE_LINT_VERSION} \ - && ansible-galaxy collection install -r /ansible_collections.yml + && pip3 install --no-cache-dir --no-compile ansible-core==${ANSIBLE_VERSION} ansible-lint==${ANSIBLE_LINT_VERSION} yamllint \ + && ln -s /opt/ansible_virtualenv/bin/ansible* /usr/bin/ \ + && ln -s /opt/ansible_virtualenv/bin/yamllint /usr/bin/ # Install Packer + Plugins RUN curl -sLSfo packer.zip https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_$(dpkg --print-architecture).zip && unzip -o packer.zip && mv packer /usr/bin -f && rm packer.zip @@ -71,7 +72,24 @@ RUN curl -sLSfo terraform.zip https://releases.hashicorp.com/terraform/${TERRA # Install TFlint RUN curl -sLSfo tflint.zip https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION}/tflint_linux_$(dpkg --print-architecture).zip && unzip -o tflint.zip && mv tflint /usr/bin -f && rm tflint.zip + +# cleanup apt mess +RUN apt-get purge -y man-db && apt-get clean \ + && rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* \ + /usr/share/doc/* \ + /usr/share/man/* \ + /usr/share/locale/* + # fatal: detected dubious ownership in repository at '/git' RUN git config --global --add safe.directory /git +RUN chown -R 1000:1000 /home/admin +USER admin +WORKDIR /home/admin + +RUN ansible-galaxy collection install -r ~/ansible_collections.yml + CMD ["/bin/bash"]