58 lines
2.1 KiB
YAML
58 lines
2.1 KiB
YAML
name: Egg CI/CD
|
||
on: [push]
|
||
|
||
jobs:
|
||
build-image:
|
||
runs-on: ubuntu-latest
|
||
container: catthehacker/ubuntu:act-latest
|
||
steps:
|
||
- name: Check out repository code
|
||
uses: actions/checkout@v3
|
||
- name: Set up QEMU
|
||
uses: docker/setup-qemu-action@v2
|
||
- name: Set up Docker Buildx
|
||
uses: docker/setup-buildx-action@v2
|
||
- name: Login to Docker Hub
|
||
uses: docker/login-action@v2
|
||
with:
|
||
registry: git.yingbo.im:333
|
||
username: ${{ secrets.DOCKER_USERNAME }}
|
||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||
- name: Build and push
|
||
uses: docker/build-push-action@v4
|
||
with:
|
||
push: true
|
||
tags: git.yingbo.im:333/zhaoyingbo/egg_server:${{ github.sha }}
|
||
|
||
deploy:
|
||
needs: build-image
|
||
runs-on: ubuntu-latest
|
||
container: catthehacker/ubuntu:act-latest
|
||
steps:
|
||
# 检出代码
|
||
- name: Check out repository code
|
||
uses: actions/checkout@v3
|
||
# 使用scp命令将docker-compose.yml文件上传到服务器
|
||
- name: Upload docker-compose.yml to server
|
||
uses: appleboy/scp-action@master
|
||
with:
|
||
host: ${{ secrets.SERVER_HOST }}
|
||
username: ${{ secrets.SERVER_USERNAME }}
|
||
key: ${{ secrets.SERVER_KEY }}
|
||
port: ${{ secrets.SERVER_PORT }}
|
||
source: docker-compose.yml
|
||
target: /home/${{ secrets.SERVER_USERNAME }}/docker/egg_server
|
||
# 登录服务器,执行docker-compose命令
|
||
- name: Login to the server and execute docker-compose command
|
||
uses: appleboy/ssh-action@master
|
||
with:
|
||
host: ${{ secrets.SERVER_HOST }}
|
||
username: ${{ secrets.SERVER_USERNAME }}
|
||
key: ${{ secrets.SERVER_KEY }}
|
||
port: ${{ secrets.SERVER_PORT }}
|
||
script: |
|
||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} git.yingbo.im:333
|
||
cd /home/${{ secrets.SERVER_USERNAME }}/docker/egg_server
|
||
sed -i "s/sha/${{ github.sha }}/g" docker-compose.yml
|
||
docker compose up -d --force-recreate --no-deps egg_server
|