Skip to content

Commit

Permalink
ci: add docker build pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: rare-magma <[email protected]>
  • Loading branch information
rare-magma committed Aug 4, 2024
1 parent a249638 commit bc002d5
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.github/
*.conf
*.png
*.json
*.service
*.timer
*.yml
Makefile
*.md
46 changes: 46 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Create and publish a container image

on:
push:
branches: main
schedule:
- cron: "2 02 4 * *"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
packages: write
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM docker.io/library/alpine:latest
ENV RUNNING_IN_DOCKER=true
ENTRYPOINT ["/bin/bash"]
CMD ["/app/cloudflare_exporter.sh"]
COPY cloudflare_exporter.sh /app/cloudflare_exporter.sh
RUN addgroup -g 10001 user \
&& adduser -H -D -u 10000 -G user user
RUN apk add --quiet --no-cache bash coreutils curl jq
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ Bash script that uploads the Cloudflare Analytics API data to influxdb on an hou
1. Run it.

```bash
docker run --rm --init --tty --interactive --volume $(pwd):/app localhost/cloudflare-exporter
```
docker run --rm --init --tty --interactive --read-only --cap-drop ALL --security-opt no-new-privileges:true --cpus 2 -m 64m --pids-limit 16 --volume ./cloudflare_exporter.conf:/app/cloudflare_exporter.conf:ro --volume ./cloudflare_zone_list.json:/app/cloudflare_zone_list.json:ro ghcr.io/rare-magma/cloudflare-exporter:latest
```

### With the Makefile

Expand Down
30 changes: 25 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
version: "3"
services:
scheduler:
image: ghcr.io/reddec/compose-scheduler:1.0.1
image: ghcr.io/reddec/compose-scheduler:1.1.0
read_only: true
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
deploy:
resources:
limits:
cpus: "2"
memory: 250m
pids: 1024
privileged: true
restart: unless-stopped
volumes:
Expand All @@ -10,10 +21,19 @@ services:
cloudflare-exporter:
image: cloudflare-exporter:latest
init: true
build:
context: .
dockerfile: ./Dockerfile
read_only: true
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
deploy:
resources:
limits:
cpus: "2"
memory: 64m
pids: 16
volumes:
- ./:/app:z
- ./cloudflare_exporter.conf:/app/cloudflare_exporter.conf:ro
- ./cloudflare_zone_list.json:/app/cloudflare_zone_list.json:ro
labels:
net.reddec.scheduler.cron: "5 * * * *"

0 comments on commit bc002d5

Please sign in to comment.