refactor(docker): improve image #32
Workflow file for this run
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
name: Docker CI | |
on: | |
pull_request: | |
paths: | |
- .github/workflows/docker-ci.yaml | |
- .github/scripts/** | |
- build.sbt | |
- src/** | |
env: | |
GITHUB_TOKEN: ${{ secrets.READ_PACKAGES }} | |
jobs: | |
build-and-test: | |
name: Build, Scan & Test | |
runs-on: self-hosted | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build Docker image | |
run: | | |
.github/scripts/dnd-sbt Docker/publishLocal | |
IMAGE_NAME=$(.github/scripts/dnd-sbt printDockerImageName | grep DOCKER_IMAGE | cut -d= -f2) | |
echo "IMAGE=${IMAGE_NAME}" >> $GITHUB_ENV | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/trivy-action@master | |
with: | |
image-ref: ${{ env.IMAGE }} | |
format: 'table' | |
exit-code: '1' | |
ignore-unfixed: true | |
vuln-type: 'os,library' | |
severity: 'CRITICAL,HIGH' | |
- name: Test image - run container | |
run: | | |
CONTAINER_ID=$(docker run -d -p 50051 ${IMAGE}) | |
echo "CONTAINER_ID=${CONTAINER_ID}" >> $GITHUB_ENV | |
sleep 15 | |
- name: Test image - verify service is running | |
run: | | |
docker exec ${CONTAINER_ID} /opt/docker/bin/healthcheck.sh | |
if [ $? -ne 0 ]; then | |
echo "Service check failed!" | |
exit 1 | |
fi | |
- name: Cleanup container | |
if: always() | |
run: | | |
if [ ! -z "${CONTAINER_ID}" ]; then | |
docker stop ${CONTAINER_ID} | |
docker rm ${CONTAINER_ID} | |
fi |