-
Notifications
You must be signed in to change notification settings - Fork 20
61 lines (57 loc) · 2.22 KB
/
main.yml
File metadata and controls
61 lines (57 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: Docker Image Core CI/CD
on:
push:
branches: [main]
env:
IMAGE_NAME: ${{ secrets.DOCKER_REPOSITORY }}
IMAGE_NAME_TAG: ${{ secrets.DOCKER_REPOSITORY }}:v${{ github.run_id }}.${{ github.run_number }}
jobs:
build-net-core:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build .Net Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: dotnet restore
run: dotnet restore ./SwiftCode.BBS.API/SwiftCode.BBS.API.csproj
- name: dotnet publish
run: dotnet publish ./SwiftCode.BBS.API/SwiftCode.BBS.API.csproj --configuration -c Release --no-restore -o ./app
- name: Docker Image
run: ls
- name: Copy DockerFile
run: cp ./Dockerfile ./app
- name: Copy APIxml
run: cp ./SwiftCode.BBS.API/SwiftCode.BBS.API.xml ./app
- name: Copy Modelxml
run: cp ./SwiftCode.BBS.Model/SwiftCode.BBS.Model.xml ./app
- name: Login to registry
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: registry.us-west-1.aliyuncs.com
- name: Build Image
run: docker build -t ${{ env.IMAGE_NAME_TAG }} ./app
- name: Push Image
run: docker push ${{ env.IMAGE_NAME_TAG }}
pull-docker:
needs: [build-net-core]
name: Pull Docker
runs-on: ubuntu-latest
steps:
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.HOST_USERNAME }}
password: ${{ secrets.HOST_PASSWORD }}
port: ${{ secrets.HOST_PORT }}
script: |
docker stop $(docker ps -a | grep ${{ env.IMAGE_NAME }} | awk '{print $1}')
docker rm -f $(docker ps -a | grep ${{ env.IMAGE_NAME }} | awk '{print $1}')
docker rmi -f $(docker images | grep ${{ env.IMAGE_NAME }} | awk '{print $3}')
docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} registry.cn-hangzhou.aliyuncs.com
docker pull ${{ env.IMAGE_NAME_TAG }}
docker run -d -p 8108:80 ${{ env.IMAGE_NAME_TAG }}