Skip to content

Commit b8fea2e

Browse files
Refactor gateway DNS and routing
1 parent 853a99e commit b8fea2e

6 files changed

Lines changed: 685 additions & 307 deletions

File tree

.github/workflows/ci.yml

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
permissions:
22
contents: read
33
packages: write
4+
pull-requests: write
45

56
name: Build, Test & Deploy
67

@@ -41,6 +42,10 @@ jobs:
4142
DOCKER_IMAGE_NAME: ${{ github.repository }}
4243
# Push only on non-PR events (push to main/tags, workflow_dispatch)
4344
PUSH: ${{ toJSON(github.event_name != 'pull_request') }}
45+
# Push PR image only for PRs from the same repository
46+
PUSH_PR_IMAGE:
47+
${{ toJSON(github.event_name == 'pull_request' &&
48+
github.event.pull_request.head.repo.full_name == github.repository) }}
4449
steps:
4550
# Set up Docker Environment
4651
- uses: actions/checkout@v4
@@ -89,8 +94,10 @@ jobs:
8994
echo "Actor: $GITHUB_ACTOR"
9095
echo "Event: $GITHUB_EVENT_NAME"
9196
echo "Ref: $GITHUB_REF"
97+
echo "PUSH: ${{ env.PUSH }}"
98+
echo "PR: ${{ env.PUSH_PR_IMAGE }}"
9299
- name: Login to GitHub Container Registry
93-
if: ${{ fromJSON(env.PUSH) }}
100+
if: ${{ fromJSON(env.PUSH) || fromJSON(env.PUSH_PR_IMAGE) }}
94101
uses: docker/login-action@v3
95102
with:
96103
registry: ghcr.io
@@ -125,3 +132,74 @@ jobs:
125132
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
126133
labels: ${{ steps.docker_meta_public.outputs.labels }}
127134
tags: ${{ steps.docker_meta_public.outputs.tags }}
135+
136+
- name: Docker meta for PR image
137+
if: ${{ fromJSON(env.PUSH_PR_IMAGE) }}
138+
id: docker_meta_pr
139+
uses: crazy-max/ghaction-docker-meta@v1
140+
with:
141+
images: |
142+
ghcr.io/tecnativa/docker-whitelist-gateway-service
143+
tags: |
144+
type=raw,value=pr-${{ github.event.pull_request.number }}
145+
type=raw,value=pr-${{ github.event.pull_request.number }}-${{ github.sha }}
146+
147+
- name: Build and push PR image to GHCR
148+
if: ${{ fromJSON(env.PUSH_PR_IMAGE) }}
149+
uses: docker/build-push-action@v4
150+
with:
151+
context: .
152+
file: ./Dockerfile
153+
platforms: |
154+
linux/386
155+
linux/amd64
156+
linux/arm64
157+
load: false
158+
push: true
159+
provenance: false
160+
cache-from: type=local,src=/tmp/.buildx-cache
161+
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
162+
labels: ${{ steps.docker_meta_pr.outputs.labels }}
163+
tags: ${{ steps.docker_meta_pr.outputs.tags }}
164+
165+
- name: Comment PR with test image
166+
if: ${{ fromJSON(env.PUSH_PR_IMAGE) }}
167+
uses: actions/github-script@v7
168+
with:
169+
script: |
170+
const pr = context.payload.pull_request.number;
171+
const owner = context.repo.owner;
172+
const repo = context.repo.repo;
173+
const image = `ghcr.io/tecnativa/docker-whitelist-gateway-service:pr-${pr}`;
174+
const marker = "<!-- pr-test-image-comment -->";
175+
const body = `${marker}
176+
Test image published:
177+
\`${image}\``;
178+
179+
const { data: comments } = await github.rest.issues.listComments({
180+
owner,
181+
repo,
182+
issue_number: pr,
183+
per_page: 100,
184+
});
185+
186+
const existing = comments.find(comment =>
187+
comment.user?.type === "Bot" &&
188+
comment.body?.includes(marker)
189+
);
190+
191+
if (existing) {
192+
await github.rest.issues.updateComment({
193+
owner,
194+
repo,
195+
comment_id: existing.id,
196+
body,
197+
});
198+
} else {
199+
await github.rest.issues.createComment({
200+
owner,
201+
repo,
202+
issue_number: pr,
203+
body,
204+
});
205+
}

Dockerfile

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
11
FROM python:3-alpine
22

3-
ENTRYPOINT ["dumb-init", "--", "/usr/local/bin/entrypoint.sh"]
4-
CMD ["proxy"]
5-
HEALTHCHECK CMD ["healthcheck"]
6-
7-
RUN apk add --no-cache -t .build build-base curl-dev && \
8-
apk add --no-cache iptables ipset iproute2 dnsmasq && \
9-
apk add --no-cache libcurl && \
10-
pip install --no-cache-dir dnspython dumb-init pycurl && \
11-
apk del .build
3+
RUN apk add --no-cache --virtual .build-deps \
4+
build-base \
5+
curl-dev \
6+
&& apk add --no-cache \
7+
dumb-init \
8+
dnsmasq \
9+
iproute2 \
10+
ipset \
11+
iptables \
12+
libcurl \
13+
&& pip install --no-cache-dir \
14+
dnspython \
15+
pycurl \
16+
&& apk del .build-deps
1217

1318
ENV NAMESERVERS="1.1.1.1 8.8.8.8" \
1419
PORT="*" \
15-
LISTEN_PORT=15000 \
16-
RESOLVE_INTERVAL=60 \
17-
PRE_RESOLVE=0 \
18-
MODE=tcp \
19-
VERBOSE=0 \
20-
MAX_CONNECTIONS=100 \
21-
UDP_ANSWERS=1 \
22-
HTTP_HEALTHCHECK=0 \
20+
LISTEN_PORT="15000" \
21+
RESOLVE_INTERVAL="60" \
22+
PRE_RESOLVE="0" \
23+
MODE="tcp" \
24+
VERBOSE="0" \
25+
MAX_CONNECTIONS="100" \
26+
UDP_ANSWERS="1" \
27+
HTTP_HEALTHCHECK="0" \
2328
HTTP_HEALTHCHECK_URL="http://\$TARGET/" \
24-
SMTP_HEALTHCHECK=0 \
29+
SMTP_HEALTHCHECK="0" \
2530
SMTP_HEALTHCHECK_URL="smtp://\$TARGET/" \
2631
SMTP_HEALTHCHECK_COMMAND="HELP" \
27-
DNS_UPSTREAMS="1.1.1.1 8.8.8.8" \
28-
RESOLVE_INTERVAL="60"
32+
DNS_UPSTREAMS="1.1.1.1 8.8.8.8"
2933

3034
COPY proxy.py /usr/local/bin/proxy
3135
COPY healthcheck.py /usr/local/bin/healthcheck
3236
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
33-
RUN chmod +x /usr/local/bin/entrypoint.sh
37+
38+
RUN chmod +x \
39+
/usr/local/bin/proxy \
40+
/usr/local/bin/healthcheck \
41+
/usr/local/bin/entrypoint.sh
42+
43+
ENTRYPOINT ["dumb-init", "--", "/usr/local/bin/entrypoint.sh"]
44+
CMD ["proxy"]
45+
HEALTHCHECK CMD ["healthcheck"]

0 commit comments

Comments
 (0)