Skip to content

Commit

Permalink
Add basic docker image test
Browse files Browse the repository at this point in the history
  • Loading branch information
akospasztor committed Feb 12, 2024
1 parent 3d300ed commit 50001a1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
44 changes: 35 additions & 9 deletions .github/workflows/ci-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Docker Image CI
on: push
env:
DOCKERHUB_USER: akospasztor
DOCKER_IMAGE_NAME: akospasztor/docker-gcc-arm

jobs:
build:
Expand All @@ -11,16 +12,16 @@ jobs:
os: [linux]
include:
- os: linux
runner: ubuntu-20.04
runner: ubuntu-latest
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup docker buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
- name: Cache docker layers
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.version }}-${{ github.sha }}
Expand All @@ -29,26 +30,51 @@ jobs:
${{ runner.os }}-buildx-
- name: Docker metadata
id: docker_meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
images: akospasztor/docker-gcc-arm
images: ${{ env.DOCKER_IMAGE_NAME }}
flavor: |
prefix=${{ matrix.version }}-${{ matrix.os }}-
latest=false
tags: |
type=raw,value=latest
type=semver,pattern={{version}}
- name: Login to dockerhub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PAT }}
- name: Build docker image
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: ./${{ matrix.version }}/${{ matrix.os }}
push: ${{ contains(github.ref, 'refs/tags/') }}
load: true
push: false
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
builder: ${{ steps.buildx.outputs.name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Test docker image
run: >
docker run --rm -i --env GCC_VERSION=${{ matrix.version }}
${{ env.DOCKER_IMAGE_NAME }}:${{ steps.docker_meta.outputs.version }}
< script/test-gcc-version.sh
- name: Search for vulnerabilities with docker scout
uses: docker/scout-action@v1
with:
command: cves
image: ${{ env.DOCKER_IMAGE_NAME }}:${{ steps.docker_meta.outputs.version }}
only-severities: critical, high
only-fixed: true
summary: true
- name: Push docker image
if: ${{ contains(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
context: ./${{ matrix.version }}/${{ matrix.os }}
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
builder: ${{ steps.buildx.outputs.name }}
Expand Down
17 changes: 17 additions & 0 deletions script/test-gcc-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

# This tiny script verifies that the installed GCC version is correct by
# comparing the installed GCC version to the version passed via an
# environmental variable.
# The script exits with 0 (OK) if the installed GCC version is correct and
# exits with 1 (error) if either the environmental variable is not set or the
# installed version does not match the value of the environmental variable.

[[ -z $GCC_VERSION ]] && exit 1

if arm-none-eabi-gcc --version | grep "$GCC_VERSION"
then
exit 0
else
exit 1
fi

0 comments on commit 50001a1

Please sign in to comment.