Skip to content

Commit

Permalink
build: upgrade FOCA (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
uniqueg authored Nov 2, 2023
1 parent ca10d61 commit fe8271a
Show file tree
Hide file tree
Showing 17 changed files with 284 additions and 247 deletions.
109 changes: 76 additions & 33 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,86 @@
---
name: Test with docker compose
name: proWES checks

on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]


jobs:
build:
lint:
name: Run linting
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install requirements
run: |
pip install -r requirements_dev.txt
pip install .
- name: Lint with Flake8
run: flake8
test:
name: Run tests
runs-on: ubuntu-latest
env:
PROBE_ENDPOINT: localhost:8080/ga4gh/wes/v1/ui/
strategy:
fail-fast: true
matrix:
python-version: ["3.7", "3.8","3.9", "3.10"]

PROBE_ENDPOINT: localhost:8090/ga4gh/wes/v1/service-info
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: pip install docker-compose
- name: Create data directories
run: mkdir -p ${HOME}/data/{db,output,tmp}
- name: Docker compose up
run: docker-compose up -d
- name: Sleep 30
run: sleep 30
- name: PROBE
run: echo "${PROBE_ENDPOINT}"
- name: Test
run: |
test $( \
curl \
-sL \
-v \
-o /dev/null \
-w '%{http_code}' \
-X GET \
--header 'Accept: application/json' \
"${PROBE_ENDPOINT}" \
) == '200' || exit 1
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Deploy app
run: docker-compose up -d --build
- name: Wait for app startup
run: sleep 20
- name: Probe endpoint
run: |
test $( \
curl \
-sL \
-v \
-o /dev/null \
-w '%{http_code}' \
-X GET \
--header 'Accept: application/json' \
"${PROBE_ENDPOINT}" \
) == '200' || exit 1
publish:
name: Build and publish app image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
needs: [lint, test]
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Generate tag
run: |
echo "TAG=$(date '+%Y%m%d')" >> $GITHUB_ENV
- name: Build and publish image
id: docker
uses: philips-software/[email protected]
with:
dockerfile: .
image-name: "prowes"
tags: "latest ${{ env.TAG }}"
push-branches: "${{ github.event.repository.default_branch }}"
env:
REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_LOGIN }}
REGISTRY_TOKEN: "${{ secrets.DOCKERHUB_TOKEN }}"
DOCKER_ORGANIZATION: ${{ secrets.DOCKERHUB_ORG }}
GITHUB_ORGANIZATION: ${{ github.repository_owner }}
- name: Verify that image was pushed
run: |
echo "Push indicator: ${{ steps.docker.outputs.push-indicator }}"
echo "# Set to 'true' if image was pushed, empty string otherwise"
test "${{ steps.docker.outputs.push-indicator }}" == "true"
41 changes: 11 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,24 @@
##### BASE IMAGE #####
FROM elixircloud/foca:20220524-py3.7
FROM elixircloud/foca:20230818-py3.10

##### METADATA #####
LABEL base.image="elixircloud/foca:20220524-py3.7"
LABEL version="2.0"
LABEL version="3.0"
LABEL software="proWES"
LABEL software.version="0.15.0"
LABEL software.description="Flask microservice implementing the Global Alliance for Genomics and Health (GA4GH) Workflow Execution Service (WES) API specification."
LABEL software.description="Flask microservice implementing the Global Alliance for Genomics and Health (GA4GH) Workflow Execution Service (WES) API specification as a proxy for middleware injection (e.g., workflow distribution logic)."
LABEL software.website="https://github.com/elixir-europe/proWES"
LABEL software.documentation="https://github.com/elixir-europe/proWES"
LABEL software.license="https://github.com/elixir-europe/proWES/blob/master/LICENSE"
LABEL software.tags="General"
LABEL maintainer="[email protected]"
LABEL maintainer.organisation="Biozentrum, University of Basel"
LABEL maintainer.location="Klingelbergstrasse 50/70, CH-4056 Basel, Switzerland"
LABEL maintainer.lab="ELIXIR Cloud & AAI"
LABEL maintainer.license="https://spdx.org/licenses/Apache-2.0"
LABEL software.license="https://spdx.org/licenses/Apache-2.0"
LABEL maintainer="[email protected]"
LABEL maintainer.organisation="ELIXIR Cloud & AAI"

# Python UserID workaround for OpenShift/K8S
ENV LOGNAME=ipython
ENV USER=ipython

## Set working directory
WORKDIR /app
COPY ./ .
RUN pip install -e .

## Copy Python requirements
COPY ./requirements.txt /app/requirements.txt
COPY ./requirements_dev.txt /app/requirements_dev.txt

## Install Python dependencies
RUN cd /app \
&& pip install -r requirements.txt \
&& pip install -r requirements_dev.txt \
&& cd /

## Copy remaining app files
COPY ./ /app

## Install app
RUN cd /app \
&& python setup.py develop \
&& cd /
## Add permissions for storing updated API specification
## (required by FOCA)
RUN chmod -R a+rwx /app/pro_wes/api
5 changes: 1 addition & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
links:
- mongodb
- rabbitmq
command: bash -c "cd /app/pro_wes; celery -A worker worker -E --loglevel=info"
command: bash -c "cd /app/pro_wes; celery -A celery_worker worker -E --loglevel=info"
volumes:
- ${PROWES_DATA_DIR:-../data/pro_wes}:/data

Expand All @@ -23,8 +23,6 @@ services:
links:
- mongodb
command: bash -c "cd /app/pro_wes; gunicorn -c gunicorn.py wsgi:app"
volumes:
- ${PROWES_DATA_DIR:-../data/pro_wes}:/data
ports:
- "8090:8080"

Expand Down Expand Up @@ -53,4 +51,3 @@ services:
command: flower --broker=amqp://guest:guest@rabbitmq:5672// --port=5555
ports:
- "5565:5555"

2 changes: 1 addition & 1 deletion pro_wes/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.17.0'
"""proWES app package root."""
4 changes: 2 additions & 2 deletions pro_wes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def init_app() -> App:
foca = Foca(
config_file=Path(__file__).resolve().parent / "config.yaml",
custom_config_model='pro_wes.config_models.CustomConfig',
custom_config_model="pro_wes.config_models.CustomConfig",
)
app = foca.create_app()
with app.app.app_context():
Expand All @@ -31,6 +31,6 @@ def run_app(app: App) -> None:
app.run(port=app.port)


if __name__ == '__main__':
if __name__ == "__main__":
app = init_app()
run_app(app)
12 changes: 12 additions & 0 deletions pro_wes/celery_worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Celery worker entry point."""

from pathlib import Path

from celery import Celery
from foca import Foca # type: ignore

foca = Foca(
config_file=Path(__file__).resolve().parent / "config.yaml",
custom_config_model="pro_wes.config_models.CustomConfig",
)
celery: Celery = foca.create_celery_app()
15 changes: 7 additions & 8 deletions pro_wes/client_wes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)


class WesClient():
class WesClient:
"""Client to communicate with GA4GH WES API.
Arguments:
Expand All @@ -39,6 +39,7 @@ class WesClient():
token: Bearer token for gaining access to WES endpoints.
session: Client server session.
"""

def __init__(
self,
host: str,
Expand Down Expand Up @@ -123,9 +124,7 @@ def post_run(
try:
RunRequest(**form_data)
except Exception as exc:
raise ValueError(
f"invalid form data: {form_data}"
) from exc
raise ValueError(f"invalid form data: {form_data}") from exc
try:
response_unvalidated = self.session.post(
url,
Expand Down Expand Up @@ -320,7 +319,7 @@ def set_token(

def set_headers(
self,
content_accept: str = 'application/json',
content_accept: str = "application/json",
content_type: Optional[str] = None,
) -> None:
"""Set session headers.
Expand All @@ -330,8 +329,8 @@ def set_headers(
content_type: Type of content sent with the request.
"""
headers = {}
headers['Accept'] = content_accept
headers["Accept"] = content_accept
if content_type is not None:
headers['Content-Type'] = content_type
headers['Authorization'] = f"Bearer {self.token}"
headers["Content-Type"] = content_type
headers["Authorization"] = f"Bearer {self.token}"
self.session.headers.update(headers)
Loading

0 comments on commit fe8271a

Please sign in to comment.