Backend dev - build and deploy #182
Workflow file for this run
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
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy | |
# More GitHub Actions for Azure: https://github.com/Azure/actions | |
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions | |
# A good guide for Python Azure action: https://azure.github.io/AppService/2020/12/11/cicd-for-python-apps.html | |
# The actual command that runs to initiate our servers on dev/prod isn't shown in the GH action. Instead, go to the following URL, and then click the "General Settings" tab: | |
# Dev: https://portal.azure.com/#@live.johnshopkins.edu/resource/subscriptions/fe24df19-d251-4821-9a6f-f037c93d7e47/resourceGroups/jh-termhub-webapp-rg/providers/Microsoft.Web/sites/termhub/slots/dev/configuration | |
# Prod: https://portal.azure.com/#@live.johnshopkins.edu/resource/subscriptions/fe24df19-d251-4821-9a6f-f037c93d7e47/resourceGroups/JH-TERMHUB-WEBAPP-RG/providers/Microsoft.Web/sites/termhub/configuration | |
name: Backend dev - build and deploy | |
on: | |
# push: | |
# branches: | |
# - develop | |
# pull_request: | |
# types: [opened, synchronize, reopened, closed] | |
# branches: | |
# - main | |
# - develop | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
submodules: true | |
- name: Set up Python version | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.10' | |
- name: Print commit hash & branch for rollbacks & troubleshooting | |
run: | | |
echo "Commit hash: ${{ github.sha }}" | |
echo "Branch: ${{ github.ref }}" | |
- name: 'Create env file' | |
run: | | |
mkdir env | |
echo "${{ secrets.ENV_FILE }}" > env/.env | |
echo "HOSTENV=dev" >> env/.env | |
- name: Create and start virtual environment | |
run: | | |
python3 -m venv venv | |
source venv/bin/activate | |
- name: Git Large File Store | |
run: | | |
git lfs install | |
cd termhub-vocab | |
git lfs pull | |
- name: Install dependencies | |
run: | | |
# Reactivate install upgrades of pip, wheel, &/or setuptools if needed | |
# python -m pip install --upgrade pip | |
# pip install --upgrade wheel | |
# pip install --upgrade setuptools | |
# VS Hub SDK w/ OAuth disabled: https://github.com/jhu-bids/TermHub/issues/863 | |
# TOKEN=$(grep '^PALANTIR_ENCLAVE_AUTHENTICATION_BEARER_TOKEN=' env/.env | cut -d'=' -f2) | |
# python3 -m pip install vshub_sdk --upgrade --extra-index-url "https://:${TOKEN}@unite.nih.gov/artifacts/api/repositories/ri.artifacts.main.repository.9bc9cc56-4b8c-4560-9bfb-fba8ade55246/contents/release/pypi/simple" --extra-index-url "https://:${TOKEN}@unite.nih.gov/artifacts/api/repositories/ri.foundry-sdk-asset-bundle.main.artifacts.repository/contents/release/pypi/simple" | |
pip install -r requirements.txt | |
# todo: optional: run tests | |
# - name: Run tests | |
# run: python -m unittest discover -v | |
# About: https://azure.github.io/AppService/2020/12/11/cicd-for-python-apps.html | |
- name: Upload artifact for deployment jobs | |
uses: actions/upload-artifact@v4 | |
with: | |
name: python-app | |
path: | | |
. | |
!venv/ | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
environment: | |
name: 'Backend: Development' | |
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | |
steps: | |
# About: https://azure.github.io/AppService/2020/12/11/cicd-for-python-apps.html | |
- name: Download artifact from build job | |
uses: actions/download-artifact@v2 | |
with: | |
name: python-app | |
path: . | |
- name: 'Deploy to Azure Web App' | |
uses: azure/webapps-deploy@v2 | |
id: deploy-to-webapp | |
with: | |
app-name: 'termhub' | |
slot-name: 'dev' | |
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_DEV }} |