Skip to content

Commit fab1d76

Browse files
authored
feat: create deploy to server gh action (#196)
we want to deploy on "prod" (server) in easy way without git pulling and reruning on server if you want to deploy on server, you must create new github release
1 parent 0c11857 commit fab1d76

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Deploy
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
timeout-minutes: 60
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
15+
- name: Deploy to server and build
16+
uses: appleboy/ssh-action@master
17+
with:
18+
host: ${{ secrets.SSH_HOST }}
19+
username: ${{ secrets.SSH_USER }}
20+
password: ${{ secrets.SSH_PASSWORD }}
21+
command_timeout: "30m"
22+
script: |
23+
mkdir -p ~/frege-app
24+
25+
rm -rf ~/frege-app/repo
26+
mkdir -p ~/frege-app/repo
27+
28+
cat > ~/frege-app/.env << EOL
29+
GITLAB_TOKEN=${{ secrets.GITLAB_TOKEN }}
30+
EOL
31+
32+
- name: Copy repository to server
33+
uses: appleboy/scp-action@master
34+
with:
35+
host: ${{ secrets.SSH_HOST }}
36+
username: ${{ secrets.SSH_USER }}
37+
password: ${{ secrets.SSH_PASSWORD }}
38+
source: "./"
39+
target: "~/frege-app/repo"
40+
rm: false
41+
strip_components: 0
42+
43+
- name: Build and run on server
44+
uses: appleboy/ssh-action@master
45+
with:
46+
host: ${{ secrets.SSH_HOST }}
47+
username: ${{ secrets.SSH_USER }}
48+
password: ${{ secrets.SSH_PASSWORD }}
49+
command_timeout: "45m"
50+
script: |
51+
cd ~/frege-app/repo
52+
53+
cp .env.template .env
54+
55+
docker compose --profile prod down
56+
docker compose --profile prod up --build -d
57+
58+
docker compose --profile prod ps
59+
60+
echo "Container logs (last 50 lines):"
61+
docker compose --profile prod logs --tail=50
62+
63+
if [ $(docker compose --profile prod ps --status running | grep -v "NAME" | wc -l) -lt 1 ]; then
64+
echo "Warning: Not all containers are running, but proceeding with deployment."
65+
else
66+
echo "All containers started successfully."
67+
fi
68+
69+
echo "Deployment completed"

0 commit comments

Comments
 (0)