From 825730b364cf706beb23c7459edfbba019a3c7d3 Mon Sep 17 00:00:00 2001 From: AaronHux Date: Sat, 25 May 2024 15:21:34 +0800 Subject: [PATCH] init --- .dockerignore | 2 + .gitea/workflows/action.yaml | 73 ++++++++++++++++++++++++++++++++++++ Dockerfile | 37 ++++++++++++++++++ nginx.conf | 64 +++++++++++++++++++++++++++++++ 4 files changed, 176 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/action.yaml create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f06235c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/.gitea/workflows/action.yaml b/.gitea/workflows/action.yaml new file mode 100644 index 0000000..3ee0fc3 --- /dev/null +++ b/.gitea/workflows/action.yaml @@ -0,0 +1,73 @@ +name: Gitea Actions Demo +run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 +on: [push] + +jobs: + Explore-Gitea-Actions: + runs-on: linux_centos + # container: catthehacker/ubuntu:act-latest + # container: + # image: ghcr.nju.edu.cn/catthehacker/ubuntu:act-latest + # volumes: + # - /run/docker.sock:/run/docker.sock + # env: + # DOCKER_ORG: gitea + # DOCKER_LATEST: latest + steps: + - name: Build & Deploy + run: | + cd /opt/workspace/TOPVERSE_Official + git pull + docker build -t website-v1:latest "." + docker stop website-v1 || true + docker rm -f website-v1 || true + docker run -d -p 19555:80 --restart=unless-stopped --name website-v1 website-v1 + docker rmi $(docker images -f "dangling=true" -q) || true + docker ps + + # - name: Build + # run: + + # - name: Deploy + # run: | + + # - name: Checkout + # uses: actions/checkout@v4 + # with: + # fetch-depth: 0 # all history for all branches and tags + + # - name: Set up QEMU + # uses: docker/setup-qemu-action@v3 + + # - name: Set up Docker BuildX + # uses: docker/setup-buildx-action@v3 + + # - name: Login to DockerHub + # uses: docker/login-action@v3 + # with: + # username: ${{ secrets.DOCKER_USERNAME }} + # password: ${{ secrets.DOCKER_PASSWORD }} + + # - name: Get Meta + # id: meta + # run: | + # echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT + # echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT + + # - name: Build and push + # uses: docker/build-push-action@v5 + # with: + # context: . + # file: ./Dockerfile + # platforms: | + # linux/amd64 + # linux/arm64 + # push: true + # tags: | + # ${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }} + + # - run: docker build -t website-v1:latest "." + # - run: docker rm -f website-v1 || true + # - run: docker run -d -p 19555:80 --restart=unless-stopped --name website-v1 website-v1 + # - run: docker rmi $(docker images -f "dangling=true" -q) || true + # - run: docker ps diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..676bca9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM node:21 AS build +# 容器内的目录,通常我们会使用 app 目录 +WORKDIR /app +# 拷贝项目文件到容器/app下 +COPY . . + +# ARG env_file + + +RUN npm config set registry https://registry.npmmirror.com +RUN npm install -g pnpm +RUN pnpm config set registry https://registry.npmmirror.com +# 下载编译 +RUN pnpm i +RUN pnpm build +RUN pnpm generate +# RUN yarn config set registry https://registry.npmmirror.com +# RUN yarn +# RUN yarn build +# RUN yarn generate + + + +# nginx默认暴露80端口 +FROM nginx + +# 更换工作目录到nginx服务目录下 +WORKDIR /usr/share/nginx/html + +# 删除服务下可能存在的无用项目 +RUN rm -rf ./* + +# 复制自定义的 Nginx 配置文件 +COPY nginx.conf /etc/nginx/nginx.conf + +# 拷贝打包的文件 +COPY --from=build /app/dist . diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..1de40ac --- /dev/null +++ b/nginx.conf @@ -0,0 +1,64 @@ +# 设置运行 Nginx 的用户 +user nginx; + +# 启动的 worker 进程数量,一般设置为 auto,Nginx 会自动根据 CPU 数量设置合适的数量 +worker_processes auto; + +# 错误日志路径和级别 +error_log /var/log/nginx/error.log warn; + +# PID 文件路径 +pid /var/run/nginx.pid; + +# 定义全局事件 +events { + # 最大连接数 + worker_connections 1024; +} + +# 定义 HTTP 服务器 +http { + # 包含 MIME 类型的文件 + include /etc/nginx/mime.types; + # 默认 MIME 类型 + default_type application/octet-stream; + + # 自定义的 Nginx 配置 + server { + # 监听的端口 + listen 80; + # 服务器名称 + server_name localhost; + + location / { + # 网站根目录,此处使用容器内的路径 + root /usr/share/nginx/html; + # 默认首页 + index index.html; + # 尝试从磁盘找到请求的文件,如果不存在则跳转到 index.html + try_files $uri $uri/ /index.html; + } + + # location ^~ /api/ { + # 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-NginX-Proxy true; + # #下面两个必须设置,请求头设置为ws请求方式 + # proxy_set_header Upgrade $http_upgrade; + # proxy_set_header Connection "upgrade"; + # proxy_pass http://192.168.41.101:28003/; + # } + + # location /api/login/ { + # # rewrite ^/wsUrl/(.*)$ /$1 break; #拦截标识去除 + # proxy_pass http://192.168.41.101:28003/; #这里是http不是ws,不用怀疑,代理的ip和port写ws访问的实际地址 + # proxy_http_version 1.1; #这里必须使用http 1.1 + # #下面两个必须设置,请求头设置为ws请求方式 + # proxy_set_header Upgrade $http_upgrade; + # proxy_set_header Connection "upgrade"; + # } + + } +} + \ No newline at end of file