-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# syntax = docker/dockerfile:1.2 | ||
|
||
ARG PYTHON_VERSION=3.9 | ||
ARG BASE_OS=slim | ||
|
||
FROM tiangolo/uvicorn-gunicorn-fastapi:python${PYTHON_VERSION}-${BASE_OS} AS base | ||
|
||
ENV APP_DIR="/app" | ||
|
||
RUN mkdir -p ${APP_DIR} | ||
WORKDIR ${APP_DIR} | ||
|
||
FROM base AS dev | ||
|
||
# Install Python dependencies | ||
# Requirement file: ./requirements.txt | ||
|
||
COPY ./requirements.txt ./requirements.txt | ||
|
||
RUN \ | ||
pip install --no-cache-dir -r ./requirements.txt && \ | ||
rm ./requirements.txt | ||
|
||
FROM dev AS prod | ||
|
||
# Add necessary source code into the image for production execution | ||
COPY ./app ${APP_DIR} | ||
|
||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"group": { | ||
"default": { | ||
"targets": [ | ||
"dev", | ||
"prod" | ||
] | ||
} | ||
}, | ||
"target": { | ||
"dev": { | ||
"dockerfile": "Dockerfile.synth", | ||
"tags": [ | ||
"my_app:dev" | ||
], | ||
"target": "dev", | ||
"cache-from": [ | ||
"type=docker" | ||
], | ||
"output": [ | ||
"type=docker" | ||
] | ||
}, | ||
"prod": { | ||
"dockerfile": "Dockerfile.synth", | ||
"tags": [ | ||
"my_app:prod" | ||
], | ||
"target": "prod", | ||
"cache-from": [ | ||
"type=docker" | ||
], | ||
"output": [ | ||
"type=docker" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
*.rendered.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- name: default | ||
image: my_app | ||
build_args: | ||
cache-from: [type=docker] | ||
output: [type=docker] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: app-code | ||
priority: -100 | ||
depends_on: | ||
- base | ||
template: | ||
file: stage.Dockerfile.jinja2 | ||
variables: | ||
instructions: | ||
- "# Add necessary source code into the image for production execution" | ||
- COPY ./app ${APP_DIR} | ||
command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: app-deps | ||
priority: 70 | ||
depends_on: | ||
- base | ||
template: | ||
file: pip-install.Dockerfile.jinja2 | ||
variables: | ||
requirement_files: | ||
- source: ./requirements.txt | ||
destination: ./requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: base | ||
priority: 100 | ||
template: | ||
variables: | ||
base: tiangolo/uvicorn-gunicorn-fastapi:python${PYTHON_VERSION}-${BASE_OS} | ||
env: | ||
APP_DIR: /app | ||
instructions: | ||
- RUN mkdir -p ${APP_DIR} | ||
- WORKDIR ${APP_DIR} | ||
image_args: | ||
PYTHON_VERSION: 3.9 | ||
BASE_OS: slim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
- name: dev | ||
modules: | ||
- base | ||
- app-deps | ||
|
||
- name: prod | ||
extends: | ||
- dev | ||
modules: | ||
- app-code |
19 changes: 19 additions & 0 deletions
19
examples/fastapi_app/docker-printer/templates/pip-install.Dockerfile.jinja2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% extends "stage.Dockerfile.jinja2" %} | ||
|
||
{% block instructions -%} | ||
# Install Python dependencies | ||
{% for req in requirement_files -%} | ||
# Requirement file: {{ req['source'] }} | ||
{%- endfor %} | ||
{% if requirements -%} | ||
# Other requirements: {% for req in requirements -%}{{ req }}{{ ", " if not loop.last else "" }}{% endfor %} | ||
{% endif %} | ||
|
||
{% for req in requirement_files -%} | ||
COPY {{ req['source'] }} {{ req['destination'] }} | ||
{% endfor %} | ||
|
||
RUN {% if cache %}--mount=type=cache,target=/var/cache/pip{% endif %} \ | ||
pip install {% if cache %}--cache-dir /var/cache/pip{% else %}--no-cache-dir{% endif %} {% for req in requirement_files %}-r {{ req['destination'] }}{% endfor %} {% for req in requirements %}{{ req }}{{ " " if not loop.last else "" }}{% endfor %}{% for req in requirement_files %} && \ | ||
rm {{ req['destination'] }}{% endfor %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This is where you would put any additional requirements beyond what's installed in the base docker image |