Skip to content
Snippets Groups Projects
Commit 16cdf389 authored by Santiago Ortiz [EPAM]'s avatar Santiago Ortiz [EPAM] Committed by Rostislav Dublin (EPAM)
Browse files

PWS-23: Service Dockerfile for development environment...

PWS-23: Service Dockerfile for development environment (!3)
parent 869737ca
No related branches found
No related tags found
1 merge request!3PWS-23: Service Dockerfile for development environment
.env/
.venv/
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.log
.git*
# The builder image, used to build the virtual environment
FROM python:3.11-bullseye as builder
# Install package manager
RUN pip install poetry==1.7.1
# Define environment
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache
# Set work directory
WORKDIR /app
# Copy project dependencies
COPY pyproject.toml poetry.lock ./
# Install production dependencies only and remove poetry cache directory
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR
# The runtime image, used to run the service
FROM python:3.11-slim-bullseye as runtime
# Set virtual environment path and add it to the system Path
ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH"
# Copy project dependencies from builder stage
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
# Copy project code
COPY app ./app
# Run service
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
......@@ -96,8 +96,8 @@ docker-compose up
curl localhost:8080/
```
#### Run with Dockerfile
```
#### Run with Dockerfile [MacOS / Linux]
```bash
export BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
export COMMIT_ID=$(git rev-parse HEAD)
export COMMIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
......@@ -113,6 +113,11 @@ docker build -f "./Dockerfile" \
docker run pws:latest
```
#### Run with Dockerfile [Windows]
```bash
winpty docker run --rm -it -p <container_port>:<host_port> pws
```
### Run with Uvicorn
```
......
......@@ -10,8 +10,19 @@ def create_app() -> FastAPI:
FastAPI: The configured and initialized FastAPI application.
"""
app = FastAPI()
print("hello")
return app
application = create_app()
app = create_app()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str | None = None):
return {"item_id": item_id, "q": q}
......@@ -4,6 +4,9 @@ version = "0.1.0"
description = ""
authors = ["Carlos Colin <Carlos_Colin@epam.com>"]
readme = "README.md"
packages = [
{ include = "app" }
]
[tool.poetry.dependencies]
python = "^3.11"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment