This commit is contained in:
wop 2024-09-26 02:47:42 +02:00
commit 1641912e55
Signed by: CaffeineFueled
GPG key ID: 739D3C8D00944004
5 changed files with 129 additions and 0 deletions

28
Dockerfile Normal file
View file

@ -0,0 +1,28 @@
# Base Image für den Container - entsprechend der genutzten Python Version anpassen
FROM python:3.10.13-bullseye
# Verhindert das Kopieren von pvc Dateien - relevant?
ENV PYTHONDONTWRITEBYTECODE 1
# Sorft dafür, dass Python-Output zum Terminal geschickt wird
ENV PYTHONUNBUFFERED 1
# Updates und Installation der nötigen Software - entsprechend anpassen
RUN apt-get update \
&& apt-get install -y build-essential \
&& apt-get install -y libpq-dev \
&& apt-get install -y gettext \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*
# Kopiervorgang Host > Container
COPY ./requirements.txt /requirements.txt
# Installation der Abhängigkeiten
RUN pip install -r /requirements.txt --no-cache-dir
# Dir, von der die Befehle abgesetzt werden
WORKDIR /app
# Uvicorn Befehl, um die App zu starten
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

38
README.md Normal file
View file

@ -0,0 +1,38 @@
# Andi's App - Irgendwas mit K
# Commands
`alias pps="podman container ps -a"`
`alias pre="podman-compose down && podman-compose up -d"`
`podman-compose up`
`podman-compose down`
# Dockerfile
[Dockerfile Reference](https://docs.docker.com/reference/dockerfile/)
[Compose File Reference](https://docs.docker.com/reference/compose-file/)
[Podman 'Basic' Networking](https://github.com/containers/podman/blob/main/docs/tutorials/basic_networking.md)
[Postgres Dockerhub](https://hub.docker.com/_/postgres/tags?page=3)
### Source Dockerfile + App
https://dev.to/mbuthi/devops-with-fast-api-postgresql-how-to-containerize-fast-api-application-with-docker-1jdb
### Unterschiede RUN CMD ENTRYPOINT
https://stackoverflow.com/questions/37461868/difference-between-run-and-cmd-in-a-dockerfile
### Beschreibung WORKDIR
https://stackoverflow.com/a/51066379
## POSTGRES
### Restore/Backup
https://stackoverflow.com/a/29913462
# Reference
[Explainshell](https://github.com/idank/explainshell)

54
docker-compose.yml Normal file
View file

@ -0,0 +1,54 @@
# specify the compose version
version: '3.7'
# Specify the services for our docker compose setup
services:
api:
build:
# path to the directory containing the Dockerfile
context: .
# Specify the image name
image: products_api
container_name: andi-app
# this volume is used to map the files and folders on the host to the container
# so if we change code on the host, code in the docker container will also be changed
volumes:
- .:/app
# Map port 8000 on the host to port 8000 on the container
ports:
- 8000:8000
# Specify the .env file path
env_file:
- ./.env
# Define a dependency on the "products_db" service, so it starts first
depends_on:
- products_db
products_db:
# specify the image name of our database
# If the image is not found in our local repository
# It will be pulled from docker registry that is Docker Hub
image: docker.io/postgres:latest
container_name: andi-db
# Mount a volume to persist postgreSQL data
volumes:
- postgres_data:/var/lib/postgresql/data/
environment: # Use environment variables for db configuration
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DATABASE=${POSTGRES_DATABASE}
# Define a volume for persisting postgreSQL data
volumes:
postgres_data:
# Source
# https://dev.to/mbuthi/devops-with-fast-api-postgresql-how-to-containerize-fast-api-application-with-docker-1jdb

7
main.py Normal file
View file

@ -0,0 +1,7 @@
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}

2
requirements.txt Normal file
View file

@ -0,0 +1,2 @@
fastapi
uvicorn