Skip to content

Commit

Permalink
Merge pull request #25 from controllan/fix/ci-pipeline-and-map-copy
Browse files Browse the repository at this point in the history
ci: improve pipeline and fix error in the mapcopy function.
  • Loading branch information
pat-git authored Sep 22, 2024
2 parents 7fde26a + 64dec29 commit 2df047d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
37 changes: 35 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker
name: Docker build & push

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
Expand Down 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/[email protected]
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 All @@ -77,5 +110,5 @@ jobs:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ (github.event_name != 'pull_request' || inputs.force_docker_push == true ) && inputs.dry_run != true }}
tags: '${{ steps.meta.outputs.tags || inputs.tags }}${{ matrix.image_suffix }}'
tags: '${{ steps.meta.outputs.tags || inputs.tags }}'
labels: ${{ steps.meta.outputs.labels || inputs.labels }}
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
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c *dockerHealthCollector) collectMetrics(ch chan<- prometheus.Metric) {
}
mapcopy := func(src map[string]string) prometheus.Labels {
dst := map[string]string{}
for k, v := range labels {
for k, v := range src {
dst[k] = v
}
return dst
Expand Down

0 comments on commit 2df047d

Please sign in to comment.