From 208edee33b18dd88aa7999a7a874571c686f4b8f Mon Sep 17 00:00:00 2001 From: mlogclub Date: Mon, 16 Sep 2024 23:03:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AEdocker=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .docker-compose/nginx.conf | 28 ---------------------------- Dockerfile | 21 ++++++++++----------- docker-compose.yml | 29 +++++++++++++---------------- server/.gitignore | 1 + server/internal/server/server.go | 2 ++ site/nuxt.config.ts | 3 +++ 6 files changed, 29 insertions(+), 55 deletions(-) delete mode 100644 .docker-compose/nginx.conf diff --git a/.docker-compose/nginx.conf b/.docker-compose/nginx.conf deleted file mode 100644 index ae924c2af..000000000 --- a/.docker-compose/nginx.conf +++ /dev/null @@ -1,28 +0,0 @@ -# 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 { - root /usr/share/nginx/html; - index index.html; - } -} diff --git a/Dockerfile b/Dockerfile index ad4857e69..2e057adc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,10 +20,10 @@ ENV APP_HOME=/code/bbs-go/site WORKDIR "$APP_HOME" COPY ./site ./ -# 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 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 @@ -34,10 +34,10 @@ ENV APP_HOME=/code/bbs-go/admin WORKDIR "$APP_HOME" 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 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 @@ -52,12 +52,11 @@ COPY --from=server_builder /code/bbs-go/server/*.yaml ./server/ COPY --from=server_builder /code/bbs-go/server/*.yml ./server/ 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 --from=admin_builder /code/bbs-go/admin/dist ./server/admin COPY ./start.sh ${APP_HOME}/start.sh RUN chmod +x ${APP_HOME}/start.sh -EXPOSE 8082 -EXPOSE 3000 +EXPOSE 8082 3000 80 CMD ["./start.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 5b4dcf980..91e8c9819 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,25 +30,22 @@ services: context: ./ volumes: - /data/docker:/data - - bbsgo-admin:/app/bbs-go/admin # 这里定义了一个卷 environment: BBSGO_ENV: docker BBSGO_DB_URL: root:123456@tcp(bbs-go-mysql:3306)/bbsgo_db?charset=utf8mb4&parseTime=True&loc=Local - BBSGO_BASEURL: http://localhost - restart: on-failure - - - nginx: - container_name: bbs-go-nginx - image: nginx:latest + BBSGO_BASEURL: ports: - - 80:80 - volumes: - - .docker-compose/nginx.conf:/etc/nginx/conf.d/default.conf # 挂载自定义的 nginx 配置文件 - - bbsgo-admin:/usr/share/nginx/html/admin # 使用同一个卷 - depends_on: - - bbsgo + - 8082:8082 + - 3000:3000 restart: on-failure -volumes: - bbsgo-admin: # 定义卷 + # nginx: + # container_name: bbs-go-nginx + # image: nginx:latest + # ports: + # - 80:80 + # volumes: + # - .docker-compose/nginx.conf:/etc/nginx/conf.d/default.conf + # depends_on: + # - bbsgo + # restart: on-failure diff --git a/server/.gitignore b/server/.gitignore index 3a84f18c2..1bc9e2524 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -28,6 +28,7 @@ tags logs/*.log web/* tmp/* +admin/* internal/web* diff --git a/server/internal/server/server.go b/server/internal/server/server.go index 1dd9918ed..4bb1fd500 100644 --- a/server/internal/server/server.go +++ b/server/internal/server/server.go @@ -51,6 +51,8 @@ func NewServer() { }) }) + app.HandleDir("/admin", "./admin") + // api mvc.Configure(app.Party("/api"), func(m *mvc.Application) { m.Party("/topic").Handle(new(api.TopicController)) diff --git a/site/nuxt.config.ts b/site/nuxt.config.ts index d8c018556..1ba12d700 100644 --- a/site/nuxt.config.ts +++ b/site/nuxt.config.ts @@ -77,6 +77,9 @@ export default defineNuxtConfig({ '/api/**': { proxy: `${import.meta.env.SERVER_URL}/api/**`, }, + '/admin/**': { + proxy: `${import.meta.env.SERVER_URL}/admin/**`, + }, }, },