-
Notifications
You must be signed in to change notification settings - Fork 25
76 lines (66 loc) · 2.21 KB
/
push_image_deploy.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
name: Build and push image
on:
push:
branches:
- master
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and Push Docker Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ghcr.io/cybermouflons/ovisbot:latest
deploy:
needs: build-and-push
runs-on: ubuntu-latest
environment: PROD
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Write Secret to .env File
env:
ENV_FILE: ${{ secrets.ENV_FILE }}
run: |
echo "$ENV_FILE" > .env
echo ".env file created with the contents of ENV_FILE secret"
- name: Set up SSH for Deployment
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
SSH_HOST: ${{ secrets.SSH_HOST }}
run: >
apt-get update && apt-get install -y sshpass
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SSH_HOST" "mkdir -p ~/ovisbot"
- name: Deploy to Server
uses: mai-space/action-sshpass-rsync@v1
with:
host: ${{ secrets.SSH_HOST }}
user: ${{ secrets.SSH_USER }}
port: 22
pass: ${{ secrets.SSH_PASS }}
local: "."
extra: "-avz --exclude '.git'"
remote: "~/ovisbot"
runAfterDeployment: |
cd ~/ovisbot
if [ -f docker-compose.yml ]; then
docker compose -f docker-compose.yml -f docker-compose.prod.yml down || true
docker compose -f docker-compose.yml -f docker-compose.prod.yml pull
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
else
echo "docker-compose.yml not found in the repository!"
exit 1
fi