File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # name: Protocicd Main Pipeline
1+ name : Protocicd Main Pipeline
22
3- # on:
4- # push:
5- # branches:
6- # - main
3+ on :
4+ push :
5+ branches :
6+ - main
77
8- # env:
8+ env :
9+ IMG_NAME = protocicd
10+
11+ jobs :
12+ deploy :
13+ runs-on : ubuntu-latest
14+ steps :
15+ - name : Checkout code
16+ uses : actions/checkout@v3
17+
18+ - name : Login to Docker Hub
19+ uses : docker/login-action@v2
20+ with :
21+ username : ${{ secrets.DOCKER_USERNAME }}
22+ password : ${{ secrets.DOCKER_PASSWORD }}
23+
24+ - name : Build and push
25+ uses : docker/build-push-action@v4
26+ with :
27+ context : .
28+ push : true
29+ tags : ${{ secrets.DOCKER_USERNAME }}/$IMG_NAME:latest
30+
31+ - name : Deploy to VM
32+ uses : appleboy/ssh-action@master
33+ with :
34+ host : ${{ secrets.VM_HOST }}
35+ username : ${{ secrets.VM_USER }}
36+ # key: ${{ secrets.SSH_PRIVATE_KEY }}
37+ script : |
38+ # Pull the latest image
39+ sudo docker pull ${{ secrets.DOCKER_USERNAME }}/$IMG_NAME:latest
40+
41+ # Stop and remove existing container if it exists
42+ sudo docker stop my-container || true
43+ sudo docker rm my-container || true
44+
45+ # Run the new image
46+ sudo docker run -d --name my-container ${{ secrets.DOCKER_USERNAME }}/$IMG_NAME:latest
You can’t perform that action at this time.
0 commit comments