Skip to content

Chore: Use official github actions for building docker images #48

Chore: Use official github actions for building docker images

Chore: Use official github actions for building docker images #48

Workflow file for this run

name: kitchen-tests
on:
push:
branches:
- "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@v3
- uses: dorny/[email protected]
id: filter
with:
base: ${{ github.ref }}
filters: |
all:
- '.github/workflows/kitchen-tests.yml'
- 'Dockerfile'
- 'Gemfile*'
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- 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@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'