prod CI/CD pipeline #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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 |