Skip to content

Commit

Permalink
docker
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbbbbbbbbbbba committed Sep 15, 2024
1 parent 6fb7233 commit 8b4e0ff
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 31 deletions.
28 changes: 28 additions & 0 deletions .docker-compose/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# nginx.conf
server {
listen 80;

# 代理到 Node.js 服务
location / {
proxy_pass http://bbsgo:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

# 代理到 Go 服务
location /api/ {
proxy_pass http://bbsgo:8082;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

# 代理到 Admin 静态资源
location /admin/ {
alias /app/bbs-go/admin/;
try_files $uri $uri/ /index.html;
}
}
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ admin/node_modules
admin/dist
admin/dist-ssr
admin/*.local

26 changes: 22 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN CGO_ENABLED=0 go build -v -o bbs-go main.go && chmod +x bbs-go


# site builder
FROM node:20-alpine AS site_builder
FROM node:20 AS site_builder

ENV APP_HOME=/code/bbs-go/site
WORKDIR "$APP_HOME"
Expand All @@ -26,19 +26,37 @@ RUN npm install -g pnpm
RUN pnpm install
RUN pnpm build:docker

# admin builder
FROM node:20-alpine AS admin_builder

ENV APP_HOME=/code/bbs-go/admin
WORKDIR "$APP_HOME"

# 安装 jpegtran 所需库
RUN apk add --no-cache libjpeg-turbo-utils

COPY ./admin ./
# RUN npm install -g pnpm --registry=https://registry.npmmirror.com
# RUN pnpm install --registry=https://registry.npmmirror.com
RUN npm install -g pnpm
RUN pnpm install
RUN pnpm build:docker

# run
FROM node:20-alpine

ENV APP_HOME=/app/bbs-go
WORKDIR "$APP_HOME"

COPY --from=site_builder /code/bbs-go/site/.output ./site/.output
COPY --from=site_builder /code/bbs-go/site/node_modules ./site/node_modules

COPY --from=server_builder /code/bbs-go/server/bbs-go ./server/bbs-go
COPY --from=server_builder /code/bbs-go/server/*.yaml ./server/
COPY --from=server_builder /code/bbs-go/server/*.yml ./server/
COPY ./start.sh ${APP_HOME}/start.sh
COPY --from=site_builder /code/bbs-go/site/.output ./site/.output
COPY --from=site_builder /code/bbs-go/site/node_modules ./site/node_modules
COPY --from=admin_builder /code/bbs-go/admin/dist ./admin

COPY ./start.sh ${APP_HOME}/start.sh
RUN chmod +x ${APP_HOME}/start.sh

EXPOSE 8082
Expand Down
5 changes: 0 additions & 5 deletions admin/.dockerignore

This file was deleted.

2 changes: 2 additions & 0 deletions admin/.env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_API_BASE_URL=
VITE_API_SITE_URL=
19 changes: 0 additions & 19 deletions admin/Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions admin/config/vite.config.docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import configImageminPlugin from './plugin/imagemin';
export default mergeConfig(
{
mode: 'docker',
base: '/admin',
plugins: [
// configCompressPlugin('gzip'),
configVisualizerPlugin(),
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ services:
BBSGO_DB_URL: root:123456@tcp(bbs-go-mysql:3306)/bbsgo_db?charset=utf8mb4&parseTime=True&loc=Local
BBSGO_BASEURL: http://localhost:3000
restart: on-failure

nginx:
container_name: bbs-go-nginx
image: nginx:latest
ports:
- 80:80
volumes:
- .docker-compose/nginx.conf:/etc/nginx/conf.d/default.conf # 挂载自定义的 nginx 配置文件
depends_on:
- bbsgo
restart: on-failure

2 changes: 0 additions & 2 deletions server/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ func NewServer() {
})
})

app.HandleDir("/admin", "./admin")

// api
mvc.Configure(app.Party("/api"), func(m *mvc.Application) {
m.Party("/topic").Handle(new(api.TopicController))
Expand Down

0 comments on commit 8b4e0ff

Please sign in to comment.