Skip to content

Commit 1731e08

Browse files
bgauduchbgauduch
andauthored
Tooling rework (#111)
* use supported version for local build version * correct build script and update readme * add git ignore config for generated container structure test config * update push-latest action to retreive latest version from JSON * remove generated containe structure test config * restore triggers for build-push latest action * update dockerhub description action * add link to Terraform AWS repository, fixme in build script * udpate docker hub descritpion only from mastere * add path filter to trigger actions only when needed * correct build script * lint Dockerfile and update dependancies, use new hasicorp gpg key * update hadolint and container-structure-test version for build script, use hadolint config file * update dockerfile lint action, add trigger path on itself for push-latest action * add support for TF 0.15.5 and 1.0.0, add support for AZ cli 2.23, 2.24 and 2.25 * update readme * remove curl verbose leftover arguments * add hadolint config to lint action * upgrade support for version 0.14 to patch 11 * enable dependabot * only support 2 latest az cli releases * move dependabot config file Co-authored-by: bgauduch <user.personal@users.noreply.github.com>
1 parent c6f39bc commit 1731e08

15 files changed

+256
-132
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# explicitely exclude all files from the build context
22
# (each file needed in the Dockefile need to be included manually)
33
*
4+
5+
# Specific to Terraform installation
46
!hashicorp.asc
7+
8+
# Specific to Hadolint linter
9+
!hadolint.yaml

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
- package-ecosystem: "docker"
8+
directory: "/"
9+
schedule:
10+
interval: "daily"

.github/workflows/build-test.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
name: build-test
22

33
# trigger on any push
4-
# but not on master, tags or markdown modifications
4+
# but not on master or tags
5+
# and only for image-related modifications
56
on:
67
push:
78
tags-ignore:
89
- "**"
910
branches:
1011
- "**"
1112
- "!master"
12-
paths-ignore:
13-
- "!README.md"
14-
- "!CODE_OF_CONDUCT.md"
13+
paths:
14+
- "Dockerfile"
15+
- "supported_versions.json"
16+
- "hashicorp.asc"
17+
- "tests/*"
18+
- ".dockerignore"
19+
- ".github/workflows/build-test.yml"
1520

1621
env:
1722
IMAGE_NAME: "terraform-azure-cli"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Update Docker Hub Description
2+
on:
3+
push:
4+
branches:
5+
- master
6+
paths:
7+
- README.md
8+
- .github/workflows/dockerhub-description.yml
9+
jobs:
10+
dockerHubDescription:
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Update Docker Hub Description
16+
uses: peter-evans/dockerhub-description@v2
17+
with:
18+
username: ${{ secrets.DOCKERHUB_USERNAME }}
19+
password: ${{ secrets.DOCKERHUB_PASS }}
20+
repository: zenika/terraform-azure-cli

.github/workflows/lint-dockerfile.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
push:
66
paths:
77
- "Dockerfile"
8+
- ".github/workflows/lint-dockerfile.yml"
89

910
jobs:
1011
lint:
@@ -15,6 +16,7 @@ jobs:
1516
uses: actions/checkout@v2
1617

1718
- name: Lint Dockerfile
18-
uses: brpaz/hadolint-action@v1.3.1
19+
uses: brpaz/hadolint-action@v1.5.0
1920
with:
2021
dockerfile: "Dockerfile"
22+
config: "hadolint.yaml"

.github/workflows/push-latest.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
name: push-latest
22

33
# trigger on push to master
4+
# only on image-related modifications
45
on:
56
push:
67
branches:
78
- "master"
8-
paths-ignore:
9-
- "!README.md"
10-
- "!CODE_OF_CONDUCT.md"
9+
paths:
10+
- "Dockerfile"
11+
- "supported_versions.json"
12+
- "hashicorp.asc"
13+
- "tests/**"
14+
- ".dockerignore"
15+
- ".github/workflows/push-latest.yml"
1116

1217
env:
1318
ORGANIZATION: "zenika"
@@ -22,8 +27,13 @@ jobs:
2227
- name: Check out the repo
2328
uses: actions/checkout@v2
2429

30+
- name: Retrieve latest suported versions
31+
run: |
32+
echo "AZ_VERSION=$(jq -r '.azcli_version | sort | .[-1]' supported_versions.json)" >> $GITHUB_ENV
33+
echo "TF_VERSION=$(jq -r '.tf_version | sort | .[-1]' supported_versions.json)" >> $GITHUB_ENV
34+
2535
- name: Build image
26-
run: docker image build . --file Dockerfile --tag $ORGANIZATION/$IMAGE_NAME:$IMAGE_TAG
36+
run: docker image build . --file Dockerfile --build-arg TERRAFORM_VERSION=${TF_VERSION} --build-arg AZURE_CLI_VERSION=${AZ_VERSION} --tag $ORGANIZATION/$IMAGE_NAME:$IMAGE_TAG
2737

2838
- name: Login to Docker Hub registry
2939
run: echo '${{ secrets.DOCKERHUB_PASS }}' | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# ignore generated container structure test config
2+
tests/container-structure-tests.yml

Dockerfile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
# Setup build arguments with default versions
2-
ARG AZURE_CLI_VERSION=2.20.0
3-
ARG TERRAFORM_VERSION=0.14.8
1+
# Build arguments
2+
ARG AZURE_CLI_VERSION
3+
ARG TERRAFORM_VERSION
44
ARG PYTHON_MAJOR_VERSION=3.7
5-
ARG DEBIAN_VERSION=buster-20210208-slim
5+
ARG DEBIAN_VERSION=buster-20210511-slim
66

77
# Download Terraform binary
88
FROM debian:${DEBIAN_VERSION} as terraform-cli
99
ARG TERRAFORM_VERSION
1010
RUN apt-get update
11-
RUN apt-get install -y --no-install-recommends apt-utils=1.8.2.2
12-
RUN apt-get install -y --no-install-recommends curl=7.64.0-4+deb10u1
11+
RUN apt-get install -y --no-install-recommends apt=1.8.2.3
12+
RUN apt-get install -y --no-install-recommends curl=7.64.0-4+deb10u2
1313
RUN apt-get install -y --no-install-recommends ca-certificates=20200601~deb10u2
1414
RUN apt-get install -y --no-install-recommends unzip=6.0-23+deb10u2
1515
RUN apt-get install -y --no-install-recommends gnupg=2.2.12-1+deb10u1
16+
WORKDIR /workspace
1617
RUN curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS
1718
RUN curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
1819
RUN curl -Os https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS.sig
@@ -28,7 +29,7 @@ FROM debian:${DEBIAN_VERSION} as azure-cli
2829
ARG AZURE_CLI_VERSION
2930
ARG PYTHON_MAJOR_VERSION
3031
RUN apt-get update
31-
RUN apt-get install -y --no-install-recommends apt-utils=1.8.2.2
32+
RUN apt-get install -y --no-install-recommends apt=1.8.2.3
3233
RUN apt-get install -y --no-install-recommends python3=${PYTHON_MAJOR_VERSION}.3-1
3334
RUN apt-get install -y --no-install-recommends python3-pip=18.1-5
3435
RUN apt-get install -y --no-install-recommends gcc=4:8.3.0-1
@@ -51,12 +52,12 @@ RUN apt-get update \
5152
&& apt-get clean \
5253
&& rm -rf /var/lib/apt/lists/* \
5354
&& update-alternatives --install /usr/bin/python python /usr/bin/python${PYTHON_MAJOR_VERSION} 1
54-
COPY --from=terraform-cli /terraform /usr/local/bin/terraform
55+
WORKDIR /workspace
56+
COPY --from=terraform-cli /workspace/terraform /usr/local/bin/terraform
5557
COPY --from=azure-cli /usr/local/bin/az* /usr/local/bin/
5658
COPY --from=azure-cli /usr/local/lib/python${PYTHON_MAJOR_VERSION}/dist-packages /usr/local/lib/python${PYTHON_MAJOR_VERSION}/dist-packages
5759
COPY --from=azure-cli /usr/lib/python3/dist-packages /usr/lib/python3/dist-packages
5860

59-
WORKDIR /workspace
6061
RUN groupadd --gid 1001 nonroot \
6162
# user needs a home folder to store azure credentials
6263
&& useradd --gid nonroot --create-home --uid 1001 nonroot \

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ It will :
6464
* Execute [container structure tests](https://github.com/GoogleContainerTools/container-structure-test) on the image.
6565

6666
```bash
67-
# launch build script
68-
./dev-build.sh
67+
# launch build script using latest supported versions for both Azure and Terraform CLI
68+
./build.sh
6969
```
7070

71-
Optionally, it is possible to choose the tools desired versions using [Docker builds arguments](https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg) :
71+
Optionally, it is possible to choose the tools desired versions:
7272

7373
```bash
7474
# Set desired tool versions
75-
AZURE_CLI_VERSION=2.20.0
76-
TERRAFORM_VERSION=0.14.8
75+
AZURE_CLI_VERSION=2.24.2
76+
TERRAFORM_VERSION=0.15.5
7777

7878
# launch build script with parameters
79-
./dev-build.sh $AZURE_CLI_VERSION $TERRAFORM_VERSION
79+
./build.sh $AZURE_CLI_VERSION $TERRAFORM_VERSION
8080
```
8181

8282
## 🙏 Roadmap & Contributions
@@ -87,20 +87,28 @@ Do not hesitate to contribute by [filling an issue](https://github.com/Zenika/te
8787
## ⬆️ Dependencies upgrades checklist
8888

8989
* Supported versions:
90-
* check Azure CLI version (only keep 3 latest releases), available versions on the [project release page](https://github.com/Azure/azure-cli/releases)
91-
* check Terraform CLI version (keep all version from 0.11), available versions on the [project release page](https://github.com/hashicorp/terraform/releases)
90+
* check Azure CLI version (only keep 2 latest releases), available on the [project release page](https://github.com/Azure/azure-cli/releases)
91+
* check Terraform CLI version (keep all minor versions from 0.11), available on the [project release page](https://github.com/hashicorp/terraform/releases)
9292
* Dockerfile:
93-
* update default version in ARGS
9493
* check base image version on DockerHub
95-
* check OS packages on Debian package repository
94+
* check OS package versions on Debian package repository
9695
* Available Git versions on the [Debian Packages repository](https://packages.debian.org/search?suite=buster&arch=any&searchon=names&keywords=git)
9796
* Available Python versions on the [Debian packages repository](https://packages.debian.org/search?suite=buster&arch=any&searchon=names&keywords=python3)
9897
* same process for all other packages
98+
* check Pip package versions on [pypi](https://pypi.org/)
9999
* Github actions:
100100
* check [runner version](https://github.com/actions/virtual-environments#available-environments)
101-
* check all actions version release
101+
* check each action release versions
102+
* Build scripts:
103+
* check container tags:
104+
* [Hadolint releases](https://github.com/hadolint/hadolint/releases)
105+
* [Container-structure-test](https://github.com/GoogleContainerTools/container-structure-test/releases)
102106
* Readme:
103-
* update version references in code exemple
107+
* update version in code exemples
108+
109+
## Similar repositories
110+
111+
* For AWS: [zenika-open-source/terraform-aws-cli](https://github.com/zenika-open-source/terraform-aws-cli)
104112

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

build.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
# FIXME: use getopts function to parse aguments
6+
# FIXME: if provided, both TF and AZ CLI semvers should be regex-validated
7+
8+
# Set AZ and TF CLI to latest supported versions if not specified
9+
[[ -n $1 ]] && AZ_VERSION=$1 || AZ_VERSION=$(jq -r '.azcli_version | sort | .[-1]' supported_versions.json)
10+
[[ -n $2 ]] && TF_VERSION=$2 || TF_VERSION=$(jq -r '.tf_version | sort | .[-1]' supported_versions.json)
11+
12+
# Set image name and tag (dev if not specified)
13+
IMAGE_NAME="zenika/terraform-azure-cli"
14+
[[ -n $3 ]] && IMAGE_TAG=$3 || IMAGE_TAG="dev"
15+
16+
# Lint Dockerfile
17+
echo "Linting Dockerfile..."
18+
docker run --rm --interactive --volume "${PWD}":/data --workdir /data hadolint/hadolint:2.5.0-alpine /bin/hadolint --config hadolint.yaml Dockerfile
19+
echo "Dockerfile successfully linted!"
20+
21+
# Build image
22+
echo "Building images with AZURE_CLI_VERSION=${AZ_VERSION} and TERRAFORM_VERSION=${TF_VERSION}..."
23+
docker image build --build-arg AZURE_CLI_VERSION="$AZ_VERSION" --build-arg TERRAFORM_VERSION="$TF_VERSION" -t $IMAGE_NAME:$IMAGE_TAG .
24+
echo "Image successfully builded!"
25+
26+
# Test image
27+
echo "Generating test config with AZURE_CLI_VERSION=${AZ_VERSION} and TERRAFORM_VERSION=${TF_VERSION}..."
28+
export AZ_VERSION=${AZ_VERSION} && export TF_VERSION=${TF_VERSION}
29+
envsubst '${AZ_VERSION},${TF_VERSION}' < tests/container-structure-tests.yml.template > tests/container-structure-tests.yml
30+
echo "Test config successfully generated!"
31+
echo "Executing container structure test..."
32+
docker container run --rm -it -v "${PWD}"/tests/container-structure-tests.yml:/tests.yml:ro -v /var/run/docker.sock:/var/run/docker.sock:ro gcr.io/gcp-runtimes/container-structure-test:v1.10.0 test --image $IMAGE_NAME:$IMAGE_TAG --config /tests.yml
33+
unset AZ_VERSION
34+
unset TF_VERSION

0 commit comments

Comments
 (0)