-
-
Notifications
You must be signed in to change notification settings - Fork 21
89 lines (75 loc) · 3.14 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
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
name: CI/CD Pipeline
on:
push:
branches: [main]
workflow_dispatch:
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: copy file via ssh
uses: garygrossgarten/github-action-scp@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
privateKey: ${{ secrets.SSH_KEY }}
local: "docker-compose.yml"
remote: "allchat/docker-compose.yml"
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test
- name: Build and Push Backend Image
if: success()
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 }}
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Build and Push Backend Image (arm64)
# run: |
# docker buildx build \
# --platform linux/arm64 \
# --output "type=image,push=true" \
# --tag ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }}:arm64 \
# ./server
# - name: Build and Push Frontend Image (arm64)
# run: |
# docker buildx build \
# --platform linux/arm64/v8 \
# --output "type=image,push=true" \
# --tag ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }}:arm64 \
# .
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
'