Skip to content

Commit

Permalink
chore: update and simplify verifyimage.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
theseion committed Jan 29, 2024
1 parent 7458db2 commit d4bc758
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions .github/workflows/verifyimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ env:
REPO: "owasp/modsecurity-crs"

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
targets: ${{ steps.generate.outputs.targets }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: List targets
id: generate
uses: docker/bake-action/subaction/list-targets@v4

build:
runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
crs_version: ["3.3.5"]
image: [apache, nginx]
variant: ["", "-alpine"]
platform: [linux/amd64]
target: ${{ fromJson(needs.prepare.outputs.targets) }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -26,47 +36,31 @@ jobs:

# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
driver-opts: image=moby/buildkit:master

- name: Docker meta ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }}
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.REPO }}
flavor: |
latest=false
tags: |
type=raw,value=${{ matrix.image }}${{ matrix.variant }}
type=semver,pattern={{major}},value=v${{ matrix.crs_version }},suffix=${{ matrix.image }}${{ matrix.variant }}-{{date 'YYYYMMDDHHMM'}}
type=semver,pattern={{major}}.{{minor}},value=v${{ matrix.crs_version }},suffix=${{ matrix.image }}${{ matrix.variant }}-{{date 'YYYYMMDDHHMM'}}
type=semver,pattern={{version}},value=v${{ matrix.crs_version }},suffix=${{ matrix.image }}${{ matrix.variant }}-{{date 'YYYYMMDDHHMM'}}
- name: Build ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }}
uses: docker/[email protected]
- name: Build images
uses: docker/[email protected]
with:
targets: ${{ matrix.image }}${{ matrix.variant }}
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: ${{ matrix.target }}
set: |
"${{ matrix.image }}${{ matrix.variant }}.platform=${{ matrix.platform }}"
*.platform=linux/amd64
load: true
push: false

- name: Run ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }}
- name: Run ${{ matrix.target }}
run: |
TAG=$(docker image inspect -f '{{ json .RepoTags }}' ${{ env.REPO }}:${{ matrix.image }}${{ matrix.variant }} | jq -r '.[0]')
echo "Starting container with TAG=$TAG"
docker run --pull "never" -d --name ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }}-test "$TAG"
docker logs ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }}-test
echo "Starting container ${{ matrix.target }}"
docker run --pull "never" -d --name ${{ matrix.target }}-test "${REPO}:${{ matrix.target }}"
docker logs ${{ matrix.target }}-test
- name: Verify ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }}
- name: Verify ${{ matrix.target }}
run: |
[ $(docker inspect ${{ matrix.crs_version }}-${{ matrix.image }}${{ matrix.variant }}-test --format='{{.State.Running}}') = 'true' ]
[ $(docker inspect ${{ matrix.target }}-test --format='{{.State.Running}}') = 'true' ]

0 comments on commit d4bc758

Please sign in to comment.