Skip to content

Commit f099ac0

Browse files
authored
Add GitHub action for image CI and multi-tag strategy (#63)
* 🐳 improved build, update dependencies, lint * 👷 add build, push-latest and release github action workflow * 🔧 add an editor config * 🔧 change dev-build script image tag from latest to dev * 📝 update readme with new image tag strategy and small updates * 🐳 renamed build stages
1 parent 1d877bc commit f099ac0

File tree

7 files changed

+228
-43
lines changed

7 files changed

+228
-43
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
indent_size = 2
10+
indent_style = spaces
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true

.github/workflows/build.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: build
2+
3+
# trigger on any push
4+
# but not on master or tag
5+
on:
6+
push:
7+
tags-ignore:
8+
- "**"
9+
branches:
10+
- "**"
11+
- "!master"
12+
13+
env:
14+
ORGANIZATION: "zenika"
15+
IMAGE_NAME: "terraform-azure-cli"
16+
17+
jobs:
18+
lint:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Check out the repo
23+
uses: actions/checkout@v2
24+
25+
- name: Lint Dockerfile
26+
uses: brpaz/hadolint-action@master
27+
with:
28+
dockerfile: "Dockerfile"
29+
30+
build:
31+
runs-on: ubuntu-latest
32+
needs: lint
33+
34+
steps:
35+
- name: Check out the repo
36+
uses: actions/checkout@v2
37+
38+
- name: Save branch name as env var
39+
run: echo "::set-env name=BRANCH::${GITHUB_REF##*/}"
40+
41+
- name: Build image
42+
run: docker image build . --file Dockerfile --tag $ORGANIZATION/$IMAGE_NAME:$BRANCH
43+
44+
- name: Save image
45+
run: docker image save -o $IMAGE_NAME-$BRANCH.tar $ORGANIZATION/$IMAGE_NAME:$BRANCH
46+
47+
- name: Upload image artifact
48+
uses: actions/upload-artifact@v2
49+
with:
50+
name: ${{ env.IMAGE_NAME }}-${{ env.BRANCH }}
51+
path: ${{ env.IMAGE_NAME }}-${{ env.BRANCH }}.tar

.github/workflows/push-latest.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: push-latest
2+
3+
# trigger on master
4+
on:
5+
push:
6+
branches:
7+
- "master"
8+
9+
env:
10+
ORGANIZATION: "zenika"
11+
IMAGE_NAME: "terraform-azure-cli"
12+
IMAGE_TAG: "latest"
13+
14+
jobs:
15+
lint:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Check out the repo
20+
uses: actions/checkout@v2
21+
22+
- name: Lint Dockerfile
23+
uses: brpaz/hadolint-action@master
24+
with:
25+
dockerfile: "Dockerfile"
26+
27+
build_push_latest:
28+
runs-on: ubuntu-latest
29+
needs: lint
30+
31+
steps:
32+
- name: Check out the repo
33+
uses: actions/checkout@v2
34+
35+
- name: Build image
36+
run: docker image build . --file Dockerfile --tag $ORGANIZATION/$IMAGE_NAME:$IMAGE_TAG
37+
38+
- name: Login to Docker Hub registry
39+
run: echo '${{ secrets.DOCKERHUB_PASS }}' | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
40+
41+
- name: Push image to registry
42+
run: docker push $ORGANIZATION/$IMAGE_NAME:$IMAGE_TAG
43+
44+
- name: Save image
45+
run: docker image save -o $IMAGE_NAME-$IMAGE_TAG.tar $ORGANIZATION/$IMAGE_NAME:$IMAGE_TAG
46+
47+
- name: Upload image artifact
48+
uses: actions/upload-artifact@v2
49+
with:
50+
name: ${{ env.IMAGE_NAME }}-${{ env.IMAGE_TAG }}
51+
path: ${{ env.IMAGE_NAME }}-${{ env.IMAGE_TAG }}.tar

.github/workflows/release.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: release
2+
3+
# trigger on tag
4+
on:
5+
push:
6+
tags:
7+
- "*.*"
8+
9+
env:
10+
ORGANIZATION: "zenika"
11+
IMAGE_NAME: "terraform-azure-cli"
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Check out the repo
19+
uses: actions/checkout@v2
20+
21+
- name: Lint Dockerfile
22+
uses: brpaz/hadolint-action@master
23+
with:
24+
dockerfile: "Dockerfile"
25+
26+
build_push_release:
27+
runs-on: ubuntu-latest
28+
needs: lint
29+
30+
strategy:
31+
matrix:
32+
versions:
33+
- { tf_version: "0.12.24", awscli_version: "2.5.1" }
34+
35+
env:
36+
TF_VERSION: ${{ matrix.versions.tf_version }}
37+
AWS_CLI_VERSIOIN: ${{ matrix.versions.awscli_version }}
38+
IMAGE_TAG: "tf${{ matrix.versions.tf_version }}-azcli${{ matrix.versions.awscli_version }}"
39+
40+
steps:
41+
- name: Check out the repo
42+
uses: actions/checkout@v2
43+
44+
- name: Get release tag and save in env var
45+
run: echo "::set-env name=RELEASE_TAG::${GITHUB_REF##*/}"
46+
47+
- name: Build image
48+
run: docker image build . --file Dockerfile --build-arg TERRAFORM_VERSION=$TF_VERSION --build-arg AWS_CLI_VERSION=$AWS_CLI_VERSIOIN --tag $ORGANIZATION/$IMAGE_NAME:$RELEASE_TAG-$IMAGE_TAG
49+
50+
- name: Login to Docker Hub registry
51+
run: echo '${{ secrets.DOCKERHUB_PASS }}' | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
52+
53+
- name: Push image to registry
54+
run: docker push $ORGANIZATION/$IMAGE_NAME:$RELEASE_TAG-$IMAGE_TAG
55+
56+
- name: Save image
57+
run: docker image save -o $IMAGE_NAME-$RELEASE_TAG-$IMAGE_TAG.tar $ORGANIZATION/$IMAGE_NAME:r$RELEASE_TAG-$IMAGE_TAG
58+
59+
- name: Upload image artifact
60+
uses: actions/upload-artifact@v2
61+
with:
62+
name: ${{ env.IMAGE_NAME }}-${{ env.RELEASE_TAG }}-${{ env.IMAGE_TAG }}
63+
path: ${{ env.IMAGE_NAME }}-${{ env.RELEASE_TAG }}-${{ env.IMAGE_TAG }}.tar

Dockerfile

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
# Setup build arguments with default versions
2-
ARG AZURE_CLI_VERSION=2.1.0
3-
ARG TERRAFORM_VERSION=0.12.21
2+
ARG AZURE_CLI_VERSION=2.5.1
3+
ARG TERRAFORM_VERSION=0.12.24
4+
ARG PYTHON_MAJOR_VERSION=3.7
45

56
# Download Terraform binary
6-
FROM debian:buster-20191118-slim as terraform
7+
FROM debian:buster-20191118-slim as terraform-cli
78
ARG TERRAFORM_VERSION
89
RUN apt-get update
910
# hadolint ignore=DL3015
10-
RUN apt-get install -y curl=7.64.0-4+deb10u1
11-
RUN apt-get install -y unzip=6.0-23+deb10u1 --no-install-recommends
12-
RUN apt-get install -y gnupg=2.2.12-1+deb10u1 --no-install-recommends
11+
RUN apt-get install -y --no-install-recommends curl=7.64.0-4+deb10u1
12+
RUN apt-get install -y --no-install-recommends ca-certificates=20190110
13+
RUN apt-get install -y --no-install-recommends unzip=6.0-23+deb10u1
14+
RUN apt-get install -y --no-install-recommends gnupg=2.2.12-1+deb10u1
1315
RUN curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS
1416
RUN curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
1517
RUN curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS.sig
1618
COPY hashicorp.asc hashicorp.asc
1719
RUN gpg --import hashicorp.asc
1820
RUN gpg --verify terraform_${TERRAFORM_VERSION}_SHA256SUMS.sig terraform_${TERRAFORM_VERSION}_SHA256SUMS
19-
# hadolint ignore=DL4006
21+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
2022
RUN grep terraform_${TERRAFORM_VERSION}_linux_amd64.zip terraform_${TERRAFORM_VERSION}_SHA256SUMS | sha256sum -c -
2123
RUN unzip -j terraform_${TERRAFORM_VERSION}_linux_amd64.zip
2224

2325
# Install az CLI using PIP
24-
FROM debian:buster-20191118-slim as azure-cli-pip
26+
FROM debian:buster-20191118-slim as azure-cli
2527
ARG AZURE_CLI_VERSION
28+
ARG PYTHON_MAJOR_VERSION
2629
RUN apt-get update
27-
RUN apt-get install -y python3=3.7.3-1 --no-install-recommends
28-
# hadolint ignore=DL3015
29-
RUN apt-get install -y python3-pip=18.1-5
30+
RUN apt-get install -y --no-install-recommends python3=${PYTHON_MAJOR_VERSION}.3-1
31+
RUN apt-get install -y --no-install-recommends python3-pip=18.1-5
32+
RUN pip3 install setuptools==46.1.3
3033
RUN pip3 install azure-cli==${AZURE_CLI_VERSION}
3134
# Fix an pyOpenSSL package issue... (see https://github.com/erjosito/ansible-azure-lab/issues/5)
3235
RUN pip3 uninstall -y pyOpenSSL cryptography
@@ -35,18 +38,18 @@ RUN pip3 install cryptography==2.8
3538

3639
# Build final image
3740
FROM debian:buster-20191118-slim
38-
ENV PYTHON_MAJOR_VERSION=3.7
41+
ARG PYTHON_MAJOR_VERSION
3942
RUN apt-get update \
4043
&& apt-get install -y --no-install-recommends \
4144
ca-certificates=20190110 \
42-
git=1:2.20.1-2+deb10u1 \
45+
git=1:2.20.1-2+deb10u3 \
4346
python3=${PYTHON_MAJOR_VERSION}.3-1 \
4447
&& apt-get clean \
4548
&& rm -rf /var/lib/apt/lists/* \
4649
&& update-alternatives --install /usr/bin/python python /usr/bin/python${PYTHON_MAJOR_VERSION} 1
47-
COPY --from=terraform /terraform /usr/local/bin/terraform
48-
COPY --from=azure-cli-pip /usr/local/bin/az* /usr/local/bin/
49-
COPY --from=azure-cli-pip /usr/local/lib/python${PYTHON_MAJOR_VERSION}/dist-packages /usr/local/lib/python${PYTHON_MAJOR_VERSION}/dist-packages
50-
COPY --from=azure-cli-pip /usr/lib/python3/dist-packages /usr/lib/python3/dist-packages
50+
COPY --from=terraform-cli /terraform /usr/local/bin/terraform
51+
COPY --from=azure-cli /usr/local/bin/az* /usr/local/bin/
52+
COPY --from=azure-cli /usr/local/lib/python${PYTHON_MAJOR_VERSION}/dist-packages /usr/local/lib/python${PYTHON_MAJOR_VERSION}/dist-packages
53+
COPY --from=azure-cli /usr/lib/python3/dist-packages /usr/lib/python3/dist-packages
5154
WORKDIR /workspace
5255
CMD ["bash"]

README.md

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![CircleCI](https://circleci.com/gh/Zenika/terraform-azure-cli.svg?style=svg)](https://circleci.com/gh/Zenika/terraform-azure-cli)
2+
[![](https://images.microbadger.com/badges/image/zenika/terraform-azure-cli.svg)](https://microbadger.com/images/zenika/terraform-azure-cli)
23
[![Docker Pulls](https://img.shields.io/docker/pulls/zenika/terraform-azure-cli.svg)](https://hub.docker.com/r/zenika/terraform-azure-cli/)
34

45
<p align="center">
@@ -8,33 +9,37 @@
89

910
# Terraform and Azure CLI Docker image
1011

11-
## :package: Supported tags and respective Dockerfile links
12-
Repository available on Docker Hub: [zenika/terraform-azure-cli](https://hub.docker.com/r/zenika/terraform-azure-cli)
12+
## 📦 Supported tags and respective Dockerfile links
13+
Available image tags can be found on the Docker Hub registry: [zenika/terraform-azure-cli](https://hub.docker.com/r/zenika/terraform-azure-cli/tags)
1314

14-
* [zenika/terraform-azure-cli:latest](https://github.com/Zenika/terraform-azure-cli/blob/master/Dockerfile)
15-
* [zenika/terraform-azure-cli:3.0-alpine](https://github.com/Zenika/terraform-azure-cli/blob/3.0/alpine.Dockerfile)
16-
* [zenika/terraform-azure-cli:3.0-debian](https://github.com/Zenika/terraform-azure-cli/blob/3.0/debian.Dockerfile)
17-
* [zenika/terraform-azure-cli:2.1-alpine](https://github.com/Zenika/terraform-azure-cli/blob/2.1/alpine.Dockerfile)
18-
* [zenika/terraform-azure-cli:2.1-debian](https://github.com/Zenika/terraform-azure-cli/blob/2.1/debian.Dockerfile)
19-
* [zenika/terraform-azure-cli:1.0](https://github.com/Zenika/terraform-azure-cli/blob/v1.0/Dockerfile) - Debian only
15+
The following image tag strategy is applied:
16+
* `zenika/terraform-azure-cli:latest` - build from master
17+
* Included CLI versions can be found in the [Dockerfile](https://github.com/Zenika/terraform-azure-cli/blob/master/Dockerfile)
18+
* `zenika/terraform-azure-cli:rS.T-tfUU.VV.WW-azcliXX.YY.ZZ` - build from releases
19+
* `rS.T` is the release tag
20+
* `tfUU.VV.WWW` is the included Terraform CLI version
21+
* `azcliXX.YY.ZZ` is the included AWS CLI version
2022

21-
:warning: alpine build support is deprecated, new versions will only be debian based.
22-
23-
## :bulb: Motivation
24-
Many Docker images including the Terraform and Azure CLI already exist out there, both on the Docker Hub and Github.
25-
But they all are quite oversized.
23+
Please report to the [releases page](https://github.com/Zenika/terraform-aws-cli/releases) for the changelogs. Any other tags are not supported.
2624

25+
## 💡Motivation
2726
The goal is to create a **minimalist** and **lightweight** image with these tools in order to reduce network and storage impact.
2827

2928
This image gives you the flexibility to be used for development or as a base image as you see fits.
3029

31-
## :wrench: What's inside ?
32-
33-
* [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest), see available version on the [pip repository](https://pypi.org/project/azure-cli/)
34-
* [Terraform CLI](https://www.terraform.io/docs/commands/index.html), see available versions on the [project release page](https://github.com/hashicorp/terraform/releases)
35-
* [Git](https://git-scm.com/), see available versions on the [Debian Packages repository](https://packages.debian.org/search?suite=buster&arch=any&searchon=names&keywords=git)
30+
## 🔧 What's inside ?
31+
* [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest):
32+
* Included version indicated in the image tag: `tfXX.YY.ZZ`
33+
* Available versions on the [pip repository](https://pypi.org/project/azure-cli/)
34+
* [Terraform CLI](https://www.terraform.io/docs/commands/index.html):
35+
* Included version indicated in the image tag: `awscliXX.YY.ZZ`
36+
* Available versions on the [project release page](https://github.com/hashicorp/terraform/releases)
37+
* [Git](https://git-scm.com/)
38+
* Available versions on the [Debian Packages repository](https://packages.debian.org/search?suite=buster&arch=any&searchon=names&keywords=git)
39+
* [Python 3](https://www.python.org/)
40+
* Available versions on the [Debian packages repository](https://packages.debian.org/search?suite=buster&arch=any&searchon=names&keywords=python3)
3641

37-
## :rocket: Usage
42+
## 🚀 Usage
3843

3944
### Launch the CLI
4045
Simply launch the container and use the CLI as you would on any other platform, for instance using the latest image:
@@ -57,17 +62,17 @@ Optionally, it is possible to choose the tools desired versions using [Docker bu
5762

5863
```bash
5964
# Set tools desired versions
60-
AZURE_CLI_VERSION=2.0.74
61-
TERRAFORM_VERSION=0.12.9
65+
AZURE_CLI_VERSION=2.5.1
66+
TERRAFORM_VERSION=0.12.24
6267

6368
# launch the build script with parameters
6469
./dev-build.sh $AZURE_CLI_VERSION $TERRAFORM_VERSION
6570
```
6671

67-
## :pray: Roadmap & Contributions
72+
## 🙏 Roadmap & Contributions
6873
Please refer to the [github project](https://github.com/Zenika/terraform-azure-cli/projects/1) to track new features.
6974

70-
Do not hesitate to contribute by [filling an issue](https://github.com/Zenika/terraform-azure-cli/issues) or [a PR](https://github.com/Zenika/terraform-azure-cli/pulls) !
75+
Do not hesitate to contribute by [filling an issue](https://github.com/Zenika/terraform-azure-cli/issues) or [opening a PR](https://github.com/Zenika/terraform-azure-cli/pulls) !
7176

72-
## :book: License
77+
## 📖 License
7378
This project is under the [Apache License 2.0](https://raw.githubusercontent.com/Zenika/terraform-azure-cli/master/LICENSE)

dev-build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ set -eo pipefail
44

55
if [ -n "$1" ] && [ -n "$2" ] ; then
66
echo "Building images with parameters AZURE_CLI_VERSION=${1} and TERRAFORM_VERSION=${2}"
7-
docker image build --build-arg AZURE_CLI_VERSION="$1" --build-arg TERRAFORM_VERSION="$2" -t zenika/terraform-azure-cli:latest .
7+
docker image build --build-arg AZURE_CLI_VERSION="$1" --build-arg TERRAFORM_VERSION="$2" -t zenika/terraform-azure-cli:dev .
88
else
99
echo "Building images with default parameters"
10-
docker image build -f Dockerfile -t zenika/terraform-azure-cli:latest .
10+
docker image build -f Dockerfile -t zenika/terraform-azure-cli:dev .
1111
fi

0 commit comments

Comments
 (0)