Skip to content

Commit e9b947d

Browse files
committed
CoPilot - bgw210 docker
1 parent 7d16428 commit e9b947d

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Dockerfile.bgw210

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM python:3.13-slim
2+
3+
# Set working directory
4+
WORKDIR /app
5+
6+
# Install system dependencies for lxml
7+
RUN apt-get update && apt-get install -y \
8+
libxml2-dev \
9+
libxslt-dev \
10+
gcc \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Copy requirements and install Python dependencies
14+
COPY requirements-bgw210.txt .
15+
RUN pip install --no-cache-dir -r requirements-bgw210.txt
16+
17+
# Copy the collector script
18+
COPY bgw210-700_prom_collector.py .
19+
20+
# Create non-root user for security
21+
RUN adduser --disabled-password --gecos '' --uid 1000 collector
22+
USER collector
23+
24+
# Expose the default port
25+
EXPOSE 8000
26+
27+
# Default command
28+
ENTRYPOINT ["python3", "bgw210-700_prom_collector.py"]
29+
CMD ["--host", "0.0.0.0", "--port", "8000"]

requirements-bgw210.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
requests>=2.25.0
2+
lxml>=4.6.0
3+
prometheus-client>=0.8.0

0 commit comments

Comments
 (0)