This commit is contained in:
shanshanzhong 2025-09-25 04:36:19 -07:00
parent de8761846a
commit e65a2ded46

View File

@ -1,5 +1,5 @@
name: CI
name: Build docker and publish
run-name: The pipeline for docker build
on:
push:
branches:
@ -9,52 +9,66 @@ on:
- cicd
env:
# Docker
REPO: ${{ vars.REPO }}
# Gitea
GIT_USERNAME: ${{ vars.GIT_USERNAME }}
GIT_PASSWORD: ${{ vars.GIT_PASSWORD }}
# Host SSH
SSH_HOST: ${{ vars.SSH_HOST }}
SSH_PORT: ${{ vars.SSH_PORT }}
SSH_USER: ${{ vars.SSH_USER }}
SSH_PASSWORD: ${{ vars.SSH_PASSWORD }}
jobs:
build:
linux:
runs-on: ppanel-web
strategy:
matrix:
# 只有node支持版本号别名
node: ['20.15.1']
# 使用gitea-tool-cache需要指定具体的版本号
go: ["1.24.3"]
steps:
- name: Checkout code
uses: https://shanshanzhong147@gmail.com:shanshanzhong147@git.kxsw.us/actions/checkout
- name: Checkout
uses: https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/actions/checkout@main
- name: change npm registry mirror
run: npm config set registry https://registry.npmmirror.com
### https://github.com/pnpm/action-setup
- name: Set up Node.js
uses: https://shanshanzhong147@gmail.com:shanshanzhong147@git.kxsw.us/actions/action-setup
# 将.env环境变量配置文件拷贝致gitea runner容器
- name: copy env file to runner container
uses: https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/actions/ssh-action@main
with:
version: 9.15.9
run_install: false
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
password: ${{ env.SSH_PASSWORD }}
port: ${{ env.SSH_PORT }}
debug: true
script: |
mkdir -p ~/cicd_env_files
cd ~/cicd_env_files
rm -f ./.env
docker cp ${{ vars.JOB_CONTAINER_NAME }}:${{ github.workspace }}/deploy/.env ./.env
source ./.env
if [ -n "${{ vars.RUNNER_CONTAINER_NAME }}" ]; then
docker cp .env ${{ vars.RUNNER_CONTAINER_NAME }}:/.env
docker exec ${{ vars.RUNNER_CONTAINER_NAME }} /bin/bash -c "source /.env"
else
echo "RUNNER_CONTAINER_NAME is not set, skipping container operations"
fi
- id: tool-cache
uses: https://shanshanzhong147@gmail.com:shanshanzhong147@git.kxsw.us/actions/gitea-tool-cache
- name: Setup Go environment with cache
uses: https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/actions/setup-go@main
with:
# 只有node支持版本号别名
node-version: lts
go-version: ${{ matrix.go }}
cache: true
cache-dependency-path: go.sum
- uses: https://shanshanzhong147@gmail.com:shanshanzhong147@git.kxsw.us/actions/setup-node
with:
# gitea-tool-cache导出 node 具体版本
node-version: ${{ steps.tool-cache.outputs.node-version }}
registry-url: https://registry.npmmirror.com
cache: pnpm
- name: set cavans registry
run: pnpm config set canvas_binary_host_mirror https://registry.npmmirror.com/-/binary/canvas
- name: Install dependencies
run: pnpm install
- name: Run Build Project
run: pnpm run build
- name: Run Build Docker
run: make build
- name: Build and push docker image
run: |
source ${{ gitea.workspace }}/deploy/.env
go mod tidy
make build-linux
make docker
make publish-docker
make docker-run