commit 4231a95fdb53cfd495e81d4e20892f49c292f524 Author: zwnk Date: Thu Jan 16 20:59:27 2025 -0300 lll diff --git a/README.md b/README.md new file mode 100644 index 0000000..7b29066 --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +# What is it? + +This is just a small Vue.js demo app with a Django Rest API Backend that writes "Todos" to a Postgesql DB. +It serves as demo to on how to setup the containerization with docker. + +# How to use/deploy +## Simple Way + +Clone the 3 repos into the folder: + +* ```mkdir TestProject && cd TestProject``` +* ```git clone ssh://git@git.impstyle.com:222/test/demo-docker.git docker``` +* ```git clone ssh://git@git.impstyle.com:222/test/demo-fronted.git frontend``` +* ```git clone ssh://git@git.impstyle.com:222/test/demo-backend.git backend``` +git submodule add git@git.impstyle.com:222/test/demo-frontend.git frontend +git submodule add git@git.impstyle.com:222/test/demo-backend.git backend + +## SSH git clone via docker compose +Have a valid ssh key pair with the Git server provider. + +adjust the path to the frontend and backend repos inside `docker-compose_ssh_git.yml` + + +run ```docker compose build -f docker-compose_ssh_git.yml --ssh default``` + +this path is tricky because you have to do more to make the ssh keys working with the docker compose instance. + +## how to start the application +Adjust the .env files. + + +run: ```docker compose up --build``` + + +run: ```docker-compose exec backend python manage.py createsuperuser``` and create a user in the backend. + +the frontend runs on http://localhost:5173 + + +### local dev: +enables live updates of the code during development, no rebuild needed: + + +```docker-compose -f docker-compose.yml -f docker-compose.override.yml up``` diff --git a/build_and_run.sh b/build_and_run.sh new file mode 100755 index 0000000..d6d50d3 --- /dev/null +++ b/build_and_run.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Build images +docker build -t demo-frontend ../frontend +docker build -t demo-backend ../backend + +# Create network if it doesn't exist +docker network create demo-network || true + +# Start PostgreSQL +docker run -d \ + --name demo-db \ + --network demo-network \ + -e POSTGRES_DB=todo_db \ + -e POSTGRES_USER=postgres \ + -e POSTGRES_PASSWORD=postgres \ + -p 5432:5432 \ + -v postgres_data:/var/lib/postgresql/data \ + postgres:13 + +# Start Backend +docker run -d \ + --name demo-backend \ + --network demo-network \ + -e DB_NAME=todo_db \ + -e DB_USER=postgres \ + -e DB_PASSWORD=postgres \ + -e DB_HOST=demo-db \ + -e DB_PORT=5432 \ + -e DEBUG=1 \ + -p 8000:8000 \ + demo-backend + +# Start Frontend +docker run -d \ + --name demo-frontend \ + --network demo-network \ + -e VITE_API_URL=http://localhost:8000/api \ + -p 5173:5173 \ + demo-frontend diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 0000000..9e78ec2 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,8 @@ +services: + backend: + volumes: + - /path/to/local/backend:/app + + frontend: + volumes: + - /path/to/local/frontend:/app diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3f51920 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +services: + db: + image: postgres:13 + volumes: + - postgres_data:/var/lib/postgresql/data + environment: + - POSTGRES_DB=todo_db + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + ports: + - "5432:5432" + + backend: + build: + context: ${PWD}/../backend/ + # dockerfile: Dockerfile + # entrypoint: ["${PWD}/../backend/entrypoint.sh"] + command: sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000" + ports: + - "8000:8000" + environment: + - DB_NAME=todo_db + - DB_USER=postgres + - DB_PASSWORD=postgres + - DB_HOST=db + - DB_PORT=5432 + - DEBUG=1 + depends_on: + - db + + frontend: + build: + context: ${PWD}/../frontend + # dockerfile: Dockerfile +# entrypoint: ["${PWD}/../frontend/entrypoint.sh"] + command: sh -c "npm run dev -- --host 0.0.0.0" + ports: + - "5173:5173" + environment: + - VITE_API_URL=http://localhost:8000/api + depends_on: + - backend + +volumes: + postgres_data: diff --git a/docker-compose_ssh_git.yml b/docker-compose_ssh_git.yml new file mode 100644 index 0000000..e37b29a --- /dev/null +++ b/docker-compose_ssh_git.yml @@ -0,0 +1,41 @@ +services: + db: + image: postgres:13 + volumes: + - postgres_data:/var/lib/postgresql/data + environment: + - POSTGRES_DB=todo_db + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + ports: + - "5432:5432" + + backend: + build: + context: ssh://git@git.impstyle.com:222/test/demo-backend.git#main # Replace with your backend repo URL + dockerfile: Dockerfile + ports: + - "8000:8000" + environment: + - DB_NAME=todo_db + - DB_USER=postgres + - DB_PASSWORD=postgres + - DB_HOST=db + - DB_PORT=5432 + - DEBUG=1 + depends_on: + - db + + frontend: + build: + context: ssh://git@git.impstyle.com:222/test/demo-frontend.git#main # Replace with your frontend repo URL + dockerfile: Dockerfile + ports: + - "5173:5173" + environment: + - VITE_API_URL=http://localhost:8000/api + depends_on: + - backend + +volumes: + postgres_data: