-
-
Notifications
You must be signed in to change notification settings - Fork 21
53 lines (45 loc) · 1.84 KB
/
ci-cd.yaml
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
name: CI/CD Pipeline
on:
push:
branches: [master]
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
BACKEND_IMAGE_NAME: allchat-backend
FRONTEND_IMAGE_NAME: allchat-frontend
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_KEY }}
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Build and Push Backend Image
run: |
docker build -t ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }} ./server
docker login -u ${{ env.DOCKER_USERNAME }} -p ${{ env.DOCKER_PASSWORD }}
docker push ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }}
- name: Build and Push Frontend Image
run: |
docker build -t ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }} .
docker push ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }}
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Deploy to SSH Host
env:
SSH_KEY: ${{ env.SSH_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
ssh ${{ env.SSH_USER }}@${{ env.SSH_HOST }} '
docker pull ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }}
docker pull ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }}
cd allchat
docker-compose down
docker-compose up -d
'