Skip to content

Commit 31c9159

Browse files
authored
Merge pull request #156 from raetha/main
Added support for docker and GHCR container building
2 parents 73d82eb + efc75d3 commit 31c9159

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ BLOCK_BASED_ON_SNI=0
1515

1616
# Optional Discord webhook URL to send a message to when a script is done running or if an error occurs.
1717
# DISCORD_WEBHOOK_URL=
18+
19+
# Optional settings for the Docker container example (see docker-compose.yml.example)
20+
# TZ=UTC
21+
# CONTAINER_NAME=cgps
22+
# IMAGE_TAG=latest
23+
# CRON_SCHEDULE=0 3 * * 1

.github/workflows/build.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish to container registry
2+
3+
on:
4+
push:
5+
branches:
6+
- v*
7+
release:
8+
types: [ "published" ]
9+
10+
env:
11+
# Use docker.io for Docker Hub if empty
12+
REGISTRY: ghcr.io
13+
# github.repository as <account>/<repo>
14+
IMAGE_NAME: ${{ github.repository }}
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Get Node Version
29+
run: echo "NODE_VERSION=$(cat .node-version)" >> $GITHUB_ENV
30+
31+
# Login against a Docker registry except on PR
32+
# https://github.com/docker/login-action
33+
- name: Log into registry ${{ env.REGISTRY }}
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
# Set up BuildKit Docker container builder to be able to build multi-platform images and export cache
41+
# https://github.com/docker/setup-buildx-action
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
# Extract metadata (tags, labels) for Docker
46+
# https://github.com/docker/metadata-action
47+
- name: Extract Docker metadata
48+
id: meta
49+
uses: docker/metadata-action@v5
50+
with:
51+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
52+
53+
# Build and push Docker image with Buildx (don't push on PR)
54+
# https://github.com/docker/build-push-action
55+
- name: Build and push Docker image
56+
id: build-and-push
57+
uses: docker/build-push-action@v6
58+
with:
59+
context: .
60+
platforms: linux/amd64,linux/arm64
61+
push: true
62+
build-args: |
63+
NODE_VERSION=${{ env.NODE_VERSION }}
64+
tags: ${{ steps.meta.outputs.tags }}
65+
labels: ${{ steps.meta.outputs.labels }}
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ARG NODE_VERSION=lts
2+
3+
FROM docker.io/node:${NODE_VERSION}-alpine
4+
5+
WORKDIR /app
6+
7+
# Add project source to image
8+
ADD . /app
9+
10+
# Install project dependencies and set permissions
11+
RUN apk add --no-cache tzdata && npm ci && chmod +x /app/docker-entrypoint.sh
12+
13+
# Run the entrypoint script on container startup
14+
ENTRYPOINT ["/app/docker-entrypoint.sh"]

docker-compose.yml.example

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
cgps:
3+
container_name: ${CONTAINER_NAME:-cgps}
4+
hostname: ${CONTAINER_NAME:-cgps}
5+
image: ghcr.io/mrrfv/cloudflare-gateway-pihole-scripts:${IMAGE_TAG:-latest}
6+
restart: unless-stopped
7+
network_mode: bridge
8+
#tty:true # Only needed if you want crond logs in the docker log (noisy)
9+
environment:
10+
TZ: "${TZ:-UTC}"
11+
CRON_SCHEDULE: "${CRON_SCHEDULE:-0 3 * * 1}"
12+
CLOUDFLARE_API_TOKEN: "${CLOUDFLARE_API_TOKEN}"
13+
CLOUDFLARE_ACCOUNT_ID: "${CLOUDFLARE_ACCOUNT_ID}"
14+
CLOUDFLARE_LIST_ITEM_LIMIT: "${CLOUDFLARE_LIST_ITEM_LIMIT:-300000}"
15+
DRY_RUN: "${DRY_RUN:-0}"
16+
BLOCK_PAGE_ENABLED: "${BLOCK_PAGE_ENABLED:-0}"
17+
BLOCK_BASED_ON_SNI: "${BLOCK_BASED_ON_SNI:-0}"
18+
ALLOWLIST_URLS: "${ALLOWLIST_URLS}"
19+
BLOCKLIST_URLS: "${BLOCKLIST_URLS}"
20+
#PING_URL: "${PING_URL}"
21+
#DISCORD_WEBHOOK_URL: "${DISCORD_WEBHOOK_URL}"

docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
# Add cron entry
4+
echo "$CRON_SCHEDULE /usr/local/bin/npm start --prefix /app/" | crontab -
5+
6+
# Start crond
7+
echo "Starting crond..."
8+
/usr/sbin/crond -l 2 -f

0 commit comments

Comments
 (0)