Skip to content

Commit

Permalink
Merge pull request #13 from BrownUniversity/chore-summer-23-updates
Browse files Browse the repository at this point in the history
Updates module with latest ruby and terraform support. Provider updat…
  • Loading branch information
digicosmos86 authored Jul 20, 2023
2 parents 430ed1d + 862d4b8 commit 71f04ad
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 246 deletions.
98 changes: 69 additions & 29 deletions .github/workflows/kitchen-tests.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,104 @@
name: kitchen-tests

on:
on:
push:
branches:
- main
- "main"
tags:
- "v*.*.*"
pull_request:

env:
REGISTRY: ghcr.io
IMAGE_NAME: brownuniversity/terraform-gcp-infoblox-a

jobs:
docker:
runs-on: ubuntu-latest

permissions:
packages: write
contents: read

outputs:
full_image_id: ${{ steps.save_full_image_id.outputs.full_image_id }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Build Image
run: docker build . --file Dockerfile --tag "${{ github.event.repository.name }}" --label "runnumber=${GITHUB_RUN_ID}"
- uses: dorny/[email protected]
id: filter
with:
base: ${{ github.ref }}
filters: |
all:
- '.github/workflows/kitchen-tests.yml'
- 'Dockerfile'
- 'Gemfile*'
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Push image to gh packages
id: upload
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=latest
echo VERSION=$VERSION
echo IMAGE_ID=$IMAGE_ID
docker tag ${{ github.event.repository.name }} $IMAGE_ID:${VERSION}
docker push $IMAGE_ID:$VERSION
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{major}}.{{minor}}
# NOTE: We are tapping into json output because tags could become a list if prior step is modified
- id: save_full_image_id
run: echo "full_image_id=${{ fromJSON(steps.meta.outputs.json).tags[0] }}" >> $GITHUB_OUTPUT

- name: print_tag
run: echo "${{ fromJSON(steps.meta.outputs.json).tags[0] }}"

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache

production-record:
needs: [docker]
runs-on: self-hosted
container:
image: ghcr.io/brownuniversity/terraform-infoblox-record-a:latest
steps:
- uses: actions/checkout@v2
- name: Run Kitchen
run: kitchen test production-record
env:
- uses: actions/checkout@v3
- name: Run Kitchen
run: kitchen test production-record
env:
TF_VAR_github_organization: BrownUniversity
TF_VAR_github_token: ${{ secrets.GH_token }}
INFOBLOX_USERNAME: ${{ secrets.INFOBLOX_JHUB_USER}}
INFOBLOX_PASSWORD: ${{ secrets.INFOBLOX_JHUB_PSWD}}
INFOBLOX_SERVER: ${{ secrets.INFOBLOX_JHUB_HOST }}


docker-cleanup:
needs: [production-record]
runs-on: self-hosted
steps:
- name: Clean up docker images
run: |
docker images --filter=reference='brownuniversity/terraform-infoblox-record-a'
docker images --filter=reference='brownuniversity/terraform-infoblox-record-a' --filter "dangling=true" | grep -E "brownuniversity/terraform-infoblox-record-a" | awk '{ print $3 }' | xargs docker rmi || :
echo "After cleanup"
docker images --filter=reference='brownuniversity/terraform-infoblox-record-a'
- name: Clean up docker images
run: |
docker images --filter=reference='brownuniversity/terraform-infoblox-record-a'
docker images --filter=reference='brownuniversity/terraform-infoblox-record-a' --filter "dangling=true" | grep -E "brownuniversity/terraform-infoblox-record-a" | awk '{ print $3 }' | xargs docker rmi || :
echo "After cleanup"
docker images --filter=reference='brownuniversity/terraform-infoblox-record-a'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ override.tf.json

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

.terraform.lock.hcl
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.50.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.81.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1
3.2.2
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hashicorp/terraform:1.2.5
FROM hashicorp/terraform:1.5.0

COPY .ruby-version .ruby-version

Expand All @@ -23,5 +23,4 @@ RUN gem install bundler && \
bundle config set system 'true' && \
bundle install


ENTRYPOINT ["/bin/bash"]
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "https://rubygems.org/" do
gem "kitchen-terraform", "~> 6.1.0"
gem "kitchen-terraform", "~> 7.0.2"
end
Loading

0 comments on commit 71f04ad

Please sign in to comment.