增加gitea的cicd功能
This commit is contained in:
parent
1233a05bd2
commit
55671c9e8b
|
@ -0,0 +1,71 @@
|
|||
name: Docker Deploy
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main # 监听main分支的push事件
|
||||
- v* # 监听v开头的分支push事件
|
||||
tags:
|
||||
- "v*" #监听所有含v开头的push事件
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: runner
|
||||
env:
|
||||
HOST_PORT: 7080
|
||||
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: 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 }}
|
|
@ -0,0 +1,11 @@
|
|||
ARG registry=registry.cn-hangzhou.aliyuncs.com/syschan
|
||||
FROM ${registry}/golang:alpine as builder
|
||||
WORKDIR /app
|
||||
COPY ./server .
|
||||
RUN go generate && source ./bin/start/.env && go build -o ./bin/$appName -v .
|
||||
|
||||
FROM ${registry}/alpine:latest
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/bin/ .
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk add bash && chmod +x ./start/script.sh
|
||||
CMD ["bash","-c","./start/script.sh"]
|
|
@ -0,0 +1,4 @@
|
|||
VERSION=1.0
|
||||
|
||||
#容器中程序名
|
||||
appName=pms-dev
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
source ./start/.env
|
||||
|
||||
#appName=$(ls | head -n 1)
|
||||
|
||||
./$appName
|
Loading…
Reference in New Issue