feat: 添加docker部署
This commit is contained in:
5
backend/.dockerignore
Normal file
5
backend/.dockerignore
Normal file
@@ -0,0 +1,5 @@
|
||||
.git
|
||||
.run
|
||||
bin
|
||||
**/*.log
|
||||
|
||||
38
backend/Dockerfile
Normal file
38
backend/Dockerfile
Normal file
@@ -0,0 +1,38 @@
|
||||
#
|
||||
# Multi-stage build for backend API and worker.
|
||||
#
|
||||
# Build:
|
||||
# docker build -f backend/Dockerfile -t feedsystem-backend:api --target api .
|
||||
# docker build -f backend/Dockerfile -t feedsystem-backend:worker --target worker .
|
||||
#
|
||||
|
||||
ARG GO_VERSION=1.24.5
|
||||
|
||||
FROM golang:${GO_VERSION} AS build
|
||||
WORKDIR /src/backend
|
||||
|
||||
COPY backend/go.mod backend/go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
COPY backend/ ./
|
||||
|
||||
ENV CGO_ENABLED=0
|
||||
RUN go build -trimpath -ldflags="-s -w" -o /out/api ./cmd
|
||||
RUN go build -trimpath -ldflags="-s -w" -o /out/worker ./cmd/worker
|
||||
|
||||
FROM alpine:3.21 AS base
|
||||
RUN apk add --no-cache ca-certificates tzdata && adduser -D -H -s /sbin/nologin app
|
||||
WORKDIR /app
|
||||
COPY --from=build /src/backend/configs ./configs
|
||||
RUN mkdir -p ./.run/uploads && chown -R app:app /app
|
||||
USER app
|
||||
|
||||
FROM base AS api
|
||||
COPY --from=build /out/api /app/api
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["/app/api"]
|
||||
|
||||
FROM base AS worker
|
||||
COPY --from=build /out/worker /app/worker
|
||||
ENTRYPOINT ["/app/worker"]
|
||||
|
||||
22
backend/configs/config.docker.yaml
Normal file
22
backend/configs/config.docker.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
database:
|
||||
host: mysql
|
||||
port: 3306
|
||||
user: root
|
||||
password: 123456
|
||||
dbname: feedsystem
|
||||
|
||||
redis:
|
||||
host: redis
|
||||
port: 6379
|
||||
password: 123456
|
||||
db: 0
|
||||
|
||||
rabbitmq:
|
||||
host: rabbitmq
|
||||
port: 5672
|
||||
username: admin
|
||||
password: password123
|
||||
|
||||
Reference in New Issue
Block a user