From a82eb4e6d996745e3427072a28cdc7250defae81 Mon Sep 17 00:00:00 2001 From: Aman Agrawal <9412470@gmail.com> Date: Wed, 13 Mar 2024 21:34:54 +0530 Subject: [PATCH] OP-21899 Packer fixed - Replaced init with plugins install (#27) --- docker/ubi8/Dockerfile | 12 +++++++++++- docker/ubi8/Dockerfile-dev | 16 +++++++++++----- docker/ubi8/Dockerfile-fips | 17 +++++++++++------ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/docker/ubi8/Dockerfile b/docker/ubi8/Dockerfile index a646e7f29..f19928736 100644 --- a/docker/ubi8/Dockerfile +++ b/docker/ubi8/Dockerfile @@ -13,7 +13,6 @@ WORKDIR /packer RUN yum install -y java-17-openjdk-devel wget unzip curl tar git openssl curl net-tools nettle && \ wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip && \ unzip packer_${PACKER_VERSION}_linux_amd64.zip && \ - packer init . && \ rm packer_${PACKER_VERSION}_linux_amd64.zip RUN yum -y update @@ -39,4 +38,15 @@ ENV PATH "kustomize:$PATH" RUN useradd spinnaker RUN mkdir -p /opt/rosco/plugins USER spinnaker + +# Install packer plugins (must be run as spinnaker user). To provide a github token (optional), run docker build with something like "--secret id=github_token,env=PACKER_GITHUB_API_TOKEN" +ARG PACKER_PLUGINS="amazon azure googlecompute" +RUN for plugin in $PACKER_PLUGINS ; do \ + if [ -f /run/secrets/github_token ]; then \ + PACKER_GITHUB_API_TOKEN=$(cat /run/secrets/github_token) packer plugins install "github.com/hashicorp/$plugin"; \ + else \ + packer plugins install "github.com/hashicorp/$plugin"; \ + fi; \ +done + CMD ["/opt/rosco/bin/rosco"] diff --git a/docker/ubi8/Dockerfile-dev b/docker/ubi8/Dockerfile-dev index f1dcafb1c..d37c31816 100644 --- a/docker/ubi8/Dockerfile-dev +++ b/docker/ubi8/Dockerfile-dev @@ -43,15 +43,10 @@ ENV PACKER_VERSION=1.10.1 WORKDIR /packer - - RUN yum install -y java-17-openjdk-devel wget unzip curl tar git openssl net-tools nettle && \ wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip && \ unzip packer_${PACKER_VERSION}_linux_amd64.zip && \ - packer init . && \ rm packer_${PACKER_VERSION}_linux_amd64.zip - - ENV PATH "/packer:$PATH" @@ -94,4 +89,15 @@ RUN mv Armory.armory-observability-plugin-${CUSTOMPLUGIN_RELEASEVERSION}-SNAPSHO RUN chmod -R 777 /opt/rosco/plugins/ RUN chown -R spinnaker:spinnaker /opt/ USER spinnaker + +# Install packer plugins (must be run as spinnaker user). To provide a github token (optional), run docker build with something like "--secret id=github_token,env=PACKER_GITHUB_API_TOKEN" +ARG PACKER_PLUGINS="amazon azure googlecompute" +RUN for plugin in $PACKER_PLUGINS ; do \ + if [ -f /run/secrets/github_token ]; then \ + PACKER_GITHUB_API_TOKEN=$(cat /run/secrets/github_token) packer plugins install "github.com/hashicorp/$plugin"; \ + else \ + packer plugins install "github.com/hashicorp/$plugin"; \ + fi; \ +done + CMD ["/opt/rosco/bin/rosco"] diff --git a/docker/ubi8/Dockerfile-fips b/docker/ubi8/Dockerfile-fips index 5421c952a..7d9d46706 100644 --- a/docker/ubi8/Dockerfile-fips +++ b/docker/ubi8/Dockerfile-fips @@ -38,18 +38,12 @@ COPY halconfig/packer /opt/rosco/config/packer ENV KUSTOMIZE_VERSION=5.0.3 ENV PACKER_VERSION=1.10.1 - WORKDIR /packer - - RUN yum install -y java-17-openjdk-devel wget unzip curl tar git openssl net-tools nettle && \ wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip && \ unzip packer_${PACKER_VERSION}_linux_amd64.zip && \ - packer init . && \ rm packer_${PACKER_VERSION}_linux_amd64.zip - - ENV PATH "/packer:$PATH" @@ -92,4 +86,15 @@ RUN chmod -R 777 /opt/rosco/plugins/ RUN chown -R spinnaker:spinnaker /opt/ RUN yum -y remove tar vim vi USER spinnaker + +# Install packer plugins (must be run as spinnaker user). To provide a github token (optional), run docker build with something like "--secret id=github_token,env=PACKER_GITHUB_API_TOKEN" +ARG PACKER_PLUGINS="amazon azure googlecompute" +RUN for plugin in $PACKER_PLUGINS ; do \ + if [ -f /run/secrets/github_token ]; then \ + PACKER_GITHUB_API_TOKEN=$(cat /run/secrets/github_token) packer plugins install "github.com/hashicorp/$plugin"; \ + else \ + packer plugins install "github.com/hashicorp/$plugin"; \ + fi; \ +done + CMD ["/opt/rosco/bin/rosco"]