Giter VIP home page Giter VIP logo

poetry-fastapi-docker's Introduction

Poetry - FastAPI - Docker

Table Of Contents

About The Project

This repo serves as a minimal reference on setting up docker multi-stage builds with poetry.

This is an updated and modified fork of python-poetry-docker-example.

Differences

  • Newer poetry version
  • Install poetry from python-poetry GitHub source
  • Does not run production image as /root
  • Set the SHELL option -o pipefail before RUN with a pipe

Requirements

NOTE - Run all commands from the project root

Local development

Poetry

Create the virtual environment and install dependencies with:

poetry install

See the poetry docs for information on how to add/update dependencies.

Run commands inside the virtual environment with:

poetry run <your_command>

Spawn a shell inside the virtual environment with:

poetry shell

Start a development server locally:

poetry run uvicorn app.main:app --reload --host localhost --port 8000

API will be available at localhost:8000/

To run testing/linting locally you would execute lint/test in the scripts directory.

Docker

Build images with:

docker build --tag poetry-project --file docker/Dockerfile .

The Dockerfile uses multi-stage builds to run lint and test stages before building the production stage. If linting or testing fails the build will fail.

You can stop the build at specific stages with the --target option:

docker build --name poetry-project --file docker/Dockerfile . --target <stage>

For example we wanted to stop at the test stage:

docker build --tag poetry-project --file docker/Dockerfile --target test .

We could then get a shell inside the container with:

docker run -it poetry-project:latest bash

If you do not specify a target the resulting image will be the last image defined which in our case is the 'production' image.

Credits

poetry-fastapi-docker's People

Contributors

svx avatar brizzbuzz avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.