Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
* adding dotenv to manage keys for local deploy
* adding deploy_mode to control where to deploy (test branch or prod branch)
* update to readme to reflect the above changes
  • Loading branch information
magnulei committed Oct 23, 2024
1 parent 365f542 commit acec4ac
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 15 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main # Trigger when pushing to main

jobs:
ci:
update-branches:
env:
UV_SYSTEM_PYTHON: true
runs-on: ubuntu-latest
Expand All @@ -20,17 +20,35 @@ jobs:
uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Install yq
run: sudo apt-get update && sudo apt-get install -y yq

- name: Read deployment mode from YAML file
run: |
export MODE=$(cat deploy_mode.yaml | yq '.mode')
echo "mode=$MODE" >> $GITHUB_ENV
- name: Print the deployment mode
run: echo "The deployment mode is ${{ env.mode }}"

- name: Generate requirements.txt with `uv`
run: uv export --no-hashes -o requirements.txt

- name: Generate rsconnect-python manifest.json
run: uvx --from rsconnect-python rsconnect write-manifest shiny . --entrypoint shinylims.app:app

- name: Commit changes and push to deploy branch
- name: Commit and push changes based on mode
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add requirements.txt manifest.json
git commit -m "Update requirements on new commit from main" || echo "No changes to commit"
git push origin --force HEAD:deploy # Push to deploy branch, using force because of diverging branches
git commit -m "Update requirements and manifest" || echo "No changes to commit"
if [ "${{ env.mode }}" == "test" ]; then
git push origin --force HEAD:test_deploy # Push to test branch
elif [ "${{ env.mode }}" == "prod" ]; then
git push origin --force HEAD:deploy # Push to deploy branch
elif [ "${{ env.mode }}" == "both" ]; then
git push origin --force HEAD:test_deploy # Push to test branch
git push origin --force HEAD:deploy # Push to deploy branch
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Ignore cache
__pycache__/
/src/shinylims/__pycache__
*.pyc
*.pyc

# Other
.env
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Shinylims

A Python Shiny app for LIMS reporting.
A Python Shiny app for LIMS reporting hosted on Posit Connect.
This python package is managed with uv (https://docs.astral.sh/uv). To run it, clone the repository and install the package with:

```
Expand All @@ -13,9 +13,8 @@ Then, run the shiny app with:
uv run uvicorn shinylims.app:app
```

Remember to update the manifest before making commits

```
uvx --from rsconnect-python --python .venv/Scripts/python.exe rsconnect write-manifest shiny . --overwrite --entrypoint shinylims.app:app
```
For development:

* Set the deploy mode in deploy_mode.yaml. If set to 'test', any pushes to main will be deployed to the test-deploy shiny app instance on posit connect. Else set the mode to 'prod' to deploy on the production instance or 'both' to update both instances. The idea here is to first implement changes on an instance running on ypu local computer. When confirmed running as expected locally, first push to the test posit instance to confirm that everything also functions on posit. Then change to 'prod' and push again to implement changes to the production instance of the app.
* For local development, the apikey and posit connect url must be provided in a .env file.
* When pushing to main a Github actions pipeline will ensure that manifest and requirement files are created for posit deployment. These files along with any updates to the code are forced pushed to either the production deploy branch or the test_deploy branch depending on the mode set (see above)
6 changes: 6 additions & 0 deletions deploy_mode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Mode options used by the deployment script:
# - prod: for production updates
# - test: for testing updates
# - both: for updating both test and production

mode: test
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ dependencies = [
"itables==2.0.1",
"pandas==2.2.2",
"pins==0.8.5",
"python-dotenv>=1.0.1",
"seaborn==0.13.2",
"shiny==0.9.0",
"shinyswatch==0.6.1",
]

[tool.hatch.build.targets.wheel]
packages = ["src/shinylims"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
9 changes: 7 additions & 2 deletions src/shinylims/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from pins import board_connect
from shiny import ui
import numpy as np

from dotenv import load_dotenv
import os

def transform_to_html(limsid):
if pd.isna(limsid) or limsid == '':
Expand Down Expand Up @@ -36,7 +37,11 @@ def custom_to_datetime(date_series):

def fetch_pinned_data(pin_name):

board = board_connect() # ADD server_url and api_key here for local deployment!
# Load environment variables from .env file
load_dotenv()

board = board_connect(api_key=os.getenv('POSIT_API_KEY'), server_url=os.getenv('POSIT_SERVER_URL'))

df = board.pin_read(pin_name)
if 'Open Date' in df.columns:
df['Open Date'] = pd.to_datetime(df['Open Date'])
Expand Down
13 changes: 12 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit acec4ac

Please sign in to comment.