Skip to content

Commit

Permalink
Merge branch 'dev' into 'master'
Browse files Browse the repository at this point in the history
Release/0.0.0: Make deployable

See merge request windenergie-hsr/aerosense/digital-twin/fsi-twins/panel-codes-twine!2
  • Loading branch information
cortadocodes committed May 3, 2021
2 parents 5635a46 + 9a0aa56 commit 71de74f
Show file tree
Hide file tree
Showing 30 changed files with 1,051 additions and 334 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv/
.git
*.egg-info
21 changes: 21 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
default:
image: python:3.6

build_and_test:
variables:
TEST_PROJECT_NAME: $TEST_PROJECT_NAME
GOOGLE_APPLICATION_CREDENTIALS: $GOOGLE_APPLICATION_CREDENTIALS
cache:
paths:
- requirements-dev.txt
when: 'on_success'
key: 'build_and_test'
script:
- apt-get update -y && apt-get install -y --fix-missing build-essential gfortran
- python3 -m venv test-venv
- bash test-venv/bin/activate
- git clone https://github.com/daniel-de-vries/xfoil-python.git && pip install ./xfoil-python
- pip install -r requirements-dev.txt
- coverage run -m unittest
- coverage report
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# xfoil-python only seems to work on python 3.6.
FROM python:3.6-slim-buster

# Allow statements and log messages to immediately appear in the Knative logs on Google Cloud.
ENV PYTHONUNBUFFERED True

ENV PROJECT_ROOT=/app
WORKDIR $PROJECT_ROOT

RUN apt-get update -y && apt-get install -y --fix-missing build-essential gfortran git && rm -rf /var/lib/apt/lists/*

# xfoil-python has to be installed locally from a clone (and only seems to work on python 3.6).
RUN git clone https://github.com/daniel-de-vries/xfoil-python.git && pip install ./xfoil-python

COPY requirements-dev.txt .
COPY setup.py .
COPY . .

RUN pip install --upgrade pip && pip install -r requirements-dev.txt

EXPOSE $PORT

ARG _SERVICE_ID
ENV SERVICE_ID=$_SERVICE_ID

ARG _GUNICORN_WORKERS=1
ENV _GUNICORN_WORKERS=$_GUNICORN_WORKERS

ARG _GUNICORN_THREADS=8
ENV _GUNICORN_THREADS=$_GUNICORN_THREADS

# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers $_GUNICORN_WORKERS --threads $_GUNICORN_THREADS --timeout 0 octue.cloud.deployment.google.cloud_run:app
104 changes: 9 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,107 +1,21 @@
# panel-code-twine-python
A simple twine that runs panel codes. This repository is mirrored to Google Cloud Source Repositories.

## Creating a twine

First, think about:
- what data you want to flow into and out of the app
- what kinds of datasets (groups of files) the app might need to access
- what other applicaitons / twins ('children') you need to use
- what credentials you might need (e.g. if you're accessing a database or a third party API

The **twine** file secifies all these things and more. First, place an empty `twine.json` file in the root directory of the app.

See [https://twined.readthedocs.io](https://twined.readthedocs.io) for everything there is to know about how to define a twine. If you log in to [octue.com](https://www.octue.com/login) you'll find tools to help you build the twine.
### Building documents manually

*Note: this example app is not up to date with the current version of twined! Follow or comment on [this issue](https://github.com/octue/octue-app-python/issues/1).*
**If you did need to build the documentation**


## First steps in development
Install `doxgen`. On a mac, that's `brew install doxygen`; other systems may differ.

If you've not developed python applications before, we strongly recommend the following practices:

- Use an Integrated Development Environment (IDE) to help you. We recommend [Pycharm, by Jetbrains](https://www.jetbrains.com/pycharm/) because it's cross-platform (i.e. for Windows, Mac and Linux), very friendly, and there's a free "Community Edition" which should have all the features you need for now.
- Ensure Python 3.5 or greater is installed. (Mac users: use [pyenv](https://github.com/pyenv/pyenv), windows users could try [pyenv-win](https://github.com/pyenv-win/pyenv-win))
- [Configure a Virtual Environment](https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html) to ensure you always have a consistent python environment and packages installed.

Once you've set yourself up with Python 3.7+, an IDE and an activated virtual environment, you're ready to go:

- PyCharm will usually do this for you, but if not, install the project dependencies (see `requirements.txt`).
- Set up a directory containing your input data. How to do this is covered below, in 'Data Directories'.

### Running your app (whilst developing)

`>> python app.py`. Simple as that. You can specify a


### Connecting to the octue platform

1. Log in to [octue.com](www.octue.com), click `applications > create` in the sidebar, and follow the wizard. Simples!


## Data directories

Octue uses a strict folder structure, to help separate input, output, and temporary data. The structure looks like this:
Install sphinx and other requirements for building the docs:
```
my_data_folder
|
|- input
| |
| |- config.json
| |- manifest.json
| |- <dataset_xx>
| | |
| | |- <file_xxx>
| | |- <file_xxy>
| | |- <file_xxz>
| | |- ...
| |
| |- <dataset_xy>
| | |
| | |- <file_xyx>
| | |- <file_xyy>
| | |- <file_xyz>
| | |- ...
| |
| |- ...
|
|- logs
| |
| |- ...
|
|- tmp
| |
| |- ...
|
|- output
| |
| |- ...
pip install -r docs/requirements.txt
```

- Folder **`input`** contains any input datasets (groups of files). Within each dataset - you can simply dump a load of files created by an instrument or supplied by a third party here. These files should never be altered by the application.
- Folder **`logs`** will contain log files produced while running the application. You shouldn't need to use these, as all output will be shown either in your terminal or on octue online.
- Folder **`tmp`** you can write any temporary files (e.g. large cached calculations that are reused but don't form part of the results) here.
- Folder **`output`** all output files should be saved to this directory. Any output files (like figures) produced by octue are saved here too.

- File **``input/manifest.json``** contains a list of all the files in the input directory, with any tags that are applied (see 'generating the manifest file', below)..
- File **``input/config.json``** contains a list of options and configuration parameters to use when running the application (see 'generating the config file', below).


### Generating the config and manifest files

When a user (you, or someone else) launches an application on octue, they fill in a form (which is generated from the twine). That creates a
`config.json` file automatically. You can download this for local development.

Connecting datasets to the application creates the `manifest.json`, which you can download too.

But, if you're just testing your own application out, its helpful to generate these files yourself.

The `octue_app_python` repository contains a `schema.json` for the example application.
Go to [the octue schema playground](https://www.octue.com/schema/playground), and paste the entire contents of
`schema.json` into the top left box.

Fill in the form (it's already populated with defaults) and you'll see your **config** change as you do, in the bottom
right box. This is what gets pasted into `config.json` (see `octue_app_python/example_data/config.json`).

You can play around with schema in that playground (if you're having trouble, use the excellent
[JSON Editor Online](https://jsoneditoronline.org/) to help debug them if you run into trouble.
Run the build process:
```
sphinx-build -b html docs/source docs/build
```
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import xfoil_module

REPOSITORY_ROOT = os.path.abspath(os.path.dirname(__file__))

def run(analysis):
"""
Expand Down
47 changes: 47 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
steps:
- name: gcr.io/cloud-builders/docker
args:
- build
- '--no-cache'
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- --build-arg
- _SERVICE_ID=$_SERVICE_ID
- .
- '-f'
- Dockerfile
id: Build
- name: gcr.io/cloud-builders/docker
args:
- push
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
id: Push
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
args:
- run
- services
- update
- $_SERVICE_NAME
- '--platform=managed'
- '--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- >-
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID,$_LABELS
- '--region=$_DEPLOY_REGION'
- '--quiet'
id: Deploy
entrypoint: gcloud
images:
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
options:
substitutionOption: ALLOW_LOOSE
substitutions:
_GCR_HOSTNAME: eu.gcr.io
_PLATFORM: managed
_SERVICE_NAME: panel-codes-twine
_LABELS: gcb-trigger-id=c11b2517-2b8b-435b-9a30-8213e322851b
_TRIGGER_ID: c11b2517-2b8b-435b-9a30-8213e322851b
_DEPLOY_REGION: europe-north1
tags:
- gcp-cloud-build-deploy-cloud-run
- gcp-cloud-build-deploy-cloud-run-managed
- panel-codes-twine
13 changes: 8 additions & 5 deletions data/input/manifest.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
{
"id": "8ead7669-8162-4f64-8cd5-4abe92509e17",
"keys": {"aerofoil_shape_data": 0},
"type" : "dataset",
"datasets": [
{
"id": "7ead7669-8162-4f64-8cd5-4abe92509e18",
"name": "aerofoil_shape_data",
"tags": "naca_0012",
"tags": ["series:naca"],
"files": [
{
"path": "input/datasets/aerofoil_shape_file/naca_2412.dat",
"path": "naca_2412.dat",
"cluster": 0,
"sequence": 0,
"extension": "dat",
"tags": "",
"tags": ["name:naca-2412"],
"timestamp": 0,
"id": "abff07bc-7c19-4ed5-be6d-a6546eae8f86",
"last_modified": "2019-02-28T22:40:30.533005Z",
"name": "naca_2412.dat",
"size_bytes": 59684813
},
{
"path": "input/datasets/aerofoil_shape_file/naca_0012.dat",
"path": "naca_0012.dat",
"cluster": 0,
"sequence": 1,
"extension": "dat",
"tags": "naca_0012",
"tags": ["name:naca-0012"],
"timestamp": 0,
"id": "abff07bc-7c19-4ed5-be6d-a6546eae8f87",
"last_modified": "2019-02-28T22:40:30.533005Z",
"name": "naca_0012.dat"
Expand Down
1 change: 1 addition & 0 deletions data/input/values.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"airfoil_name": "naca-0012",
"alpha_range": [0, 6, 1],
"inflow_speed": 1,
"kinematic_viscosity": 1e-5,
Expand Down
8 changes: 8 additions & 0 deletions deployment_configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"app_dir": ".",
"twine": "twine.json",
"configuration_values": {
"analysis_program": "xfoil",
"max_iterations": 20
}
}
4 changes: 4 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
doctrees
html
source/doxyoutput*
source/library_api*
6 changes: 6 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Required by the python script for building documentation
Sphinx>=2,<3
sphinx-rtd-theme==0.5.0
sphinx-tabs==1.2.1
octue==0.1.12
pyserial==3.5
14 changes: 14 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. _api:

===
API
===


.. _api_xfoil:

X-Foil Module
=============

.. automodule:: xfoil_module.routines
:members:
Loading

0 comments on commit 71de74f

Please sign in to comment.