From 2e217c96cbc23b6048eb5e2dbffa4336d8e84ca6 Mon Sep 17 00:00:00 2001 From: Bartosz Stachowiak Date: Sun, 16 Apr 2023 18:10:15 +0200 Subject: [PATCH] update: new CI/CD workflows for deployment --- .github/workflows/main.yml | 37 --------------- .github/workflows/prod-deploy.yml | 63 +++++++++++++++++++++++++ .github/workflows/staging-deploy.yml | 62 ++++++++++++++++++++++++ .github/workflows/test-pull-request.yml | 35 ++++++++++++++ README.md | 20 ++++++-- 5 files changed, 177 insertions(+), 40 deletions(-) delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/prod-deploy.yml create mode 100644 .github/workflows/staging-deploy.yml create mode 100644 .github/workflows/test-pull-request.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 88e0269e..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: testing workflow - -on: - push: - pull_request: - branches: [ main ] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set up Python 3.10.6 - uses: actions/setup-python@v4 - with: - python-version: 3.10.6 - cache: 'pip' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - export PYTHONPATH=$PYTHONPATH:/home/runner/work/drug-screening/drug-screening/src - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # temporary comment for tests - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pip install pytest - pip install pytest-cov - pytest tests/ diff --git a/.github/workflows/prod-deploy.yml b/.github/workflows/prod-deploy.yml new file mode 100644 index 00000000..dea0089e --- /dev/null +++ b/.github/workflows/prod-deploy.yml @@ -0,0 +1,63 @@ +name: Deploy to Production + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python version + uses: actions/setup-python@v1 + with: + python-version: "3.10" + + - name: Create and start virtual environment + run: | + python -m venv venv + source venv/bin/activate + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Test with pytest + run: | + pip install pytest + pip install pytest-cov + pytest tests/ + + - name: Upload artifact for deployment jobs + uses: actions/upload-artifact@v2 + with: + name: python-app + path: | + . + !venv/ + + deploy: + runs-on: ubuntu-latest + needs: build + concurrency: production + environment: + name: "production" + url: ${{ vars.AZURE_WEBAPP_URL }} + + steps: + - 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: ${{ vars.AZURE_WEBAPP_NAME }} + publish-profile: ${{ secrets.PROD_AZURE_PUBLISH_PROFILE }} diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml new file mode 100644 index 00000000..0618b023 --- /dev/null +++ b/.github/workflows/staging-deploy.yml @@ -0,0 +1,62 @@ +name: Deploy to Staging + +on: + push: + branches: + - develop + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python version + uses: actions/setup-python@v1 + with: + python-version: "3.10" + + - name: Create and start virtual environment + run: | + python -m venv venv + source venv/bin/activate + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Test with pytest + run: | + pip install pytest + pip install pytest-cov + pytest tests/ + + - name: Upload artifact for deployment jobs + uses: actions/upload-artifact@v2 + with: + name: python-app + path: | + . + !venv/ + + deploy: + runs-on: ubuntu-latest + needs: build + concurrency: staging + environment: + name: "staging" + url: ${{ vars.AZURE_WEBAPP_URL }} + + steps: + - 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: ${{ vars.AZURE_WEBAPP_NAME }} + publish-profile: ${{ secrets.STAGING_AZURE_PUBLISH_PROFILE }} diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml new file mode 100644 index 00000000..7a63d7d4 --- /dev/null +++ b/.github/workflows/test-pull-request.yml @@ -0,0 +1,35 @@ +name: Testing Workflow + +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python 3.10.6 + uses: actions/setup-python@v4 + with: + python-version: 3.10.6 + cache: "pip" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + export PYTHONPATH=$PYTHONPATH:/home/runner/work/drug-screening/drug-screening/src + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # temporary comment for tests + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pip install pytest + pip install pytest-cov + pytest tests/ diff --git a/README.md b/README.md index e17f2f63..a4421f5d 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,42 @@ -![testing workflow](https://github.com/zuzg/drug-screening/actions/workflows/main.yml/badge.svg) +![Latest PR Test](https://github.com/zuzg/drug-screening/actions/workflows/test-pull-request.yml/badge.svg) +![Prod Deployment](https://github.com/zuzg/drug-screening/actions/workflows/prod-deploy.yml/badge.svg) +![Staging Deployment](https://github.com/zuzg/drug-screening/actions/workflows/staging-deploy.yml/badge.svg) [![badges-are-fun](https://img.shields.io/badge/badges_are-fun-deeppink.svg)](https://tenor.com/view/excited-ron-swanson-giggle-so-much-fun-gif-14647008) ![fail](https://img.shields.io/badge/unless_they-fail-red.svg) + # drug-screening + ## About + A project examining data from High Throughput Screening center in Poznan. HTS goal is to identify active compounds from hundreds of thousands. + ## Setup + ### Prepare repository + ``` git clone https://github.com/zuzg/drug-screening.git -``` +``` + ``` cd drug-screening ``` + ### Prepare environment + ``` conda env create -f environment.yml ``` + ``` conda activate drug-screening ``` + ### Starting the dashboard To start the dashboard enter the following command in the terminal (active in the root project directory) while the conda environment is active: + ``` python -m dashboard -``` \ No newline at end of file +```