File tree Expand file tree Collapse file tree 8 files changed +27
-10
lines changed
template/{{cookiecutter.project_name}} Expand file tree Collapse file tree 8 files changed +27
-10
lines changed Original file line number Diff line number Diff line change 3131 - name : Install deps
3232 run : |
3333 pip install -U pip
34- pip install poetry==1.2 .2
34+ pip install poetry==1.4 .2
3535 poetry install
3636 env :
3737 POETRY_VIRTUALENVS_CREATE : false
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ WORKDIR /src
2222
2323ENV PATH ${PATH}:/home/fastapi_template/.local/bin
2424
25- RUN pip install poetry==1.2 .2
25+ RUN pip install poetry==1.4 .2
2626
2727COPY . /src/
2828RUN pip install .
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ stages:
1010 except :
1111 - tags
1212 before_script :
13- - pip install poetry==1.2 .2
13+ - pip install poetry==1.4 .2
1414 - poetry config virtualenvs.create false
1515 - poetry install
1616
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ If you want to develop in docker with autoreload add `-f deploy/docker-compose.d
3232Like this:
3333
3434``` bash
35- docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . up
35+ docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . up --build
3636```
3737
3838This command exposes the web application on port 8000, mounts current directory and enables autoreload.
@@ -210,8 +210,8 @@ aerich migrate
210210If you want to run it in docker, simply run:
211211
212212` ` ` bash
213- docker-compose -f deploy/docker-compose.yml -- project-directory . run --rm api pytest -vv .
214- docker-compose -f deploy/docker-compose.yml --project-directory . down
213+ docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml -- project-directory . run --build --rm api pytest -vv .
214+ docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml - -project-directory . down
215215` ` `
216216
217217For running tests on your local machine.
Original file line number Diff line number Diff line change 1- FROM python:3.9.6-slim-buster
1+ FROM python:3.9.6-slim-buster as prod
22
33{%- if cookiecutter.db_info.name == "mysql" %}
44RUN apt-get update && apt-get install -y \
@@ -15,7 +15,7 @@ RUN apt-get update && apt-get install -y \
1515{%- endif %}
1616
1717
18- RUN pip install poetry==1.2 .2
18+ RUN pip install poetry==1.4 .2
1919
2020# Configuring poetry
2121RUN poetry config virtualenvs.create false
@@ -25,7 +25,7 @@ COPY pyproject.toml poetry.lock /app/src/
2525WORKDIR /app/src
2626
2727# Installing requirements
28- RUN poetry install
28+ RUN poetry install --only main
2929
3030{%- if cookiecutter.db_info.name == "mysql" or cookiecutter.db_info.name == "postgresql" %}
3131# Removing gcc
@@ -36,6 +36,10 @@ RUN apt-get purge -y \
3636
3737# Copying actuall application
3838COPY . /app/src/
39- RUN poetry install
39+ RUN poetry install --only main
4040
4141CMD ["/usr/local/bin/python" , "-m" , "{{cookiecutter.project_name}}" ]
42+
43+ FROM prod as dev
44+
45+ RUN poetry install
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ services:
55 ports :
66 # Exposes application port.
77 - " 8000:8000"
8+ build :
9+ target : dev
810 volumes :
911 # Adds current directory as volume.
1012 - .:/app/src/
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ services:
55 build :
66 context : .
77 dockerfile : ./deploy/Dockerfile
8+ target : prod
89 image : {{cookiecutter.project_name}}:{{"${" }}{{cookiecutter.project_name | upper }}_VERSION:-latest{{"}"}}
910 restart : always
1011 env_file :
Original file line number Diff line number Diff line change 11import os
2+ from pathlib import Path
23import shlex
34import subprocess
45from typing import Optional
@@ -39,6 +40,15 @@ def run_docker_compose_command(
3940
4041def run_default_check (context : BuilderContext , without_pytest = False ):
4142 generate_project_and_chdir (context )
43+ compose = Path ("./deploy/docker-compose.yml" )
44+ compose_contents = compose .read_text ()
45+ new_compose_lines = []
46+ for line in compose_contents .splitlines ():
47+ if line .strip ().replace (" " , "" ) == "target:prod" :
48+ continue
49+ new_compose_lines .append (line )
50+ compose .write_text ("\n " .join (new_compose_lines ) + "\n " )
51+
4252 assert run_pre_commit () == 0
4353
4454 if without_pytest :
You can’t perform that action at this time.
0 commit comments