-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (77 loc) · 2.38 KB
/
main.yml
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#name: ci
#
#on:
# push:
# branches:
# - main
#
#jobs:
# build:
#
# runs-on: self-hosted
#
# steps:
# - uses: actions/checkout@v4
# - name: Build the Docker image
# run: docker compose up -d --build
name: Deploy to VPS
on:
push:
branches:
- main
jobs:
build-and-push:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v2
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker images
run: |
docker compose up -d --build
docker compose push
# - name: Deploy to server
# env:
# host: ${{ secrets.SERVER_HOST }}
# username: ${{ secrets.SERVER_USER }}
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
# script: |
# sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no $USERNAME@$HOST '
# docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} &&
#
# mkdir -p /path/to/your/deployment
# cd /path/to/your/deployment
# docker-compose pull
# docker-compose up -d
# '
- name: copy file via ssh key
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
port: 22
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "docker-compose.yml,.env"
target: 'project' #path project
- name: Deploy to server
env:
HOST: ${{ secrets.SERVER_HOST }}
USERNAME: ${{ secrets.SERVER_USER }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
echo "${SSH_PRIVATE_KEY}" > ssh_key
chmod -R 600 ssh_key
ssh -i ssh_key -o StrictHostKeyChecking=no $USERNAME@$HOST '
docker login --username ${{ secrets.DOCKER_USERNAME }} --password-stdin ${{ secrets.DOCKER_PASSWORD }} &&
pwd
cd project
pwd
docker compose pull &&
docker compose up -d --build
'