Build & Deploy (manually) #15
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: Build & Deploy (manually) | |
on: | |
workflow_dispatch: | |
inputs: | |
branch: | |
description: 'Branch to (re)deploy from' | |
required: true | |
default: 'development' | |
type: choice | |
options: | |
- main | |
- development | |
- release/0.6.6 | |
- release/0.6.7 | |
- release/0.6.8 | |
environment: | |
description: 'Environment to (re)deploy to' | |
type: environment | |
default: 'development' | |
required: true | |
jobs: | |
build_frontend: | |
name: build frontend | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ inputs.branch }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
- name: Install npm packages | |
run: | | |
cd frontend | |
npm install | |
- name: Build & bundle | |
run: | | |
cd frontend | |
unset CI # ignore React warnings | |
npm run build | |
build_backend: | |
name: build backend | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ inputs.branch }} | |
- name: Fetch submodules | |
run: | | |
cd backend | |
cd apps | |
git submodule update --init --recursive | |
git submodule update --remote | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.11 | |
- name: Create venv | |
run: | | |
cd backend | |
python3.11 -m venv venv | |
- name: Install packages | |
run: | | |
cd backend | |
source venv/bin/activate | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Install ifcopenshell package (temp) | |
run: | | |
cd backend | |
source venv/bin/activate | |
# use version of ifcopenshell with desired schema parsing | |
# TODO: revert to pyPI when schema parsing is published in the future | |
wget -O /tmp/ifcopenshell_python.zip "https://s3.amazonaws.com/ifcopenshell-builds/ifcopenshell-python-311-v0.8.1-92b63a0-linux64.zip" | |
mkdir -p venv/lib/python3.11/site-packages | |
unzip -d venv/lib/python3.11/site-packages /tmp/ifcopenshell_python.zip | |
- name: Check Django config | |
run: | | |
cd backend | |
source venv/bin/activate | |
python3 manage.py check | |
- name: Run tests | |
run: | | |
cd backend | |
source venv/bin/activate | |
python3 manage.py test | |
deploy: | |
name: deploy to server (${{ inputs.environment }}) | |
needs: [build_frontend, build_backend] | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ inputs.environment }} | |
steps: | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/ssh_host.key | |
chmod 600 ~/.ssh/ssh_host.key | |
cat >>~/.ssh/config <<END | |
Host ssh_host | |
HostName $SSH_HOST | |
User $SSH_USER | |
IdentityFile ~/.ssh/ssh_host.key | |
StrictHostKeyChecking no | |
END | |
env: | |
SSH_USER: ${{ secrets.SSH_USERNAME }} | |
SSH_KEY: ${{ secrets.SSH_PRIV_KEY }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
- name: Stop Docker containers | |
run: | | |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }} | |
sudo make stop' | |
- name: Fetch sources & submodules | |
run: | | |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }} | |
git checkout -q ${{ inputs.branch }} && git pull | |
sudo make fetch-modules' | |
- name: Checkout correct branches | |
run: | | |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }} | |
cd ${{ vars.REPO_CLONE_PATH }}/backend/apps/ifc_validation/checks/ifc_gherkin_rules && git checkout -q ${{ inputs.branch }} && git pull | |
cd ./ifc_validation_models && git checkout -q ${{ inputs.branch }} && git pull | |
cd ${{ vars.REPO_CLONE_PATH }}/backend/apps/ifc_validation/checks/step_file_parser && git checkout -q master && git pull | |
cd ${{ vars.REPO_CLONE_PATH }}/backend/apps/ifc_validation_models && git checkout -q ${{ inputs.branch }} && git pull | |
cd ${{ vars.REPO_CLONE_PATH }} | |
./check-submodules.sh' | |
- name: Show repo & git status | |
run: | | |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }} | |
echo "*** Validate repository" | |
git remote get-url origin && git rev-parse --abbrev-ref HEAD && git rev-parse --short HEAD | |
echo "*** git status" | |
git status' | |
- name: Show submodule status | |
run: | | |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }} && \ | |
./check-submodules.sh' | |
- name: Set VERSION | |
run: | | |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }} | |
COMMIT_HASH=$(git rev-parse --short HEAD) | |
VERSION="${{ vars.VERSION }}" | |
echo "Set VERSION to ${VERSION}" | |
echo "Set COMMIT_HASH to ${COMMIT_HASH}" | |
echo "${VERSION}" > .VERSION' | |
- name: Build Docker images | |
run: | | |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }} | |
sudo make rebuild' | |
- name: Start Docker containers | |
run: | | |
ssh ssh_host 'cd ${{ vars.REPO_CLONE_PATH }} | |
sudo docker compose -f ${{ vars.DOCKER_COMPOSE_FILE }} --env-file ${{ vars.ENV_FILE }} up -d' |