Skip to content

Commit

Permalink
chore: Dockerize API
Browse files Browse the repository at this point in the history
  • Loading branch information
deuzu authored and Fenkiou committed Feb 15, 2023
1 parent c1c3d57 commit fa78f8e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ export AWS_SECRET_ACCESS_KEY="<secret-key>"
export FLASK_APP=lightsoff_api
export DATABASE_URI=postgresql://username:password@host:port/database_name
export CORS_ALLOWED_ORIGINS="*"

export SERVER_NAME=0.0.0.0:5000
export FLASK_APP=lightsoff_ape
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.9

RUN mkdir /app
COPY . /app
WORKDIR /app
ENV PYTHONPATH=${PYTHONPATH}:${PWD}
RUN pip3 install poetry
RUN poetry config virtualenvs.create false
RUN poetry install
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: all install update uninstall

all:
@docker compose run --rm --entrypoint '' api flask db upgrade

install:
@docker compose up --detach --remove-orphans

update:
@docker compose pull
@docker compose up --force-recreate --build --detach

uninstall:
@docker compose stop
@docker compose rm --volumes --force
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Development setup

- [Install poetry](https://python-poetry.org/docs/#installation)
- Install python 3.9
- Create a virtual `python -m venv venv`
- Activate `source venv/bin/activate`
- Install dependencies `poetry install`
- Copy environment file: `cp .env.template .env`
- Replace environment variables with yours
- Run migrations `flask db upgrade`
- Launch the app `flask run`
# LightsOff API

## Built With

- [Python3](https://www.python.org/)
- [Poetry](https://python-poetry.org/)
- [Flask](https://flask.palletsprojects.com/)
- [Docker](https://www.docker.com/) & [Docker Composer](https://docs.docker.com/compose/)

## Get Started

Copy environment file: `cp .env.template .env`

```console
make
make install
```
23 changes: 23 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
services:
api:
build: .
working_dir: /app
volumes:
- ./:/app
ports:
- 5000:5000
depends_on:
- database
entrypoint: flask run --debug
environment:
- DATABASE_URI=postgresql://lightsoff:lightsoff@database:5432/lightsoff
- SERVER_NAME=0.0.0.0:5000

database:
image: postgres:15-alpine
environment:
- POSTGRES_USER=lightsoff
- POSTGRES_PASSWORD=lightsoff
- POSTGRES_DB=lightsoff
ports:
- 5054:5432

0 comments on commit fa78f8e

Please sign in to comment.