Skip to content

Commit

Permalink
Docker-compose and justfile (#67)
Browse files Browse the repository at this point in the history
* Add justfile, docker-compose config

* Switch to python 3.9

* Update documentation, lint

* Add note about IS_PROD
  • Loading branch information
AetherUnbound authored Dec 22, 2021
1 parent 0c75c79 commit 4867ac8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 11 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.7-slim
FROM python:3.9-slim

ENV PYTHONUNBUFFERED=true \
FLASK_DEBUG=1
Expand All @@ -10,5 +10,3 @@ WORKDIR /app
RUN pip install -r requirements.txt

COPY src/ /app

CMD ["flask", "run", "--host=0.0.0.0"]
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ Licenses are looked up in the dataset and if a vehicle is found, that data is di

## Development

### If you just want to run the app
We use the [`just` command runner](https://github.com/casey/just), you'll need to install it before running any steps below.

Build the image with `docker build -t <tag> .`. Run it with `docker run -p 5000:5000 <tag>`.
### Build and run the app

Build the image with `just build` and run it using `just up`.
The server will be available at port `3030`.

To run this image in production, use the `IS_PROD` variable for any actions, e.g. `IS_PROD=true just up`.

### If you want to make changes

1. Install a python virtual environment: `python3 -m venv venv`
2. Activate the virtual environment: `source venv/bin/activate`
3. Install dependencies: `pip install -r requirements-dev.txt`
4. Install the pre-commit hook: `pre-commit install`
5. Run the app: `cd src; FLASK_DEBUG=1 flask run`
6. Make changes and contribute 🙌
The flask server will detect any changes made to the code and restart the application to pick up said changes.

To run the static checks (`just lint`), you will first need to [install `pre-commit`](https://pre-commit.com/).
11 changes: 11 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3"

services:
app:
build: .
environment:
FLASK_ENV: development
FLASK_DEBUG: 1
command: flask run --host=0.0.0.0 --port 3030
volumes:
- ./src:/app
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3"

services:
app:
restart: always
build: .
environment:
FLASK_APP: app
FLASK_ENV: production
command: gunicorn --workers=2 --bind 0.0.0.0:3030 app:app
ports:
- "3030:3030"
37 changes: 37 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
IS_PROD := env_var_or_default("IS_PROD", "")
COMPOSE_FILE := "-f docker-compose.yml " + if IS_PROD == "true" {""} else {"-f docker-compose.override.yml "}
DC := "docker-compose " + COMPOSE_FILE
RUN := DC + " run --rm app"
set dotenv-load := false


default:
@just -lu

# Build all containers
build:
{{ DC }} build

# Print the docker-compose config
config:
{{ DC }} config

# Spin up all (or the specified) services
up service="":
{{ DC }} up -d {{ service }}

# Tear down all services
down:
{{ DC }} down

# Attach logs to all (or the specified) services
logs service="":
{{ DC }} logs -f {{ service }}

# Run a command using the web image
run +args:
{{ RUN }} {{ args }}

# Run the static checks
lint:
pre-commit run --all-files

0 comments on commit 4867ac8

Please sign in to comment.