Docker-ify development process
This commit is contained in:
parent
817f52b359
commit
6f0e7cd593
@ -1,10 +1,3 @@
|
|||||||
# Run locally
|
|
||||||
|
|
||||||
In increasing complexity:
|
|
||||||
|
|
||||||
* `./basic-run.sh` - just raw-dog it
|
|
||||||
* `docker compose up --build`
|
|
||||||
|
|
||||||
# Pre-commit
|
# Pre-commit
|
||||||
|
|
||||||
This repo uses [pre-commit](https://pre-commit.com/). Install the tool with `pip install pre-commit` (or just `pip install -r requirements-dev.txt`), then install the hooks with `pre-commit install`
|
This repo uses [pre-commit](https://pre-commit.com/). Install the tool with `pip install pre-commit` (or just `pip install -r requirements-dev.txt`), then install the hooks with `pre-commit install`
|
||||||
|
30
Dockerfile
30
Dockerfile
@ -1,9 +1,5 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
# Comments are provided throughout this file to help you get started.
|
|
||||||
# If you need more help, visit the Dockerfile reference guide at
|
|
||||||
# https://docs.docker.com/go/dockerfile-reference/
|
|
||||||
|
|
||||||
ARG PYTHON_VERSION=3.9.6
|
ARG PYTHON_VERSION=3.9.6
|
||||||
FROM python:${PYTHON_VERSION}-slim as base
|
FROM python:${PYTHON_VERSION}-slim as base
|
||||||
|
|
||||||
@ -36,12 +32,6 @@ RUN --mount=type=cache,target=/root/.cache/pip \
|
|||||||
--mount=type=bind,source=requirements.txt,target=requirements.txt \
|
--mount=type=bind,source=requirements.txt,target=requirements.txt \
|
||||||
python -m pip install -r requirements.txt
|
python -m pip install -r requirements.txt
|
||||||
|
|
||||||
# Switch to the non-privileged user to run the application.
|
|
||||||
USER appuser
|
|
||||||
|
|
||||||
# Copy the source code into the container.
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Create writeable directory for database
|
# Create writeable directory for database
|
||||||
USER root
|
USER root
|
||||||
RUN mkdir database
|
RUN mkdir database
|
||||||
@ -49,7 +39,25 @@ RUN chmod 755 database
|
|||||||
RUN chown appuser:appuser database
|
RUN chown appuser:appuser database
|
||||||
USER appuser
|
USER appuser
|
||||||
|
|
||||||
# Expose the port that the application listens on.
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
|
|
||||||
|
########
|
||||||
|
# Targets diverge from here
|
||||||
|
########
|
||||||
|
|
||||||
|
FROM base as prod
|
||||||
|
|
||||||
|
COPY . .
|
||||||
CMD uvicorn app:app --host 0.0.0.0
|
CMD uvicorn app:app --host 0.0.0.0
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
FROM base as dev
|
||||||
|
# You probably want sqlite3 to poke around with the database anyway
|
||||||
|
USER root
|
||||||
|
RUN apt update
|
||||||
|
RUN apt install sqlite3
|
||||||
|
USER appuser
|
||||||
|
# Expects that the source code will be mounted into the container
|
||||||
|
CMD uvicorn app:app --reload --host 0.0.0.0
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Idempotent
|
|
||||||
source .venv/bin/activate
|
|
||||||
uvicorn app:app --reload --log-config ./local-run-log-config.yaml
|
|
49
compose.yaml
49
compose.yaml
@ -1,49 +1,14 @@
|
|||||||
# Comments are provided throughout this file to help you get started.
|
# This Docker Compose is intended for development, therefore it loads the code directories into the container.
|
||||||
# If you need more help, visit the Docker compose reference guide at
|
|
||||||
# https://docs.docker.com/go/compose-spec-reference/
|
|
||||||
|
|
||||||
# Here the instructions define your application as a service called "server".
|
|
||||||
# This service is built from the Dockerfile in the current directory.
|
|
||||||
# You can add other services your application may depend on here, such as a
|
|
||||||
# database or a cache. For examples, see the Awesome Compose repository:
|
|
||||||
# https://github.com/docker/awesome-compose
|
|
||||||
services:
|
services:
|
||||||
server:
|
server:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
|
target: dev
|
||||||
|
volumes:
|
||||||
|
- type: bind
|
||||||
|
source: ./app/
|
||||||
|
# Yes, really - we're using `/app` as the WD within the container, but `uvicorn` requires an import path.
|
||||||
|
target: /app/app
|
||||||
ports:
|
ports:
|
||||||
- 8000:8000
|
- 8000:8000
|
||||||
|
|
||||||
# The commented out section below is an example of how to define a PostgreSQL
|
|
||||||
# database that your application can use. `depends_on` tells Docker Compose to
|
|
||||||
# start the database before your application. The `db-data` volume persists the
|
|
||||||
# database data between container restarts. The `db-password` secret is used
|
|
||||||
# to set the database password. You must create `db/password.txt` and add
|
|
||||||
# a password of your choosing to it before running `docker compose up`.
|
|
||||||
# depends_on:
|
|
||||||
# db:
|
|
||||||
# condition: service_healthy
|
|
||||||
# db:
|
|
||||||
# image: postgres
|
|
||||||
# restart: always
|
|
||||||
# user: postgres
|
|
||||||
# secrets:
|
|
||||||
# - db-password
|
|
||||||
# volumes:
|
|
||||||
# - db-data:/var/lib/postgresql/data
|
|
||||||
# environment:
|
|
||||||
# - POSTGRES_DB=example
|
|
||||||
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
|
|
||||||
# expose:
|
|
||||||
# - 5432
|
|
||||||
# healthcheck:
|
|
||||||
# test: [ "CMD", "pg_isready" ]
|
|
||||||
# interval: 10s
|
|
||||||
# timeout: 5s
|
|
||||||
# retries: 5
|
|
||||||
# volumes:
|
|
||||||
# db-data:
|
|
||||||
# secrets:
|
|
||||||
# db-password:
|
|
||||||
# file: db/password.txt
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user