1+ name : Build and Push BGW210 Docker Image
2+
3+ on :
4+ push :
5+ paths :
6+ - ' bgw210-700_prom_collector.py'
7+ - ' Dockerfile.bgw210'
8+ - ' requirements-bgw210.txt'
9+ - ' .github/workflows/bgw210-docker.yml'
10+ pull_request :
11+ paths :
12+ - ' bgw210-700_prom_collector.py'
13+ - ' Dockerfile.bgw210'
14+ - ' requirements-bgw210.txt'
15+ - ' .github/workflows/bgw210-docker.yml'
16+
17+ env :
18+ REGISTRY : ghcr.io
19+ IMAGE_NAME : bgw210-prom-collector
20+
21+ jobs :
22+ build-and-push :
23+ runs-on : ubuntu-latest
24+ permissions :
25+ contents : read
26+ packages : write
27+
28+ steps :
29+ - name : Checkout repository
30+ uses : actions/checkout@v4
31+
32+ - name : Set up Docker Buildx
33+ uses : docker/setup-buildx-action@v3
34+
35+ - name : Log in to Container Registry
36+ uses : docker/login-action@v3
37+ with :
38+ registry : ${{ env.REGISTRY }}
39+ username : ${{ github.actor }}
40+ password : ${{ secrets.GITHUB_TOKEN }}
41+
42+ - name : Extract metadata
43+ id : meta
44+ uses : docker/metadata-action@v5
45+ with :
46+ images : ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
47+ tags : |
48+ type=ref,event=branch
49+ type=ref,event=pr
50+ type=sha,prefix={{branch}}-
51+ type=raw,value=latest,enable={{is_default_branch}}
52+
53+ - name : Build and push Docker image
54+ uses : docker/build-push-action@v5
55+ with :
56+ context : .
57+ file : ./Dockerfile.bgw210
58+ push : true
59+ tags : ${{ steps.meta.outputs.tags }}
60+ labels : ${{ steps.meta.outputs.labels }}
61+ platforms : linux/amd64,linux/arm64
62+ cache-from : type=gha
63+ cache-to : type=gha,mode=max
64+
65+ - name : Test Docker image
66+ if : github.event_name == 'pull_request'
67+ run : |
68+ docker run --rm -d --name bgw210-test -p 8000:8000 \
69+ ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
70+ sleep 10
71+ curl -f http://localhost:8000/metrics || exit 1
72+ docker stop bgw210-test
0 commit comments