Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial local UI+dsub docker compose #20

Merged
merged 5 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
swagger-codegen-cli.jar
ui/node_modules
5 changes: 5 additions & 0 deletions Dockerfile.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node

WORKDIR /ui
ADD ui/package-lock.json ui/package.json /ui/
RUN npm install
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

Job Monitor API and UI for interacting with asynchronous batch jobs.

## Development

```
docker-compose up
```

Navigate to http://localhost:4200.

Note: websocket reload on code change does not work in docker-compose (see
https://github.com/angular/angular-cli/issues/6349).

Changes to `package.json` or `requirements.txt` require a rebuild:

```
docker-compose up --rebuild
```

Alternatively, rebuild a single component:

```
docker-compose build ui
```

## Setup Lint Git Hook:
```
sudo pip install yapf
Expand Down Expand Up @@ -78,4 +101,3 @@ pip install -r servers/dsub/requirements-to-freeze.txt
pip freeze | sort > servers/dsub/requirements.txt
deactivate
```

31 changes: 30 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
version: '2'
services:
jobs:
ui:
build:
context: .
dockerfile: Dockerfile.ui
# Use --host "ui" to match the container name, as this is how nginx will
# access the UI on the network. This must match to avoid "Invalid Host"
# errors. See also https://github.com/angular/angular-cli/issues/6349.
command: ["npm", "run-script", "ng", "--", "serve", "--host", "ui"]
volumes:
# Only mount a whitelist of top-level /ui files/directories; specifically
# node_modules must not be included here. Mount only files required to run
# the dev server. Anything required to install dependencies (npm install)
# should instead be added via the Dockerfile. Updating dependencies
# requires use of the slower docker-compose build.
- ./ui/src:/ui/src
- ./ui/tsconfig.json:/ui/tsconfig.json
- ./ui/tslint.json:/ui/tslint.json
- ./ui/.angular-cli.json:/ui/.angular-cli.json
dsub-server:
# dsub creates the local provider folder in /tmp/dsub-local which can only
# be written to by the owner. Unless dsub changes the permissions on this
# folder the docker container must be 'privileged'
Expand All @@ -16,6 +34,7 @@ services:
command: ["-b", ":8190"]
environment:
- PROVIDER_TYPE=local
- PATH_PREFIX=/api/v1
# Avoid writing .pyc files back to the volume. Files generated this way
# have restricted permissions set which cause errors on subsequent docker
# builds.
Expand All @@ -28,3 +47,13 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 8190:8190
jobs-proxy:
image: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
links:
- ui
- dsub-server
ports:
- 4200:4200

25 changes: 25 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# nginx proxy over the UI and API job manager servers. For directive
# documentation, see http://nginx.org/en/docs/dirindex.html
# Required - just leave the defaults for now.
events {}
http {
# These host names are available in a docker-compose environment via
# docker linking.
upstream ui {
server ui:4200;
}
upstream api {
server dsub-server:8190;
}
server {
listen 4200;
# All API requests have a version prefix. Route everything else to
# the UI server.
location /api {
proxy_pass http://api;
}
location / {
proxy_pass http://ui;
}
}
}
25 changes: 15 additions & 10 deletions servers/dsub/jobs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
from .encoder import JSONEncoder
from controllers.dsub_client import DSubClient

app = connexion.App(__name__, specification_dir='./swagger/', swagger_ui=False)
app.app.json_encoder = JSONEncoder
app.add_api('swagger.yaml')

# Log to stderr.
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
app.app.logger.addHandler(handler)
app.app.logger.setLevel(logging.INFO)

# gunicorn flags are passed via env variables, so we use these as the default
# values. These arguments will rarely be specified as flags directly, aside from
# occasional use during local debugging.
Expand All @@ -26,6 +16,11 @@
type=str,
help='The dsub provider type to use for monitoring jobs',
default=os.environ.get('PROVIDER_TYPE'))
parser.add_argument(
'--path_prefix',
type=str,
help='Path prefix, e.g. /api/v1, to serve from',
default=os.environ.get('PATH_PREFIX'))

if __name__ == '__main__':
parser.add_argument(
Expand All @@ -39,8 +34,18 @@
# gunicorn.
args, _ = parser.parse_known_args()

app = connexion.App(__name__, specification_dir='./swagger/', swagger_ui=False)
app.app.config['PROVIDER_TYPE'] = args.provider_type
app.app.config['CLIENT'] = DSubClient()

# Log to stderr.
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
app.app.logger.addHandler(handler)
app.app.logger.setLevel(logging.INFO)

app.app.json_encoder = JSONEncoder
app.add_api('swagger.yaml', base_path=args.path_prefix)

if __name__ == '__main__':
app.run(host='0.0.0.0', port=args.port)
Loading