From f62973e2cfa571eeae8cd80af6c6719eb34a512a Mon Sep 17 00:00:00 2001 From: Oliver Ford Date: Fri, 15 Jul 2022 22:12:29 +0100 Subject: [PATCH 1/2] Add a dockerfile, end-to-end sanity test Could potentially form the basis of (or simplify) more testing involving environment variables and filesystem setup too. Closes #241 --- .github/workflows/test.yml | 34 ++++++++++++++++++++++++++++++++++ Dockerfile | 27 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ede0c63d..77a594ac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,23 @@ jobs: run: './test/run.sh' shell: 'bash' + - uses: 'docker/setup-buildx-action@v2' + if: contains(matrix.os, 'ubuntu') + with: + install: true + - uses: 'docker/build-push-action@v3' + if: contains(matrix.os, 'ubuntu') + with: + context: . + load: true + tags: "tfenv-terraform:${GITHUB_SHA}" + - name: 'Check Dockerfile' + if: contains(matrix.os, 'ubuntu') + run: | + expect=1.2.3; + got="$(docker run -e "TFENV_TERRAFORM_VERSION=${expect}" "tfenv-terraform:${GITHUB_SHA}" version)"; + echo "${got}" | tee /dev/stderr | grep -e 'Terraform v1.2.3' + # When we push to master, test everything in order to guarantee releases test-master-pushes: if: github.event_name == 'push' && github.ref == 'refs/heads/master' @@ -51,3 +68,20 @@ jobs: - name: 'Run all tests' run: './test/run.sh' shell: 'bash' + + - uses: 'docker/setup-buildx-action@v2' + if: contains(matrix.os, 'ubuntu') + with: + install: true + - uses: 'docker/build-push-action@v3' + if: contains(matrix.os, 'ubuntu') + with: + context: . + load: true + tags: 'tfenv-terraform:latest' + - name: 'Check Dockerfile' + if: contains(matrix.os, 'ubuntu') + run: | + expect=1.2.3; + got="$(docker run -e "TFENV_TERRAFORM_VERSION=${expect}" tfenv-terraform:latest version)"; + echo "${got}" | tee /dev/stderr | grep -e 'Terraform v1.2.3' diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..016b42d8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +ARG BASH_VERSION=5 +FROM "docker.io/bash:${BASH_VERSION}" + +# Runtime dependencies +RUN apk add --no-cache --purge \ + curl \ + ; + +ARG TFENV_VERSION=3.0.0 +RUN wget -O /tmp/tfenv.tar.gz "https://github.com/tfutils/tfenv/archive/refs/tags/v${TFENV_VERSION}.tar.gz" \ + && tar -C /tmp -xf /tmp/tfenv.tar.gz \ + && mv "/tmp/tfenv-${TFENV_VERSION}/bin"/* /usr/local/bin/ \ + && mkdir -p /usr/local/lib/tfenv \ + && mv "/tmp/tfenv-${TFENV_VERSION}/lib" /usr/local/lib/tfenv/ \ + && mv "/tmp/tfenv-${TFENV_VERSION}/libexec" /usr/local/lib/tfenv/ \ + && mkdir -p /usr/local/share/licenses \ + && mv "/tmp/tfenv-${TFENV_VERSION}/LICENSE" /usr/local/share/licenses/tfenv \ + && rm -rf /tmp/tfenv* \ + ; +ENV TFENV_ROOT /usr/local/lib/tfenv + +ENV TFENV_CONFIG_DIR /var/tfenv +VOLUME /var/tfenv + +# Default to latest; user-specifiable +ENV TFENV_TERRAFORM_VERSION latest +ENTRYPOINT ["/usr/local/bin/terraform"] From 5e1a3f57f05698b4115b645d06e0f71c6d508dbb Mon Sep 17 00:00:00 2001 From: Oliver Ford Date: Fri, 15 Jul 2022 23:24:41 +0100 Subject: [PATCH 2/2] Fix invalid reference format in PR workflow --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77a594ac..8a711cd5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,12 +39,12 @@ jobs: with: context: . load: true - tags: "tfenv-terraform:${GITHUB_SHA}" + tags: "tfenv-terraform:${{ github.head_ref }}" - name: 'Check Dockerfile' if: contains(matrix.os, 'ubuntu') run: | expect=1.2.3; - got="$(docker run -e "TFENV_TERRAFORM_VERSION=${expect}" "tfenv-terraform:${GITHUB_SHA}" version)"; + got="$(docker run -e "TFENV_TERRAFORM_VERSION=${expect}" "tfenv-terraform:${{ github.head_ref }}" version)"; echo "${got}" | tee /dev/stderr | grep -e 'Terraform v1.2.3' # When we push to master, test everything in order to guarantee releases