工作流

This commit is contained in:
hi2hi 2024-12-03 15:31:52 +00:00
parent e2e186329e
commit 7b9d078c5e
3 changed files with 47 additions and 1 deletions

2
.env
View File

@ -1 +1 @@
VITE_VERSION=0.3.0
VITE_VERSION=0.3.0

43
.github/workflows/docker-build.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: Build and Push Docker Image
on:
push:
branches:
- main # 监听 main 分支的 push 操作
workflow_dispatch: # 手动触发
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Get version from package.json
id: get_version
run: echo "VERSION=$(node -p \"require('./package.json').version\")" >> $GITHUB_ENV
- name: Build project
run: npm run build
- name: Build Docker image
run: |
docker build -t ghcr.io/${{ github.repository }}/nazhua:${{ env.VERSION }} .
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push Docker image
run: |
docker push ghcr.io/${{ github.repository }}/nazhua:${{ env.VERSION }}
docker tag ghcr.io/${{ github.repository }}/nazhua:${{ env.VERSION }} ghcr.io/${{ github.repository }}/nazhua:latest
docker push ghcr.io/${{ github.repository }}/nazhua:latest

View File

@ -2,3 +2,6 @@ FROM nginx:1.27.3
COPY ./dist /home/wwwroot/html
COPY ./nginx-default.conf.template /etc/nginx/templates/default.conf.template
# 暴露端口
EXPOSE 80