Skip to content

Merge pull request #61 from pablomarin/main #112

Merge pull request #61 from pablomarin/main

Merge pull request #61 from pablomarin/main #112

# 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
name: GPTSmartSearch Apps Deployment
env:
DO_BUILD_DURING_DEPLOYMENT: true
on:
push:
branches:
- github-actions-apps
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
outputs:
env-name: ${{steps.set-deploy-env.outputs.DEPLOY_ENVIRONMENT}}
steps:
- uses: actions/checkout@v2
- name: Set up Python version
uses: actions/setup-python@v1
with:
python-version: '3.10'
- name: Set environment for branch
id: set-deploy-env
run: |
if [[ $GITHUB_REF_NAME == 'refs/heads/main' ]]; then
echo "DEPLOY_ENVIRONMENT=Development" >> "$GITHUB_OUTPUT"
elif [[ $GITHUB_REF_NAME == 'refs/heads/develop' ]]; then
echo "DEPLOY_ENVIRONMENT=Development" >> "$GITHUB_OUTPUT"
elif [[ $GITHUB_REF_NAME == 'refs/heads/release' ]]; then
echo "DEPLOY_ENVIRONMENT=Development" >> "$GITHUB_OUTPUT"
else
echo "DEPLOY_ENVIRONMENT=Development" >> "$GITHUB_OUTPUT"
fi
- name: merge backend and common folder
run: |
echo "Prepare backend source for enviroment [${{ steps.set-deploy-env.outputs.DEPLOY_ENVIRONMENT }}]"
mkdir -p ./target/backend
cp -r ./apps/backend ./target
cp -r ./common/*.* ./target/backend
- name: Create and start virtual environment in backend folder
if: ${{ !env.DO_BUILD_DURING_DEPLOYMENT }}
run: |
python -m venv ./target/backend/venv
source ./target/backend/venv/bin/activate
- name: Install backend dependencies
if: ${{ !env.DO_BUILD_DURING_DEPLOYMENT }}
run: pip install -r ./target/backend/requirements.txt
- name: merge frontend and common folder
run: |
echo "Prepare frontend source for enviroment [${{ steps.set-deploy-env.outputs.DEPLOY_ENVIRONMENT }}]"
mkdir -p ./target/frontend
cp -r ./apps/frontend ./target
cp -r ./common/*.* ./target/frontend
- name: Create and start virtual environment in frontend folder
if: ${{ !env.DO_BUILD_DURING_DEPLOYMENT }}
run: |
python -m venv ./target/frontend/venv
source ./target/frontend/venv/bin/activate
- name: Install frontend dependencies
if: ${{ !env.DO_BUILD_DURING_DEPLOYMENT }}
run: pip install -r ./target/frontend/requirements.txt
# Optional: Add step to run tests here (PyTest, Django test suites, etc.)
- name: Upload artifacts for backend deployment jobs
uses: actions/upload-artifact@v2
with:
name: python-backend-app
path: |
./target/backend
- name: Upload artifacts for frontend deployment jobs
uses: actions/upload-artifact@v2
with:
name: python-frontend-app
path: |
./target/frontend
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: ${{ needs.build.outputs.env-name}}
url: ${{ steps.deploy-frontend-to-webapp.outputs.webapp-url }}
steps:
- name: Download backend artifact from build job
uses: actions/download-artifact@v2
with:
name: python-backend-app
path: ./backend
- name: 'Deploy backend to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-backend-to-webapp
with:
app-name: ${{ vars.AZURE_WEBAPP_BACKEND_NAME }}
package: ./backend
publish-profile: ${{ secrets.AZUREAPPSERVICE_BACKEND_PUBLISHPROFILE}}
- name: Download frontend artifact from build job
uses: actions/download-artifact@v2
with:
name: python-frontend-app
path: ./frontend
- name: 'Deploy frontend to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-frontend-to-webapp
with:
app-name: ${{ vars.AZURE_WEBAPP_FRONTEND_NAME }}
package: ./frontend
publish-profile: ${{ secrets.AZUREAPPSERVICE_FRONTEND_PUBLISHPROFILE}}