diff --git a/.env.template b/.env.template index def3e7f..e566f60 100644 --- a/.env.template +++ b/.env.template @@ -5,3 +5,6 @@ export AWS_SECRET_ACCESS_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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8561d94 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2e02fe6 --- /dev/null +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index f24ff8a..bd97001 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..2d6d9cb --- /dev/null +++ b/compose.yaml @@ -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