Skip to content

Commit

Permalink
ci(docker-publish): verify that the image can be run successfully.
Browse files Browse the repository at this point in the history
  • Loading branch information
pat-git committed Sep 22, 2024
1 parent 1b542cf commit 64dec29
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ on:

run-name: "Build docker image [dry_run=${{ inputs.dry_run }}, ${{ vars.CONTAINER_REGISTRY_URL }}/${{ vars.CONTAINER_REGISTRY_REPOSITORY }}]"

env:
TEST_TAG: controllan/docker-state-exporter:test

jobs:
build:
runs-on: [ self-hosted, ubuntu-latest, '${{ vars.RUNNER_LABEL_NAME }}' ]
Expand Down Expand Up @@ -69,6 +72,36 @@ jobs:
with:
images: ${{ vars.CONTAINER_REGISTRY_URL }}/${{ vars.CONTAINER_REGISTRY_REPOSITORY }}

# Build test docker image
# https://github.com/docker/build-push-action
- name: Build test image [${{ env.TEST_TAG }}]
uses: docker/build-push-action@v6.7.0
with:
context: .
load: true
tags: ${{ env.TEST_TAG }}

- name: Run docker image and verify if it is running
env:
IMAGE_TAG: ${{ env.TEST_TAG }}
PORT: ${{ vars.DOCKER_TEST_PORT }}
WAIT_TIME: ${{ vars.DOCKER_TEST_WAIT_TIME }}
run: |
docker compose up -d
sleep $WAIT_TIME
HEALTH_STATUS=$(docker inspect --format "{{json .State.Health }}" docker_state_exporter | jq -r ".Status")
docker compose down -v
if [ "$HEALTH_STATUS" != "healthy" ]
then
echo "Docker state exporter has an unhealthy status and therefore seems not to work."
exit 1
fi
shell: bash

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image [${{ vars.CONTAINER_REGISTRY_URL }}/${{ vars.CONTAINER_REGISTRY_REPOSITORY }}]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ For Docker compose.
```yaml
---
version: '3.8'

services:
docker_state_exporter:
image: ghcr.io/controllan/docker-state-exporter
image: ghcr.io/controllan/docker-state-exporter:latest
container_name: docker_state_exporter
volumes:
- type: bind
source: /var/run/docker.sock
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
version: '3.8'
services:
docker_state_exporter:
image: ${IMAGE_TAG:-ghcr.io/controllan/docker-state-exporter:latest}
container_name: docker_state_exporter
volumes:
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
ports:
- "${PORT:-8080}:${PORT:-8080}"
command:
- --no-add-container-labels # Keep this if you do not wand to add container labels.
- --web.listen-address=:${PORT:-8080} # Set the port of the docker state exporter
healthcheck:
test: "wget -q -O - localhost:${PORT:-8080}/metrics | grep -q ',status=\"running\"} 1'"
interval: 3s
timeout: 10s
retries: 3

0 comments on commit 64dec29

Please sign in to comment.