From 6a3cfc5327be1377b455f73c2333ee93a5ec3695 Mon Sep 17 00:00:00 2001 From: chennqqi Date: Mon, 9 Aug 2021 00:38:08 +0800 Subject: [PATCH 1/3] fix Dockerfile && docker-compose --- Dockerfile | 12 +++++++----- DockerfileCN | 12 +++++++----- docker-compose-mysql.yaml | 4 ++-- docker-compose-sqlite.yaml | 27 +++++++++++++++++++++++++++ docker-compose-standalone.yaml | 18 ------------------ 5 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 docker-compose-sqlite.yaml delete mode 100644 docker-compose-standalone.yaml diff --git a/Dockerfile b/Dockerfile index 3252f80..18dada6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ RUN yarn config set registry https://registry.npm.taobao.org && yarn install RUN yarn build # build backend -FROM golang:1.16.4 as backend-builder +FROM golang:1.16.4-alpine as backend-builder RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.12/main" > /etc/apk/repositories #RUN apk add build-base git musl-dev @@ -29,10 +29,12 @@ RUN mkdir -p /app COPY --from=backend-builder /go/bin/godnslog /app/godnslog COPY --from=frontend-builder /app/dist /app/dist -RUN addgroup -S app && \ - adduser app -S -G app -h /app && \ - chown -R app:app /app && \ - setcap cap_net_bind_service=eip /app/godnslog +ARG UID=1000 +ARG GID=1000 + +RUN addgroup -g $GID -S app && adduser -u $UID -S -g app app && \ + chown -R app:app /app && \ + setcap cap_net_bind_service=eip /app/godnslog WORKDIR /app USER app diff --git a/DockerfileCN b/DockerfileCN index 2fbcee5..cb700f0 100644 --- a/DockerfileCN +++ b/DockerfileCN @@ -6,7 +6,7 @@ COPY frontend /app RUN yarn config set registry https://registry.npm.taobao.org && yarn install RUN yarn build -FROM golang:1.16.4 as backend-builder +FROM golang:1.16.4-alpine as backend-builder RUN go env -w GOPROXY=https://goproxy.cn #RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.12/main" > /etc/apk/repositories @@ -31,10 +31,12 @@ RUN mkdir -p /app COPY --from=backend-builder /go/bin/godnslog /app/godnslog COPY --from=frontend-builder /app/dist /app/dist -RUN addgroup -S app && \ - adduser app -S -G app -h /app && \ - chown -R app:app /app && \ - setcap cap_net_bind_service=eip /app/godnslog +ARG UID=1000 +ARG GID=1000 + +RUN addgroup -g $GID -S app && adduser -u $UID -S -g app app && \ + chown -R app:app /app && \ + setcap cap_net_bind_service=eip /app/godnslog WORKDIR /app USER app diff --git a/docker-compose-mysql.yaml b/docker-compose-mysql.yaml index 45b23f9..74778d9 100644 --- a/docker-compose-mysql.yaml +++ b/docker-compose-mysql.yaml @@ -28,10 +28,10 @@ services: networks: - overlay volumes: - - db-data:/var/lib/mysql/data + - godnslog-mysql-data:/var/lib/mysql/data networks: overlay: volumes: - godnslog-data: \ No newline at end of file + godnslog-mysql-data: diff --git a/docker-compose-sqlite.yaml b/docker-compose-sqlite.yaml new file mode 100644 index 0000000..6c73fcd --- /dev/null +++ b/docker-compose-sqlite.yaml @@ -0,0 +1,27 @@ +version: "3.6" #docker version>=18.02.0+ + +services: + + init-godnslog: + image: busybox + container_name: busybox + command: /bin/sh -c 'touch /backup/.initialized && chown -R 1000:1000 /backup' + restart: "no" + volumes: + - godnslog-sqlite-data:/app/sqlite + + godnslog: + image: sort/godnslog + container_name: godnslog + environment: + - GIN_MODE=release + ports: + - "127.0.0.1:8080:8080" # 反向代理模式 + - "53:53/udp" + restart: always + command: serve -domain yourdomain.com -4 x.x.x.x -dsn 'file:/app/sqlite/godnslog.db?cache=shared&mode=rwc' + volumes: + - godnslog-sqlite-data:/app/sqlite/godnslog.db # 持久化存储 + +volumes: + godnslog-sqlite-data: diff --git a/docker-compose-standalone.yaml b/docker-compose-standalone.yaml deleted file mode 100644 index 704571b..0000000 --- a/docker-compose-standalone.yaml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3.6" #docker version>=18.02.0+ - -services: - godnslog: - image: sort/godnslog - container_name: godnslog - environment: - - GIN_MODE=release - ports: - - "127.0.0.1:10080:8080" # 反向代理模式 - - "53:53/udp" - restart: always - command: serve -domain yourdomain.com -4 x.x.x.x - volumes: - - ./godnslog.db:/app/godnslog.db # 持久化存储 - -volumes: - godnslog-standalone-data: \ No newline at end of file From cf49d34540eefa8164256062ff9718fd07a2cf10 Mon Sep 17 00:00:00 2001 From: chennqqi Date: Mon, 9 Aug 2021 08:59:45 +0800 Subject: [PATCH 2/3] fix dockerfile go mod --- DockerfileCN | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DockerfileCN b/DockerfileCN index cb700f0..d9e90b2 100644 --- a/DockerfileCN +++ b/DockerfileCN @@ -9,15 +9,15 @@ RUN yarn build FROM golang:1.16.4-alpine as backend-builder RUN go env -w GOPROXY=https://goproxy.cn -#RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.12/main" > /etc/apk/repositories -#RUN apk add build-base git musl-dev +RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.12/main" > /etc/apk/repositories +RUN apk add build-base git musl-dev COPY models /src/godnslog/models COPY server /src/godnslog/server COPY cache /src/godnslog/cache COPY *.go go.mod /src/godnslog/ WORKDIR /src/godnslog -RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/godnslog +RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -mod=mod -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/godnslog FROM alpine:3.13.5 From d1198a0c41df5d0fac48a5f14a1824964224780d Mon Sep 17 00:00:00 2001 From: chennqqi Date: Tue, 10 Aug 2021 01:04:19 +0800 Subject: [PATCH 3/3] fix docker-compose --- docker-compose-mysql.yaml | 37 ++++++++++++++++--------------------- docker-compose-sqlite.yaml | 16 ++++++++-------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/docker-compose-mysql.yaml b/docker-compose-mysql.yaml index 74778d9..5106af8 100644 --- a/docker-compose-mysql.yaml +++ b/docker-compose-mysql.yaml @@ -1,37 +1,32 @@ -version: "3.6" #docker version>=18.02.0+ +version: "3.3" #docker version>=18.02.0+ services: godnslog: - container_name: godnslog + depends_on: + - db image: sort/godnslog - command: serve -domain yourdomain.com -4 x.x.x.x -dsn 'mysql://' + container_name: godnslog + command: serve -domain yourdomain.com -4 x.x.x.x -driver mysql -dsn 'godnslog:godnslog123@tcp(db:3306)/godnslog?charset=utf8' ports: - - "127.0.0.1:10080:8080" # reverseProxy + - "8080:8080" # reverseProxy - "53:53/udp" environment: - GIN_MODE=release restart: always - depends_on: - - db - networks: - - overlay - + db: - image: mysql + image: mysql:5.7 container_name: godnslog-mysql - restart: always + restart: always environment: - MYSQL_ROOT_PASSWORD: example - MYSQL_USER: - MYSQL_PASSWORD: - MYSQL_DATABASE: - networks: - - overlay + MYSQL_ROOT_PASSWORD: godnslogPASS + MYSQL_USER: godnslog + MYSQL_PASSWORD: godnslog123 + MYSQL_DATABASE: godnslog + MYSQL_ROOT_HOST: "0.0.0.0" volumes: - - godnslog-mysql-data:/var/lib/mysql/data + - godnslog-mysql-data:/var/lib/mysql + #- ./mysql:/docker-entrypoint-initdb.d/ -networks: - overlay: - volumes: godnslog-mysql-data: diff --git a/docker-compose-sqlite.yaml b/docker-compose-sqlite.yaml index 6c73fcd..d8022e7 100644 --- a/docker-compose-sqlite.yaml +++ b/docker-compose-sqlite.yaml @@ -1,27 +1,27 @@ -version: "3.6" #docker version>=18.02.0+ +version: "3.3" #docker version>=18.02.0+ services: - init-godnslog: image: busybox container_name: busybox - command: /bin/sh -c 'touch /backup/.initialized && chown -R 1000:1000 /backup' + command: /bin/sh -c 'touch /app/db/godnslog.db && ls /app/db && chown -R 1000:1000 /app/db' restart: "no" volumes: - - godnslog-sqlite-data:/app/sqlite + - godnslog-sqlite-data:/app/db godnslog: image: sort/godnslog container_name: godnslog + restart: always environment: - - GIN_MODE=release + - GIN_MODE=release ports: - - "127.0.0.1:8080:8080" # 反向代理模式 + - "8080:8080" # 反向代理模式 - "53:53/udp" restart: always - command: serve -domain yourdomain.com -4 x.x.x.x -dsn 'file:/app/sqlite/godnslog.db?cache=shared&mode=rwc' + command: serve -domain example.com -4 100.100.100.100 -dsn 'file:/app/db/godnslog.db?cache=shared&mode=rwc' volumes: - - godnslog-sqlite-data:/app/sqlite/godnslog.db # 持久化存储 + - godnslog-sqlite-data:/app/db # 持久化存储 volumes: godnslog-sqlite-data: