Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically build docker terraform image #10

Merged
merged 1 commit into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Docker
on:
push:
branches:
- master
tags:
- "v*"
workflow_dispatch: {}

jobs:
docker-build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@master
- name: Get the version
id: get_version
run: |
tag=${GITHUB_REF#refs/tags/}
VERSION=${tag#"v"}
if [[ ${GITHUB_REF} == "refs/heads/master" ]]; then
VERSION=latest
fi
echo ::set-output name=VERSION::${VERSION}
- name: Get git revision
id: vars
shell: bash
run: |
echo "::set-output name=git_revision::$(git rev-parse --short HEAD)"

- name: Login docker.io
uses: docker/login-action@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
with:
driver-opts: image=moby/buildkit:master

- uses: docker/build-push-action@v2
name: Build & Pushing terraform controller for Dockerhub
with:
context: .
file: Dockerfile
labels: |-
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
build-args: |
GITVERSION=git-${{ steps.vars.outputs.git_revision }}
VERSION=${{ steps.get_version.outputs.VERSION }}
GOPROXY=https://proxy.golang.org
tags: |-
docker.io/oamdev/docker-terraform:${{ steps.get_version.outputs.VERSION }}
24 changes: 18 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
FROM oamdev/docker-terraform-base:1.0.9
FROM alpine:3.13

RUN \
apk update && \
apk add bash py-pip && \
apk add --virtual=build gcc libffi-dev musl-dev openssl-dev python3-dev make && \
apk add curl jq python3 ca-certificates git openssl unzip wget && \
pip --no-cache-dir install -U pip && \
pip install azure-cli && \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why used the azure-cli here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the provide is azurerm, it's needed.

apk del --purge build

VOLUME ["/data"]

WORKDIR /data

ENTRYPOINT ["tail", "-f", "/dev/null"]

ENV TERRAFORM_VERSION=1.0.2
COPY terraform_${TERRAFORM_VERSION}_linux_amd64.zip /tmp
RUN cd /tmp && \
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/bin
COPY retrieve_tf_provider.sh /tmp

ARG VCS_REF
ENV RETRIEVE_TF_PROVIDER=/tmp/retrieve_tf_provider.sh

LABEL org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/broadinstitute/docker-terraform"
RUN $RETRIEVE_TF_PROVIDER random 3.1.0
RUN $RETRIEVE_TF_PROVIDER alicloud 1.140.0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe always use the newest version is better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alicloud or random?


RUN cp -r .terraform.d /root/.terraform.d

ENTRYPOINT ["tail", "-f", "/dev/null"]
20 changes: 20 additions & 0 deletions retrieve_tf_provider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set -x
# accept two arguments from command line
# 1. the name of the Terraform provider
# 2. the version of the Terraform provider

PROVIDER_NAME=$1
PROVIDER_VERSION=$2

echo "Downloading: $PROVIDER_NAME, $PROVIDER_VERSION"

TERRAFORM_DIR=.terraform.d/plugins/registry.terraform.io/hashicorp
HASHICORP_RELEASE_DOMAIN=https://releases.hashicorp.com

PROVIDER_RUL=$HASHICORP_RELEASE_DOMAIN/terraform-provider-"$PROVIDER_NAME"/"$PROVIDER_VERSION"/terraform-provider-"$PROVIDER_NAME"_"$PROVIDER_VERSION"_linux_amd64.zip
wget "$PROVIDER_RUL" -O provider.zip &&
unzip provider.zip &&
chmod +x terraform-provider-"$PROVIDER_NAME"_* &&
mkdir -p $TERRAFORM_DIR/"$PROVIDER_NAME"/"$PROVIDER_VERSION"/linux_amd64 &&
mv terraform-provider-"$PROVIDER_NAME"_* $TERRAFORM_DIR/"$PROVIDER_NAME"/"$PROVIDER_VERSION"/linux_amd64 &&
rm -f provider.zip