From 6cc6c04975443f72737e06ed7d5703329bdea80b Mon Sep 17 00:00:00 2001 From: Mikkel Jakobsen Date: Sun, 23 May 2021 09:08:08 +0200 Subject: [PATCH 1/6] Adding helm to dplsh docker images for provisioning k8s resources --- tools/dplsh/Dockerfile | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/dplsh/Dockerfile b/tools/dplsh/Dockerfile index 6f04584..687daf0 100644 --- a/tools/dplsh/Dockerfile +++ b/tools/dplsh/Dockerfile @@ -3,14 +3,18 @@ ARG AZURE_CLI_TAG=latest ARG DPLSH_BUILD_VERSION=latest + # We use the official azure cli as a base-image. It is itself based on alpine # and is quite minimal. FROM mcr.microsoft.com/azure-cli:$AZURE_CLI_TAG ARG TASK_VERSION=v3.0.0 ARG TERRAFORM_RELEASE=0.15.1 +ARG HELM_VERSION=canary +ARG HELM_BASE_URL="https://storage.googleapis.com/kubernetes-helm" +ARG HELM_TAR_FILE="helm-${HELM_VERSION}-linux-amd64.tar.gz" LABEL org.opencontainers.image.source https://github.com/reload/dpl-platform-poc -SHELL ["/bin/bash", "-o", "pipefail", "-c"] +SHELL ["/bin/bash", "-ox", "pipefail", "-c"] WORKDIR /tmp # TODO - this will install the latest version - we should pin to the version we @@ -28,11 +32,22 @@ RUN apk add --no-cache \ RUN curl -sL https://taskfile.dev/install.sh | bash -s -- -b /usr/local/bin ${TASK_VERSION} WORKDIR /tmp + +# Add Terraform RUN curl -O https://releases.hashicorp.com/terraform/${TERRAFORM_RELEASE}/terraform_${TERRAFORM_RELEASE}_linux_amd64.zip \ && unzip terraform_${TERRAFORM_RELEASE}_linux_amd64.zip \ && mv terraform /usr/bin \ && rm terraform_${TERRAFORM_RELEASE}_linux_amd64.zip +# Add Helm +RUN apk add --update --no-cache curl ca-certificates wget && \ + curl -L ${HELM_BASE_URL}/${HELM_TAR_FILE} | tar xvz && \ + mv linux-amd64/helm /usr/bin/helm && \ + chmod +x /usr/bin/helm && \ + rm -rf linux-amd64 && \ + apk del curl && \ + rm -f /var/cache/apk/* + # Create a dplsh user and switch to it to avoid running the shell as root RUN adduser -D --shell /bin/bash dplsh From cc1d78d92745dcf98b9295b5dbff92f6a3b3ff14 Mon Sep 17 00:00:00 2001 From: "Mads H. Danquah" Date: Tue, 25 May 2021 08:30:01 +0200 Subject: [PATCH 2/6] Pull in Helm via an intermediate build step --- tools/dplsh/Dockerfile | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tools/dplsh/Dockerfile b/tools/dplsh/Dockerfile index 687daf0..1d7ed9b 100644 --- a/tools/dplsh/Dockerfile +++ b/tools/dplsh/Dockerfile @@ -3,15 +3,15 @@ ARG AZURE_CLI_TAG=latest ARG DPLSH_BUILD_VERSION=latest +# Use an intermediate image as a way to have dependabot track our dependency +FROM alpine/helm:3.5.4 as helm + # We use the official azure cli as a base-image. It is itself based on alpine # and is quite minimal. FROM mcr.microsoft.com/azure-cli:$AZURE_CLI_TAG ARG TASK_VERSION=v3.0.0 ARG TERRAFORM_RELEASE=0.15.1 -ARG HELM_VERSION=canary -ARG HELM_BASE_URL="https://storage.googleapis.com/kubernetes-helm" -ARG HELM_TAR_FILE="helm-${HELM_VERSION}-linux-amd64.tar.gz" LABEL org.opencontainers.image.source https://github.com/reload/dpl-platform-poc SHELL ["/bin/bash", "-ox", "pipefail", "-c"] @@ -40,13 +40,7 @@ RUN curl -O https://releases.hashicorp.com/terraform/${TERRAFORM_RELEASE}/terraf && rm terraform_${TERRAFORM_RELEASE}_linux_amd64.zip # Add Helm -RUN apk add --update --no-cache curl ca-certificates wget && \ - curl -L ${HELM_BASE_URL}/${HELM_TAR_FILE} | tar xvz && \ - mv linux-amd64/helm /usr/bin/helm && \ - chmod +x /usr/bin/helm && \ - rm -rf linux-amd64 && \ - apk del curl && \ - rm -f /var/cache/apk/* +COPY --from=helm /usr/bin/helm /usr/local/bin/ # Create a dplsh user and switch to it to avoid running the shell as root RUN adduser -D --shell /bin/bash dplsh From c4efe85d3e183da1af2701d4ffc37dbd8f0a943f Mon Sep 17 00:00:00 2001 From: "Mads H. Danquah" Date: Tue, 25 May 2021 08:54:51 +0200 Subject: [PATCH 3/6] Pull in Terraform via a docker intermediate layer --- tools/dplsh/Dockerfile | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/dplsh/Dockerfile b/tools/dplsh/Dockerfile index 1d7ed9b..b4909ae 100644 --- a/tools/dplsh/Dockerfile +++ b/tools/dplsh/Dockerfile @@ -3,15 +3,14 @@ ARG AZURE_CLI_TAG=latest ARG DPLSH_BUILD_VERSION=latest -# Use an intermediate image as a way to have dependabot track our dependency +# Use an intermediate images as a way to have dependabot track our dependency FROM alpine/helm:3.5.4 as helm - +FROM hashicorp/terraform:0.15.1 as terraform # We use the official azure cli as a base-image. It is itself based on alpine # and is quite minimal. FROM mcr.microsoft.com/azure-cli:$AZURE_CLI_TAG ARG TASK_VERSION=v3.0.0 -ARG TERRAFORM_RELEASE=0.15.1 LABEL org.opencontainers.image.source https://github.com/reload/dpl-platform-poc SHELL ["/bin/bash", "-ox", "pipefail", "-c"] @@ -34,13 +33,10 @@ RUN curl -sL https://taskfile.dev/install.sh | bash -s -- -b /usr/local/bin ${TA WORKDIR /tmp # Add Terraform -RUN curl -O https://releases.hashicorp.com/terraform/${TERRAFORM_RELEASE}/terraform_${TERRAFORM_RELEASE}_linux_amd64.zip \ - && unzip terraform_${TERRAFORM_RELEASE}_linux_amd64.zip \ - && mv terraform /usr/bin \ - && rm terraform_${TERRAFORM_RELEASE}_linux_amd64.zip +COPY --from=terraform /bin/terraform /bin/ # Add Helm -COPY --from=helm /usr/bin/helm /usr/local/bin/ +COPY --from=helm /usr/bin/helm /usr/bin/ # Create a dplsh user and switch to it to avoid running the shell as root RUN adduser -D --shell /bin/bash dplsh From 2383139ca05f87bf9521e7cb278cd0f5adac9631 Mon Sep 17 00:00:00 2001 From: "Mads H. Danquah" Date: Tue, 25 May 2021 09:00:47 +0200 Subject: [PATCH 4/6] Make the runtime image configurable --- tools/dplsh/dplsh.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/dplsh/dplsh.sh b/tools/dplsh/dplsh.sh index 9c3f7ff..b57f0da 100755 --- a/tools/dplsh/dplsh.sh +++ b/tools/dplsh/dplsh.sh @@ -19,7 +19,7 @@ find-up () { } PROFILE_FILE= -DOCKER_IMAGE="ghcr.io/reload/dpl-platform-poc/dplsh:latest" +DOCKER_IMAGE="${DPLSH_IMAGE:-ghcr.io/reload/dpl-platform-poc/dplsh:latest}" CHDIR= SHELL_ROOT="${PWD}" From 2aaf802beed23776a5b421e2b904aec07cb49246 Mon Sep 17 00:00:00 2001 From: "Mads H. Danquah" Date: Tue, 25 May 2021 09:03:35 +0200 Subject: [PATCH 5/6] Add simple testing of dplsh --- .github/workflows/dplsh-build-release.yaml | 13 ++++++++++++- tools/dplsh/Taskfile.yml | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dplsh-build-release.yaml b/.github/workflows/dplsh-build-release.yaml index 7b964b7..d88b4e6 100644 --- a/.github/workflows/dplsh-build-release.yaml +++ b/.github/workflows/dplsh-build-release.yaml @@ -28,10 +28,21 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2.3.4 + - name: Install Task + uses: Arduino/actions/setup-taskfile@master # Generate a sane tag based on current git ref (branch, tag, etc). - uses: rlespinasse/github-slug-action@v3.x - name: Build ${{env.image}} container image - run: docker build -t working-image:0.0.0 . + env: + IMAGE_URL: working-image + IMAGE_TAG: 0.0.0 + run: task build + working-directory: tools/dplsh + - name: Test ${{env.image}} container image + env: + IMAGE_URL: working-image + IMAGE_TAG: 0.0.0 + run: task test working-directory: tools/dplsh # Publish to container registry if this was a push event (not a PR). - name: Publish image to registry diff --git a/tools/dplsh/Taskfile.yml b/tools/dplsh/Taskfile.yml index b332b99..af52902 100644 --- a/tools/dplsh/Taskfile.yml +++ b/tools/dplsh/Taskfile.yml @@ -17,3 +17,10 @@ tasks: - docker tag {{.image}} {{.latest}} - docker push {{.image}} - docker push {{.latest}} + + test: + env: + DPLSH_IMAGE: "{{.image}}" + cmds: + - ./dplsh.sh terraform -version + - ./dplsh.sh helm version From 881daf3ffa90e2930a1918dc43f638a06bd21f2c Mon Sep 17 00:00:00 2001 From: "Mads H. Danquah" Date: Tue, 25 May 2021 09:30:39 +0200 Subject: [PATCH 6/6] Make it possible to run dplsh non-interactive --- tools/dplsh/Taskfile.yml | 1 + tools/dplsh/dplsh.sh | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/dplsh/Taskfile.yml b/tools/dplsh/Taskfile.yml index af52902..d028863 100644 --- a/tools/dplsh/Taskfile.yml +++ b/tools/dplsh/Taskfile.yml @@ -21,6 +21,7 @@ tasks: test: env: DPLSH_IMAGE: "{{.image}}" + DPLSH_NON_INTERACTIVE: "true" cmds: - ./dplsh.sh terraform -version - ./dplsh.sh helm version diff --git a/tools/dplsh/dplsh.sh b/tools/dplsh/dplsh.sh index b57f0da..aca5959 100755 --- a/tools/dplsh/dplsh.sh +++ b/tools/dplsh/dplsh.sh @@ -204,10 +204,15 @@ for key in "${!docker_creds[@]}"; do ADDITIONAL_ARGS+=(-e "${key}=${docker_creds[$key]}") done +# We run in interactive mode unless if we're in DPLSH_NON_INTERACTIVE. +if [[ -z "${DPLSH_NON_INTERACTIVE:-}" ]]; then + ADDITIONAL_ARGS+=(-i) +fi + docker run --hostname=dplsh \ --rm \ "${ADDITIONAL_ARGS[@]}" \ - -ti \ + -t \ -v "${HOME}/.azure:/home/dplsh/.azure-host" \ -v "${SHELL_ROOT}:/home/dplsh/host_mount" \ -w "/home/dplsh/host_mount/${CHDIR}" \