-
Notifications
You must be signed in to change notification settings - Fork 2
45 lines (38 loc) · 1.55 KB
/
deploy-be.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
name: Deploy Backend
on:
push:
branches:
- develop
paths:
- 'backend/src/**'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to NCP Container Registry
run: |
set +x
echo "${{ secrets.NCP_SECRET_KEY }}" | docker login -u "${{ secrets.NCP_ACCESS_KEY }}" https://${{ secrets.NCP_REGISTRY_URL }} --password-stdin
- name: Build Docker Image
run: |
cd ${{ github.workspace }}/backend
echo "${{ secrets.DOT_ENV_PROD }}" >> .env.prod
docker build -t ${{ secrets.NCP_REGISTRY_URL }}/${{ secrets.DOCKER_IMAGE_NAME }} .
- name: Push Docker Image to NCP Container Registry
run: |
docker push ${{ secrets.NCP_REGISTRY_URL }}/${{ secrets.DOCKER_IMAGE_NAME }}
- name: Log out from Docker Registry
run: docker logout https://${{ secrets.NCP_REGISTRY_URL }}
- name: SSH and deploy backend
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.NCP_SERVER_USER }}@${{ secrets.NCP_SERVER_HOST }} \
"export NCP_ACCESS_KEY=${{ secrets.NCP_ACCESS_KEY }} \
NCP_SECRET_KEY=${{ secrets.NCP_SECRET_KEY }} \
NCP_REGISTRY_URL=${{ secrets.NCP_REGISTRY_URL }} \
DOCKER_IMAGE_NAME=${{ secrets.DOCKER_IMAGE_NAME }} && \
/home/${{ secrets.NCP_SERVER_USER }}/deploy-backend.sh"