This commit is contained in:
AaronHux 2024-05-25 15:21:34 +08:00
parent 96a117b084
commit 825730b364
4 changed files with 176 additions and 0 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
node_modules
dist

View File

@ -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

37
Dockerfile Normal file
View File

@ -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 .

64
nginx.conf Normal file
View File

@ -0,0 +1,64 @@
# 设置运行 Nginx 的用户
user nginx;
# 启动的 worker 进程数量,一般设置为 autoNginx 会自动根据 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";
# }
}
}