-
Notifications
You must be signed in to change notification settings - Fork 0
47 lines (39 loc) · 1.32 KB
/
main.yml
File metadata and controls
47 lines (39 loc) · 1.32 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
name: Protocicd Main Pipeline
on:
push:
branches:
- main
env:
IMG_NAME: 'protocicd'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMG_NAME }}:latest
- name: Deploy to VM
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USER }}
password: ${{ secrets.VM_PASS }}
# key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
# Pull the latest image
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ env.IMG_NAME }}:latest
# Stop and remove existing container if it exists
docker stop ${{ env.IMG_NAME }} || true
docker rm ${{ env.IMG_NAME }} || true
# Run the new image
docker run -d --name ${{ env.IMG_NAME }} -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/${{ env.IMG_NAME }}:latest