This commit is contained in:
zwnk 2025-01-16 20:59:27 -03:00
commit 4231a95fdb
5 changed files with 178 additions and 0 deletions

44
README.md Normal file
View file

@ -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```

40
build_and_run.sh Executable file
View file

@ -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

View file

@ -0,0 +1,8 @@
services:
backend:
volumes:
- /path/to/local/backend:/app
frontend:
volumes:
- /path/to/local/frontend:/app

45
docker-compose.yml Normal file
View file

@ -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:

View file

@ -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: