-
Notifications
You must be signed in to change notification settings - Fork 1
114 lines (101 loc) · 3.82 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Deploys Solana Project to Ubuntu VPS
on:
push:
branches:
- main
jobs:
prepare_environment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Esure target directory exists on VPS
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
if [ ! -d "/dockerized/containers/solana_project" ]; then
mkdir -p /dockerized/containers/solana_project
else
rm -rf /dockerized/containers/solana_project/*
fi
- name: Copy Github files to VPS
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "./"
target: "/dockerized/containers/solana_project"
- name: Create .env file
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cat << EOF > /dockerized/containers/solana_project/.env
NEXT_PUBLIC_TOKEN_OWNER_KEY_PAIR=${{ secrets.NEXT_PUBLIC_TOKEN_OWNER_KEY_PAIR }}
EOF
build_docker_image:
needs: prepare_environment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build Docker image with commit hash
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
export DOCKER_BUILDKIT=1
cd /dockerized/containers/solana_project
docker build -t solana_project_image .
stop_and_start_container:
needs: build_docker_image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Stop and remove old Docker containers
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker stop solana_project_instance || true
docker rm solana_project_instance || true
- name: Run new Docker container
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker run -d --name solana_project_instance --restart unless-stopped -p ${{secrets.PORT}}:3000 -v solana_project_volume:/data solana_project_image
clean_up_except_the_latest:
needs: stop_and_start_container
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Clean up previous Docker images except the latest
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
# Get the latest image ID
latest_image_id=$(docker images 'solana_project_image*' --format "{{.ID}}" | head -n1)
# Remove all images except the latest one
docker images 'solana_project_image*' --format "{{.ID}}" | grep -v "$latest_image_id" | xargs --no-run-if-empty docker rmi
- name: Remove untagged Docker images
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker rmi $(docker images -f "dangling=true" -q) || true