-
Notifications
You must be signed in to change notification settings - Fork 0
39 lines (32 loc) · 1.25 KB
/
production-ci-cd-pipeline.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
name: prod CI/CD pipeline
on:
# pull_request:
# branches: [ main, release/* ]
workflow_dispatch:
inputs:
branch:
description: 'Branch to run the workflow on'
required: true
default: 'main'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
deploy_and_build:
name: Build and deploy
runs-on: ubuntu-latest
environment: staging
steps:
- name: Install ssh keys
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SSH_HOST }} > ~/.ssh/known_hosts
- name: connect, pull and build
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "source ~/.bashrc && cd ${{ secrets.PROD_WORK_DIR }} && git checkout main && git pull && make deploy-prod-dotenv-file && make stop-frontend && make build-frontend && make stop-backend && make build-backend && exit"
- name: cleanup unused containers, images, volumes, and networks
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd ${{ secrets.PROD_WORK_DIR }} && make cleanup-unused-infra && exit"
- name: cleanup
run: rm -rf ~/.ssh