Skip to content

Commit

Permalink
Move to terraform 1.5.7 and add Dockerfile validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mpagot committed Feb 7, 2024
1 parent 60808b4 commit 99907d4
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ansible.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Ansible

on: [push, pull_request]

jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/gluescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Glue Script

on:
push:
branches:
- "main"
paths:
- scripts/qesap/**
- .github/workflows/gluescript.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.6
terraform_version: 1.5.7
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
run: terraform init
Expand Down
95 changes: 95 additions & 0 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Tools environment

on:
push:
branches:
- "main"
paths:
- Dockerfile
- requirements.txt
- requirements.yml
- .github/workflows/tools.yml
pull_request:
paths:
- Dockerfile
- requirements.txt
- requirements.yml
- .github/workflows/tools.yml

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: qe-sap-deployment # ${{ github.repository }}
TEST_TAG: test



jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
#- name: Install cosign
# if: github.event_name != 'pull_request'
# uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0
# with:
# cosign-release: 'v1.11.0'

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
#- name: Extract Docker metadata
# id: meta
# uses: docker/metadata-action@v5
# with:
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
#context: .
push: false
load: true # Export to Docker Engine rather than pushing to a registry
# push: ${{ github.event_name != 'pull_request' }} # Don't push on PR
tags: ${{ github.run_id }} # ${{ env.TEST_TAG }} # ${{ steps.meta.outputs.tags }}
#target: test
#labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Test
run: |
docker run --rm ${{ github.run_id }} cat /etc/os-release
- name: Podman info
run: |
podman info
- name: Test
run: |
./tools/image_test.sh ${{ env.TEST_TAG }}
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM opensuse/tumbleweed:latest
## AZURE
# way suggested on https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=zypper
RUN zypper ref && zypper up -y && \
zypper install -y tar gzip unzip curl python310-pip openssh && \
zypper install -y tar gzip unzip curl python311-pip openssh && \
rpm --import https://packages.microsoft.com/keys/microsoft.asc && \
zypper addrepo --name 'Azure CLI' --check https://packages.microsoft.com/yumrepos/azure-cli azure-cli && \
zypper install --from azure-cli -y azure-cli && \
Expand All @@ -21,13 +21,20 @@ RUN curl https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud
echo 'source ~/google-cloud-sdk/path.bash.inc' >> ~/.bashrc

## Terraform
RUN curl https://releases.hashicorp.com/terraform/1.3.6/terraform_1.3.6_linux_amd64.zip -o terraform.zip && \
RUN curl https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip -o terraform.zip && \
unzip terraform.zip -d /usr/local/bin && \
terraform -install-autocomplete && \
rm terraform.zip

ENV VIRTUAL_ENV=/opt/venv
RUN python3.11 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
COPY requirements.txt .
RUN pip install -r requirements.txt
RUN pip install --upgrade pip && \
pip install -r requirements.txt

COPY requirements.yml .
RUN ansible-galaxy install -r requirements.yml

RUN mkdir /src
WORKDIR /src
WORKDIR /src
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ This project is in a very early stage of development.

Tools needed

* Python 3.9
* terraform v1.3.6
* Python >= 3.9
* terraform v1.5.7
* ansible-core 2.13.5 : please refer to the **requirements.txt** file
* cloud provider cli tools (`az`, `aws`, `gcloud`)

Expand Down
24 changes: 24 additions & 0 deletions tools/image_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

img_name=$1

#podman build -f Dockerfile -t "${img_name}"

podman run "${img_name}" terraform --version | grep 1.5.7 || ( echo "ERROR[$?] wrong or not usable Terraform" ; exit 1 )
podman run -v $(pwd):/src "${img_name}" terraform -chdir=/src/terraform/azure init || ( echo "ERROR[$?] terraform init does not work for azure" ; exit 1 )
podman run -v $(pwd):/src "${img_name}" terraform -chdir=/src/terraform/aws init || ( echo "ERROR[$?] terraform init does not work for aws" ; exit 1 )
podman run -v $(pwd):/src "${img_name}" terraform -chdir=/src/terraform/gcp init || ( echo "ERROR[$?] terraform init does not work for google" ; exit 1 )

podman run "${img_name}" python3.11 --version | grep 3.11 || ( echo "ERROR[$?] wrong or not usable Python" ; exit 1 )
podman run "${img_name}" pip3.11 --version || ( echo "ERROR[$?] wrong or not usable pip" ; exit 1 )
podman run "${img_name}" pip3.11 freeze | grep ansible-core || ( echo "ERROR[$?] ansible-core not installed" ; exit 1 )
podman run "${img_name}" ansible --version || ( echo "ERROR[$?] wrong or not usable Terraform" ; exit 1 )
podman run "${img_name}" ansible-galaxy --version || ( echo "ERROR[$?] wrong or not usable Terraform" ; exit 1 )

podman run "${img_name}" pip3.11 freeze | grep aws || ( echo "ERROR[$?] aws cli not installed" ; exit 1 )
podman run "${img_name}" aws --version || ( echo "ERROR[$?] wrong or not usable aws" ; exit 1 )
podman run "${img_name}" az --version || ( echo "ERROR[$?] wrong or not usable az" ; exit 1 )
podman run "${img_name}" cat /root/.bashrc
#podman run "${img_name}" gcloud --version


0 comments on commit 99907d4

Please sign in to comment.