Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.

Commit 05aed37

Browse files
authored
feat: Add Debian based image (#81)
1 parent 67b77e0 commit 05aed37

File tree

8 files changed

+143
-25
lines changed

8 files changed

+143
-25
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
cache-dependency-path: package-lock.json
2727
- run: npm ci
2828
- run: npm run lint
29-
docker:
29+
docker-alpine:
3030
runs-on: ubuntu-latest
3131
permissions:
3232
contents: read
@@ -54,6 +54,37 @@ jobs:
5454
tags: ${{ steps.meta.outputs.tags }}
5555
labels: ${{ steps.meta.outputs.labels }}
5656
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
57+
docker-debian:
58+
runs-on: ubuntu-latest
59+
permissions:
60+
contents: read
61+
packages: write
62+
steps:
63+
- uses: actions/checkout@v3
64+
- uses: docker/metadata-action@v4
65+
id: meta
66+
with:
67+
images: ghcr.io/joshuaavalon/cloudflare-ddns
68+
tags: |
69+
type=sha
70+
type=ref,event=branch
71+
flavor: |
72+
suffix=-debian,onlatest=true
73+
- uses: docker/setup-qemu-action@v2
74+
- uses: docker/setup-buildx-action@v2
75+
- uses: docker/login-action@v2
76+
if: github.event_name != 'pull_request'
77+
with:
78+
registry: ghcr.io
79+
username: ${{ github.actor }}
80+
password: ${{ secrets.GITHUB_TOKEN }}
81+
- uses: docker/build-push-action@v4
82+
with:
83+
file: Dockerfile.debian
84+
push: ${{ github.event_name != 'pull_request' }}
85+
tags: ${{ steps.meta.outputs.tags }}
86+
labels: ${{ steps.meta.outputs.labels }}
87+
platforms: linux/amd64,linux/arm64,linux/arm/v7
5788
release-please:
5889
runs-on: ubuntu-latest
5990
if: github.ref == 'refs/heads/master'

.github/workflows/tag.yml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
schedule:
88
- cron: "0 0 * * *"
99
jobs:
10-
docker:
10+
docker-alpine:
1111
runs-on: ubuntu-latest
1212
permissions:
1313
contents: read
@@ -33,9 +33,44 @@ jobs:
3333
registry: ghcr.io
3434
username: ${{ github.actor }}
3535
password: ${{ secrets.GITHUB_TOKEN }}
36-
- uses: docker/build-push-action@v3
36+
- uses: docker/build-push-action@v4
3737
with:
3838
push: ${{ github.event_name != 'pull_request' }}
3939
tags: ${{ steps.meta.outputs.tags }}
4040
labels: ${{ steps.meta.outputs.labels }}
4141
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
42+
docker-debian:
43+
runs-on: ubuntu-latest
44+
permissions:
45+
contents: read
46+
packages: write
47+
steps:
48+
- uses: actions/checkout@v3
49+
- uses: docker/metadata-action@v4
50+
id: meta
51+
with:
52+
images: ghcr.io/joshuaavalon/cloudflare-ddns
53+
tags: |
54+
type=schedule
55+
type=semver,pattern={{version}}
56+
type=semver,pattern={{major}}.{{minor}}
57+
type=semver,pattern={{major}}
58+
type=sha
59+
type=ref,event=branch
60+
flavor: |
61+
suffix=-debian,onlatest=true
62+
- uses: docker/setup-qemu-action@v2
63+
- uses: docker/setup-buildx-action@v2
64+
- uses: docker/login-action@v2
65+
if: github.event_name != 'pull_request'
66+
with:
67+
registry: ghcr.io
68+
username: ${{ github.actor }}
69+
password: ${{ secrets.GITHUB_TOKEN }}
70+
- uses: docker/build-push-action@v4
71+
with:
72+
file: Dockerfile.debian
73+
push: ${{ github.event_name != 'pull_request' }}
74+
tags: ${{ steps.meta.outputs.tags }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
platforms: linux/amd64,linux/arm64,linux/arm/v7

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RUN npm ci && \
1313

1414
RUN mkdir /packages && \
1515
cp --parents -r packages/*/lib / && \
16+
1617
cp --parents packages/*/package.json /
1718

1819
FROM $BASE_IMAGE
@@ -24,6 +25,7 @@ ENV CF_DNS__CONFIG=/app/config.yaml
2425
ENV NODE_ENV=production
2526
ENV CF_DNS__CRON='*/5 * * * *'
2627
ENV NPM_CONFIG_UPDATE_NOTIFIER=false
28+
ENV NPM_CONFIG_LOGLEVEL=warn
2729

2830
COPY --from=builder /packages /app/packages/
2931
COPY package.json package-lock.json index.mjs /app/

Dockerfile.debian

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
ARG BASE_IMAGE=node:18-slim
2+
3+
FROM $BASE_IMAGE as builder
4+
5+
WORKDIR /app
6+
7+
COPY packages /app/packages/
8+
COPY package.json tsconfig.json package-lock.json /app/
9+
10+
RUN npm ci && \
11+
npm run build && \
12+
rm -rf packages/*/lib/__tests__
13+
14+
RUN mkdir /packages && \
15+
cp --parents -r packages/*/lib / && \
16+
cp --parents packages/*/package.json /
17+
18+
FROM $BASE_IMAGE
19+
20+
WORKDIR /app
21+
22+
ENV NPM_CONFIG_PREFIX=/app/.npm
23+
ENV CF_DNS__CONFIG=/app/config.yaml
24+
ENV NODE_ENV=production
25+
ENV CF_DNS__CRON='*/5 * * * *'
26+
ENV NPM_CONFIG_UPDATE_NOTIFIER=false
27+
ENV NPM_CONFIG_LOGLEVEL=warn
28+
29+
COPY --from=builder /packages /app/packages/
30+
COPY package.json package-lock.json index.mjs /app/
31+
COPY docker/root/ /
32+
33+
RUN chmod +x /app/cloudflare.sh /app/start.sh
34+
35+
RUN apt-get update && apt-get install -y cron
36+
37+
SHELL ["/bin/bash", "-c"]
38+
39+
RUN npm ci
40+
41+
ENV ZONE=
42+
ENV HOST=
43+
ENV EMAIL=
44+
ENV API=
45+
ENV TTL=
46+
ENV PROXY=
47+
ENV DEBUG=
48+
ENV FORCE_CREATE=
49+
ENV RUNONCE=
50+
ENV IPV6=
51+
52+
ENTRYPOINT ["/app/start.sh"]
53+
CMD []

docker/root/app/cloudflare.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env bash
22

3-
cd /app
3+
cd /app;
44

55
if [ "$CF_DNS__LOG_TYPE" == "json" ]; then
6-
npm run --cache /home/node/.npm start:json;
6+
su node -c "npm run --cache /home/node/.npm start:json";
77
else
8-
npm run --cache /home/node/.npm start:pretty;
8+
su node -c "npm run --cache /home/node/.npm start:pretty";
99
fi

docker/root/app/start.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ else
1818
";
1919
fi
2020

21-
chown node:node /app
21+
chown node:node /app;
2222

2323
if [ "$CF_DNS__LOG_TYPE" == "json" ]; then
2424
msg='{"level":30,"time":';
@@ -35,9 +35,15 @@ else
3535
echo "Setting crontab to ${CF_DNS__CRON}";
3636
fi
3737

38-
# Delete last line
39-
sed -i '$ d' /etc/crontabs/root
40-
echo -e "${CF_DNS__CRON} /app/cloudflare.sh" >> /etc/crontabs/root
41-
chmod 600 /etc/crontabs/root
42-
43-
crond -f
38+
if [ -f /etc/debian_version ]; then
39+
printenv > /etc/environment;
40+
echo -e "${CF_DNS__CRON} root /app/cloudflare.sh > /proc/1/fd/1 2>&1" > /etc/cron.d/cloudflare-ddns;
41+
chmod 600 /etc/cron.d/cloudflare-ddns;
42+
cron -f;
43+
else
44+
# Delete last line
45+
sed -i '$ d' /etc/crontabs/root;
46+
echo -e "${CF_DNS__CRON} /app/cloudflare.sh" >> /etc/crontabs/root;
47+
chmod 600 /etc/crontabs/root;
48+
crond -f;
49+
fi

docker/root/etc/crontabs/root

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/app/src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ const updateDnsRecords = async (ctx: Context): Promise<void> => {
6565
};
6666

6767
const printConfig = (ctx: Context): void => {
68-
const { config, logger } = ctx;
69-
const cloneConfig = omit(config, ["auth"]);
70-
const configStr = JSON.stringify(cloneConfig, null, 2);
71-
logger.debug(`Running with the following configuration:\n${configStr}`);
68+
const { logger } = ctx;
69+
const config = omit(ctx.config, ["auth"]);
70+
logger.debug("Running with the following configuration", { config });
7271
};
7372

7473
const registerParsers = (config: Config): void => {

0 commit comments

Comments
 (0)