pms/.gitea/workflows/pms.yaml

82 lines
2.6 KiB
YAML

name: Docker Deploy
on:
workflow_dispatch:
push:
branches:
- main # 监听main分支的push事件
- pms* # 监听v开头的分支push事件
tags:
- "v*" #监听所有含v开头的push事件
jobs:
build-and-deploy:
runs-on: runner
env:
HOST_PORT: 8080
CTN_NAME: "ctn-pms"
IMG_NAME: "${{ github.repository }}:${{ github.ref_name }}"
REMOTE_IMG_NAME: "${{ vars.ALI_REGISTRY }}/${{ github.repository }}:${{ github.ref_name }}"
steps:
- name: install nodejs&golang and set proxy
run: |
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
apk add npm go docker
npm config set registry https://npm.aliyun.com
echo "-----============$REMOTE_IMG_NAME=========--------"
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Checkout Repo
uses: http://${{vars.DOMAIN}}:5678/actions/checkout@v4
- name: Build server
run: |
go env -w GOPROXY=https://goproxy.cn
go generate
go build -o /opt/server -v .
pwd
working-directory: ./server
# - name: Login to Alibaba Cloud Docker Registry
# uses: http://${{vars.DOMAIN}}:5678/docker/login-action@v3
# with:
# registry: ${{ vars.ALI_REGISTRY }}
# username: ${{ secrets.ALI_USER }}
# password: ${{ secrets.ALI_PWD }}
# - name: Remove Container & Image
# run: |
# docker stop $CTN_NAME || true
# docker rm $CTN_NAME || true
# docker rmi $REMOTE_IMG_NAME || true
# - name: Build and Push Docker Image To Alibaba Cloud
# uses: http://${{vars.DOMAIN}}:5678/docker/build-push-action@v6
# with:
# push: true
# context: ./cicd
# dockerfile: Dockerfile
# #tags: ${{ vars.ALI_REGISTRY }}/${{ github.repository }}:${{ github.ref_name }}
# tags: ${{env.REMOTE_IMG_NAME}} #支持env变量
# username: ${{ secrets.ALI_USER }}
# password: ${{ secrets.ALI_PWD }}
# - name: Run On Server
# run: |
# docker run -d --name $CTN_NAME -p $HOST_PORT:8080 $REMOTE_IMG_NAME
# - name: SSH Deploy
# uses: easingthemes/ssh-deploy-action@v2.1.5
# env:
# SSH_PRIVATE_KEY: ${{ vars.SSH_PRIVATE_KEY }}
# ARGS: echo "deploying"
# with:
# source: .
# destination: /app/demo
# host: ${{ vars.HOST }}
# port: 22
# username: ${{ vars.USERNAME }}