Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build and Push Docker Image

on:
push:
branches: [ "main" ]
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/masterdnsvpn
tags: |
# version from tag (v1.2.3 -> 1.2.3)
type=semver,pattern={{version}}
# full tag (v1.2.3)
type=ref,event=tag
# latest only on default branch
type=raw,value=latest,enable={{is_default_branch}}
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ---------- BUILD STAGE ----------
FROM golang:1.25-alpine AS builder

WORKDIR /app
RUN apk add --no-cache git

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -ldflags="-s -w" -o server ./cmd/server && \
go build -ldflags="-s -w" -o client ./cmd/client

# ---------- RUNTIME ----------
FROM alpine:3.20

WORKDIR /app

RUN adduser -D appuser

COPY --from=builder /app/server /usr/local/bin/server
COPY --from=builder /app/client /usr/local/bin/client

USER appuser

# DNS port
EXPOSE 53/udp

# select mode: server (default) or client
ENV MODE=server

# entrypoint wrapper
ENTRYPOINT ["/bin/sh", "-c", "if [ \"$MODE\" = \"client\" ]; then exec client \"$@\"; else exec server \"$@\"; fi", "--"]

# default args
CMD ["--help"]