Skip to content

Commit 9d65eeb

Browse files
authored
WIP: Fix/integration (#6)
* Adds pip workaround as in ITISFoundation/osparc-simcore#540 Cleans up Dockerfile target `cache` * Flipped position of 'development' target in Dockerfile to speed up image build of production targets during CI. Now development is a bit slower * Adds fixes for .pipcache workaround so that it does not fail in devmode Changes to be committed: modified: {{cookiecutter.project_slug}}/Dockerfile * renamed integration -> _osparc-simcore folder * Fixes typo in README rendering Minor * Uninstalls in production stage all dev tools * output folder has osparc-simcore-like folder structure * Minor: alias target in makefile and added pre-gen hook as sample * Fixes test failure * to log or not to logger ...? * Added health-check command and script for service * Minors in Makefile * cleaned up template Makefile and added usage in README.md * Fixes setup naming * Adds setup_swagger to display API documentation * Added exceptions pckage * Added microbadger badges for images * Added banners for released docker images * updated healtcheck * Upgrading Dockerfile to deal with non-root users (ITISFoundation/osparc-simcore#90) * Updated entrypoint and boot as well as docker-compose and .dockerignor * Updated doc to underline new features * Adapting travis to run docker tests * Added make target to build prod docker * Disabled docker-build * Minor fixes * Fixing app console path * Simplified PR message * Fixes on docker configs after creating webserver and storage services * minor fixes and doc added folder for integration tests WIP * Disabled client-sdk * Moved client-sdk and integration tests to keep folder * Renamed as 'stub' * Cleaned up cookiecutter attributes list * Removed all references to docker in the Makefile * fix exit code * Fixes development mode in windows where docker mounts all volumes as root * literal user name instead of variable * Changend environment variables prefix Simplified healthcheck * Minor linter * Fix issue when docker group name already exists * REview: disabled all todos and other minor * Added test to check for tags in all generated files * Review: reduced timeout * Cleanedup readme * Fixes test and minor changes * fixes tests * Review: commented out installed packages in Dockerfile * fixed TODOs
1 parent a3b56df commit 9d65eeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+437
-221
lines changed
+12-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
---
2-
name: Feature request
3-
about: Suggest an idea to implement in the simcore plaform
2+
name: <!-- Feature request -->
3+
about: <!-- Suggest an idea to implement in the simcore plaform -->
44

55
---
66

77
**USER STORY:**
88

9-
A clear and concise description of how the feature works and looks like from the user's perspective.
9+
<!--A clear and concise description of how the feature works and looks like from the user's perspective.
1010
11-
Ex. I want to be able the stop the running pipeline by pressing a stop button. If the pipeline is stopped, I see a info-level message confirming it in the logger, if it fails the message should be displayed in red (error). Also, all the progress bars in the nodes must be set to 0.
11+
Ex. I want to be able the stop the running pipeline by pressing a stop button. If the pipeline is stopped, I see a info-level message confirming it in the logger, if it fails the message should be displayed in red (error). Also, all the progress bars in the nodes must be set to 0. -->
1212

1313
**DEFINITION OF DONE:**
1414

15-
A clear and concise description of what the feature requires.
15+
<!--A clear and concise description of what the feature requires.
1616
1717
0. Play button turns into stop button when pipeline is running
1818
1. Stop button turns into play button when pipeline is finished
1919
2. Stop button turns into play button when pipeline is successfully stopped
2020
3. Logger displays messages everytime the play/stop button is pressed
2121
4. Progress bars are set to 0 when stopping pipeline
2222
5. Stop button has a Python interface
23+
-->
2324

2425
**EXAMPLE:**
2526

26-
Any file/screenshot/photomontage/video/website is provided for a better understanding of the request
27+
<!-- Any file/screenshot/photomontage/video/website is provided for a better understanding of the request
28+
29+
Recommended tools for screen captures:
30+
- https://getgreenshot.org/ : very complete screen capture with annotation capabilities [windows only]
31+
- https://www.cockos.com/licecap/ : produces lighweight animated screen captures
32+
-->

.github/PULL_REQUEST_TEMPLATE.md

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
<!-- Thank you for your contribution!
2-
3-
- Add **WIP-** prefix in title if it is still work in progress (i.e. should not be merged but is ready to start reviewing it)
4-
- Use [waffle.io] keywords in title/descriptions to trigger bot actions:
5-
- close, closes, close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved #[issueNumber]
6-
- connect to, connects to, connected to, connect, connects, connected #[issueNumber]
7-
- parent of, parent to, parent #[issueNumber]
8-
- child of, child to, child #[issueNumber]
9-
- blocks, block, required by, needed by, dependency of #[issueNumber]
10-
- blocked by, required, require, needs, need, depends on #[issueNumber]
11-
-->
1+
<!-- **WIP-** prefix in title if still work in progress -->
122

133
## What do these changes do?
144

@@ -17,17 +7,20 @@
177

188
## Related issue number
199

20-
<!-- Are there any issues opened that will be resolved by merging this change?
10+
<!--
11+
Use [waffle.io] keywords in title/descriptions to trigger bot actions:
2112
22-
- add mentions of the user or team responsible for reviewing proposed changes
23-
- and user/team to .github/CODEOWNERS to automatically assign reviewers
13+
- close, closes, close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved #[issueNumber]
14+
- connect to, connects to, connected to, connect, connects, connected #[issueNumber]
2415
-->
2516

17+
2618
## Checklist
2719

2820
- [ ] I think the code is well written
2921
- [ ] Unit tests for the changes exist
3022
- [ ] Documentation reflects the changes
23+
- [ ] **Runs in the swarm**
3124
- [ ] If you design a new module, add your user to .github/CODEOWNERS
3225

3326
[waffle.io]:https://waffle.io/marketing-assets/documents/waffleio_cheatsheet_v1.pdf?utm_source=blog&utm_medium=cheatsheet-ctabutton&utm_campaign=cheatsheet

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
language: python
2+
dist: xenial
23
addons:
34
apt:
45
packages:
5-
- "python3"
6+
- python3
67
- "python3-pip"
8+
- docker-ce
79
python:
810
- "3.6"
911
install:

.vscode-template/install-dev-tools.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
# uname -s == Darwin
3+
brew install gnu-sed

README.md

+18-22
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,28 @@ To generate a new cookiecutter template layout just type
1919
```
2020
and answer the questions.
2121

22+
23+
## Backed project
24+
25+
Infrastructure:
26+
- [osparc-simcore]-compatible project skeleton for python services
27+
- service-level makefile (type ``make help``)
28+
- [folder]({{cookiecutter.project_slug}}/extra_osparc-simcore) with stub code to integrate service in [osparc-simcore] framework
29+
- Multi-stage [Dockerfile]({{cookiecutter.project_slug}}/Dockerfile) with different boot modes and healt-check
30+
-
31+
- ...
32+
33+
Service Features:
34+
- [aiohttp] server
35+
- [OpenAPI](https://www.openapis.org/) compatible RESTful API
36+
- ...
37+
2238
Then, to work in the backed project, this is the standard wordflow
2339
``` console
2440
$ cd my project
2541
$ make help
2642

27-
# Create and activate virtual envi
43+
# Create and activate virtual environment
2844
$ make venv
2945
$ source .venv/bin/activate
3046

@@ -52,26 +68,6 @@ clean – cleans projects directory
5268
clean-force – cleans & removes also venv folder
5369
```
5470

55-
#### Features of the backed project
56-
- [aiohttp] server
57-
- [OpenAPI](https://www.openapis.org/) compatible RESTful API
58-
-
59-
- Predefined project skeleton
60-
- ``.vscode-template`` are recommended settings for vscode
61-
- ``{{cookiecutter.project_slug}}/extra`` contains code modules within a tree folder structure equivalent to [osparc-simcore] repo
62-
- makefile
63-
```console
64-
$ make help
65-
simcore_service_dummy_service:0.1.0
66-
67-
venv – Create the virtual environment
68-
install – Install project sources in "development mode"
69-
uninstall – Uninstall project sources
70-
test – Runs unit tests [w/ fail fast]
71-
help – Display all callable targets
72-
clean – Clean the project's directory
73-
```
74-
7571
---
7672

7773
## Acknoledgements
@@ -81,6 +77,6 @@ This template was built upon ideas/snippets borrowed from already existing great
8177
This project is licensed under the terms of the [MIT License](/LICENSE)
8278

8379

84-
[aiohptt]:https://aiohttp.readthedocs.io/en/stable/
80+
[aiohttp]:https://aiohttp.readthedocs.io/en/stable/
8581
[cookiecutter]:https://cookiecutter.readthedocs.io
8682
[osparc-simcore]:https://github.com/ITISFoundation/osparc-simcore

cookiecutter.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
{
22
"full_name": "Your name",
33
"github_username": "Your github username",
4+
45
"project_name": "Name of the project",
56
"project_short_description": "A short description of the project",
67
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}",
7-
"dockercompose_service_name": "{{ cookiecutter.project_slug }}",
8-
"dockercompose_service_api_port": "8080",
8+
99
"package_name": "simcore_service_{{ cookiecutter.project_slug|replace('-','_') }}",
1010
"distribution_name": "simcore-service-{{ cookiecutter.project_slug }}",
1111
"command_line_interface_bin_name": "{{ cookiecutter.distribution_name }}",
12-
"simcore_install_root": ["../../", "git+https://github.com/ITISFoundation/osparc-simcore.git@master"],
13-
"release_date": "{% now 'local' %}",
12+
1413
"version": "0.1.0",
1514
"openapi_specs_version": "v{{ cookiecutter.version.split('.')[0] }}",
16-
"sdk_package_name": "simcore_{{ cookiecutter.project_slug|replace('-','_') }}_sdk",
15+
16+
"dockercompose_service_name": "{{ cookiecutter.project_slug }}",
17+
"dockercompose_service_api_port": "8080",
18+
19+
"enable_aiohttp_swagger": ["false", "true"],
20+
21+
"year": "{% now 'utc', '%Y' %}",
1722
"_extensions": ["jinja2_time.TimeExtension"]
1823
}

{{cookiecutter.project_slug}}/client-sdk/codegen.sh renamed to keep/{# client-sdk #}/codegen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#/bin/bash
2-
# TODO: unify scripts
2+
# FIXME: activate when ITIFoundation/openapi-tools:latest available
33
exec {{ cookiecutter.simcore_install_root }}../scripts/openapi/openapi_codegen.sh \
44
-i ../src/{{ cookiecutter.package_name }}/oas3/{{cookiecutter.openapi_specs_version}}/openapi.yaml \
55
-o . \

keep/{# integration #}/conftest.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
# TODO: docker-compose -f services/docker-compose.yml up --exit-code-from={{ cookiecutter.project_name }} {{ cookiecutter.project_name }}
4+
5+
# TODO: docker-compose -f services/docker-compose.yml up --detach {{ cookiecutter.project_name }}
6+
# test if responsive ??
7+
8+
# ls home
9+
# ls /devel

tests/test_bake_project.py

+64-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
#pylint: disable=W0621
2-
# W0621:Redefining name 'here' from outer scope (line 12)
1+
# pylint:disable=wildcard-import
2+
# pylint:disable=unused-import
3+
# pylint:disable=unused-variable
4+
# pylint:disable=unused-argument
5+
# pylint:disable=redefined-outer-name
6+
7+
import logging
38
import os
4-
import sys
5-
import pytest
9+
import shutil
610
import subprocess
7-
import logging
11+
import sys
812
from contextlib import contextmanager
9-
1013
from pathlib import Path
1114

15+
import pytest
16+
1217
logger = logging.getLogger(__name__)
1318

1419
@pytest.fixture
@@ -38,6 +43,8 @@ def inside_dir(dirpath):
3843
os.chdir(old_path)
3944

4045

46+
47+
4148
def test_project_tree(cookies):
4249
result = cookies.bake(extra_context={'project_slug': 'test_project'})
4350
assert result.exit_code == 0
@@ -51,13 +58,28 @@ def test_project_tree(cookies):
5158
# with inside_dir(str(result.project)):
5259
# assert subprocess.check_call(['flake8']) == 0
5360

61+
# TODO: use pylint via package instead of application entrypoint
5462
def test_run_pylint(cookies, pylintrc):
5563
result = cookies.bake(extra_context={'project_slug': 'pylint_compat', 'package_name': 'package_folder'})
5664
with inside_dir(str(result.project)):
5765
cmd = 'pylint --rcfile {} -v src/package_folder/'.format(pylintrc.absolute()).split()
5866
assert subprocess.check_call(cmd) == 0
5967

6068

69+
def test_no_tags(cookies):
70+
exclude = ['.pylintrc']
71+
result = cookies.bake(extra_context={
72+
'project_slug': 'myproject', 'package_name': 'package_folder'})
73+
for root, dirs, files in os.walk(result.project):
74+
for fname in files:
75+
if fname not in exclude:
76+
fpath = os.path.join(root, fname)
77+
with open(fpath) as fh:
78+
for lineno, line in enumerate(fh):
79+
assert "TODO" not in line, "{}:{}".format(fpath, lineno)
80+
# skips
81+
dirs[:] = [n for n in dirs if not n.startswith('.')]
82+
6183
def test_run_tests(cookies):
6284
result = cookies.bake(extra_context={'project_slug': 'dummy-project'})
6385
working_dir = str(result.project)
@@ -73,3 +95,39 @@ def test_run_tests(cookies):
7395
logger.info("Running '%s' ...", cmd)
7496
assert subprocess.check_call(cmd.split()) == 0
7597
logger.info("Done '%s' .", cmd)
98+
99+
100+
101+
102+
@pytest.mark.skip("TODO: Under development")
103+
def test_build_docker(cookies, tmpdir):
104+
# TODO: check build target base, build, cache, prod and devel
105+
106+
# bakes cookie within osparc-simcore tree structure
107+
result = cookies.bake(extra_context={'project_slug': 'dummy-project'})
108+
working_dir = str(result.project)
109+
110+
tmpdir.mkdir("packages").join("dummy.py").write("import os")
111+
new_working_dir = tmpdir.mkdir("services") / os.path.basename(working_dir)
112+
shutil.move(working_dir, new_working_dir)
113+
114+
# ----
115+
commands = (
116+
"ls -la .",
117+
"pip install pip-tools",
118+
"make requirements",
119+
"docker build -f Dockerfile -t dummy-project:prod --target production ../../"
120+
)
121+
with inside_dir(new_working_dir):
122+
for cmd in commands:
123+
logger.info("Running '%s' ...", cmd)
124+
assert subprocess.check_call(cmd.split()) == 0
125+
logger.info("Done '%s' .", cmd)
126+
127+
128+
@pytest.mark.skip("TODO: Under development")
129+
def test_run_docker(cookies, tmpdir):
130+
# check state after boot
131+
# check run permissions `simcore-service-storage --help`
132+
# check load config `simcore-service-storage -c `
133+
pass

tools/cleanup-settings.bat

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
:: cleanup settings
2+
::
3+
:: UNDER development
4+
::
5+
@echo OFF
6+
setlocal
7+
8+
set HERE=%~dp0
9+
set REPODIR=%HERE%..\
10+
11+
set SETTINGSPATH="%REPODIR%\.vscode\settings.json"
12+
type %SETTINGSPATH% | python -m json.tool --sort-keys > %HERE%workspace-settings.json
13+
:: TODO this should update %SETTINGSPATH%
14+
15+
set SETTINGSPATH="%APPDATA%\Code\User\settings.json"
16+
type %SETTINGSPATH% | python -m json.tool --sort-keys > %HERE%user-settings.json

tools/user-settings.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"atomKeymap.promptV3Features": true,
3+
"editor.formatOnPaste": true,
4+
"editor.insertSpaces": false,
5+
"editor.multiCursorModifier": "ctrlCmd",
6+
"editor.renderWhitespace": "all",
7+
"editor.tabSize": 2,
8+
"explorer.confirmDelete": false,
9+
"files.exclude": {
10+
"**/*.pyc": true,
11+
"**/.DS_Store": true,
12+
"**/.git": true,
13+
"**/.hg": true,
14+
"**/.svn": true,
15+
"**/CVS": true
16+
},
17+
"git.enabled": true,
18+
"git.path": "%ConEmuDir%\\vendor\\git-for-windows\\cmd\\git.exe",
19+
"latex-workshop.view.pdf.viewer": "tab",
20+
"python.linting.enabled": true,
21+
"python.pythonPath": "C:\\Users\\crespo\\Miniconda3\\envs\\py3\\python.exe",
22+
"python.unitTest.unittestEnabled": true,
23+
"terminal.integrated.shell.windows": "cmd.exe",
24+
"terminal.integrated.shellArgs.windows": [
25+
"/k",
26+
"%ConEmuDir%\\vendor\\init.bat"
27+
],
28+
"workbench.iconTheme": "vscode-icons"
29+
}

{{cookiecutter.project_slug}}/.dockerignore

-10
This file was deleted.

0 commit comments

Comments
 (0)