From 52e949de85799d7950f6d055a84e7715bacf7f40 Mon Sep 17 00:00:00 2001 From: yusing Date: Mon, 8 Sep 2025 09:15:24 +0800 Subject: [PATCH] feat: Add development environment configuration with Docker Compose and Dockerfile --- Makefile | 9 ++++++--- dev.Dockerfile | 33 +++++++++++++++++++++++++++++++++ dev.compose.yml | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 dev.Dockerfile create mode 100644 dev.compose.yml diff --git a/Makefile b/Makefile index 11864e24..550c6c53 100755 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ shell := /bin/sh export VERSION ?= $(shell git describe --tags --abbrev=0) export BUILD_DATE ?= $(shell date -u +'%Y%m%d-%H%M') export GOOS = linux +export GOARCH ?= amd64 WEBUI_DIR ?= ../godoxy-frontend DOCS_DIR ?= ../godoxy-wiki @@ -113,9 +114,11 @@ build: run: cd ${PWD} && [ -f .env ] && godotenv -f .env go run ${BUILD_FLAGS} ./cmd -debug: - make NAME="godoxy-test" debug=1 build - sh -c 'HTTP_ADDR=:81 HTTPS_ADDR=:8443 API_ADDR=:8899 DEBUG=1 bin/godoxy-test' +dev: + docker compose -f dev.compose.yml up -t 0 -d + +dev-build: build + docker compose -f dev.compose.yml up -t 0 -d --build mtrace: ${BIN_PATH} debug-ls-mtrace > mtrace.json diff --git a/dev.Dockerfile b/dev.Dockerfile new file mode 100644 index 00000000..369b1cb1 --- /dev/null +++ b/dev.Dockerfile @@ -0,0 +1,33 @@ +# Stage 1: deps +FROM golang:1.25.0-alpine AS deps +HEALTHCHECK NONE + +# package version does not matter +# trunk-ignore(hadolint/DL3018) +RUN apk add --no-cache tzdata make libcap-setcap + +# Stage 3: Final image +FROM alpine:3.22 + +LABEL maintainer="yusing@6uo.me" +LABEL proxy.exclude=1 + +# copy timezone data +COPY --from=deps /usr/share/zoneinfo /usr/share/zoneinfo + +# copy certs +COPY --from=deps /etc/ssl/certs /etc/ssl/certs + +ARG TARGET +ENV TARGET=${TARGET} + +ENV DOCKER_HOST=unix:///var/run/docker.sock + +# copy binary +COPY bin/${TARGET} /app/run + +WORKDIR /app + +RUN chown -R 1000:1000 /app + +CMD ["/app/run"] \ No newline at end of file diff --git a/dev.compose.yml b/dev.compose.yml new file mode 100644 index 00000000..9919f350 --- /dev/null +++ b/dev.compose.yml @@ -0,0 +1,44 @@ +services: + app: + image: godoxy-dev + build: + context: . + dockerfile: dev.Dockerfile + args: + - TARGET=godoxy + container_name: godoxy-proxy-dev + restart: unless-stopped + environment: + TZ: Asia/Hong_Kong + API_ADDR: :8999 + API_USER: dev + API_PASSWORD: 1234 + API_SKIP_ORIGIN_CHECK: true + API_JWT_SECURE: false + API_JWT_TTL: 24h + DEBUG: true + API_SECRET: 1234567891234567 + labels: + proxy.exclude: true + proxy.#1.healthcheck.disable: true + ipc: host + network_mode: host + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ./dev-data/config:/app/config + - ./dev-data/certs:/app/certs + - ./dev-data/error_pages:/app/error_pages:ro + - ./dev-data/data:/app/data + - ./dev-data/logs:/app/logs + depends_on: + - tinyauth + tinyauth: + image: ghcr.io/steveiliop56/tinyauth:v3 + container_name: tinyauth + restart: unless-stopped + environment: + - SECRET=12345678912345671234567891234567 + - APP_URL=https://tinyauth.my.app + - USERS=user:$$2a$$10$$UdLYoJ5lgPsC0RKqYH/jMua7zIn0g9kPqWmhYayJYLaZQ/FTmH2/u # user:password + labels: + proxy.tinyauth.port: "3000"