-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (47 loc) · 1.62 KB
/
ci-cd.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
name: CI/CD Pipeline
on:
push:
tags:
- 'v1.*.*'
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout Repository
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.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and Push Docker image
uses: docker/build-push-action@v2
with:
file: ./cicd/dockerfiles/insta-bot.Dockerfile
context: .
push: true
tags: haski007/insta-bot:${{ github.ref_name }}
- name: Deploy to Digital Ocean
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
HOST: ${{ secrets.DO_HOST }}
PASS: ${{ secrets.DO_PASSKEY }}
# Add any other environment variables if needed
run: |
# Install SSH client
sudo apt-get update
sudo apt-get install -y openssh-client
# Start SSH agent and add key
eval "$(ssh-agent -s)"
echo "$SSH_PRIVATE_KEY" | ssh-add -
# Disable host key checking (for automation)
ssh-keyscan -H "$HOST" >> ~/.ssh/known_hosts
# SSH into the Digital Ocean server and pull the latest image and restart services
ssh -o 'StrictHostKeyChecking=no' root@$HOST << 'ENDSSH'
cd /path/to/your/app
docker-compose pull
docker-compose up -d
ENDSSH