diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ede0c63d..8a711cd5 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.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.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 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"]