- Install python and minikube
- Start minikube:
minikube start --driver docker
- Prepare a virtual environment:
python -m venv venv
pip install flask "psycopg[binary]" python-dotenv
- Start the database:
docker compose up -d postgres-db
- Obtain the docker container ID:
docker ps
- Run a shell in the container:
docker exec -it <ID> /bin/bash
- Connect to the postgres shell
psql -U postgres
- Switch to the site database:
\c site
- Create a table in the database. Refer to postgres-init.sql for sample SQL commands.
- Check the table's existence:
\dt
- Integrate the database with the API and test it
- Build the API docker image by hand:
docker build -t devopsdemo:latest .
- Run the
devopsdemo
image, either by hand withdocker run
or via compose as a new service - Move the build command into the docker-compose service
- Run the new compose service:
docker compose up -d site
graph TD;
d["Database (site)"]
s["Schema (public)"]
t["Table (important_data)"]
d --> Users;
d --> Views;
d --> etc;
d --> s;
s --> t;
t --> data;
- Added a volume to persist postgres data in the docker compose:
<snip>
postgres-db:
volumes:
# /var/lib/postgresql/data is the location of the actual database files
- pg-data:/var/lib/postgresql/data
<snip>
volumes:
pg-data:
- Postgres will load the init file on startup only if there is no data in the DB
- Healthcheck should specify the condition to wait for:
depends_on:
postgres-db:
condition: service_healthy