-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update and simplify verifyimage.yml
- Loading branch information
Showing
1 changed file
with
26 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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' ] |