Skip to content

Commit

Permalink
Merge pull request #684 from kids-first/development-docker-compose
Browse files Browse the repository at this point in the history
πŸ‘¨πŸ»β€πŸ’» Always bind all interfaces when app runs in docker-compose
  • Loading branch information
znatty22 authored Sep 5, 2024
2 parents 182f4b2 + 63abb20 commit 7370bbd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
27 changes: 3 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,11 @@ development environment using 1 of 2 options:

- Pro: Quick setup, no installation of dependencies
- Con: Since everything is running in containers, need to use `docker container exec` to run things in container
- Con: You'll need to make a couple of small changes to run the dockerized service in debug mode (live updates)

1. In docker-compose.yml change the following under the `dataservice` block:
Follow the instructions in [Run API](#run-api)

```yaml
# command: /bin/ash -c "sleep 5; ./bin/run.sh"
command: /bin/ash -c "sleep 5; flask db upgrade; ./manage.py"

port:
- "5000:5000"
```
2. Bind host to all interfaces in manage.py:
```python
if __name__ == '__main__':
app.run(host="0.0.0.0")
```
3. Follow the instructions in [Run API](#run-api)
Now your service should be running at http://localhost:5000 inside the
docker-compose stack. The changes you made above allow the service to run
in **debug mode** which means when you make changes to the code,
it should reload the service automatically so that you can see your updates in
realtime instead of having to bring down the stack and bring it up again.
Once again your service should be running at http://localhost:5000 inside the
docker-compose stack.

### Option 2: Develop API on Machine

Expand Down
12 changes: 8 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ services:
build:
context: .
target: test
command: /bin/ash -c "sleep 5; ./bin/run.sh"
# command: /bin/ash -c "sleep 5; flask db upgrade; ./manage.py"
# command: /bin/ash -c "sleep 5; ./bin/run.sh"
command: /bin/ash -c "sleep 5; flask db upgrade; ./manage.py"
volumes:
- .:/app
ports:
- "5000:80"
- "5000:5000"
env_file:
- .env
environment:
FLASK_CONFIG: "${FLASK_CONFIG}"
FLASK_APP: "${FLASK_APP}"
PG_HOST: "${DATASERVICE_PG_HOST}"
# NOTE: Only set BIND_ALL_INTERFACES to enabled if running app within
# a docker container. Otherwise, you will make your app accessible to
# any IP that can reach machine via its public IP
BIND_ALL_INTERFACES: "enabled"
PG_HOST: dataservice_pg
PG_PORT: "${DATASERVICE_PG_PORT}"
PG_NAME: "${DATASERVICE_DB}"
PG_USER: "${DATASERVICE_DB_USER}"
Expand Down
7 changes: 6 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@

app = create_app(os.environ.get('FLASK_CONFIG') or 'default')

BIND_ALL_INTERFACES = os.environ.get("BIND_ALL_INTERFACES")
host = None
if BIND_ALL_INTERFACES == "enabled":
host = "0.0.0.0"

if __name__ == '__main__':
app.run()
app.run(host=host)

0 comments on commit 7370bbd

Please sign in to comment.