This commit is contained in:
Adrien Audebert 2024-07-18 13:55:01 +02:00
parent dafa62612e
commit b5bc219cd6
6 changed files with 81 additions and 29 deletions

View File

@ -3,7 +3,6 @@ FROM python:3.12.4
WORKDIR /ft_transcendence
RUN apt update && apt upgrade -y
RUN apt install -y vim
COPY requirements.txt .
COPY manage.py .
@ -12,11 +11,4 @@ RUN python3 -m venv venv
RUN venv/bin/pip3 install --upgrade pip
RUN venv/bin/pip3 install --no-cache-dir -r requirements.txt
COPY . .
#RUN venv/bin/python3 manage.py migrate --noinput
#RUN venv/bin/python manage.py collectstatic --noinput
EXPOSE 8000
CMD ["venv/bin/python", "manage.py", "runserver", "0.0.0.0:8000"]

36
README.md Normal file
View File

@ -0,0 +1,36 @@
# Installing Docker and Docker Compose on Ubuntu
This guide will help you install Docker and Docker Compose on an Ubuntu system.
## Prerequisites
- A system running Ubuntu (preferably 20.04 LTS or later)
- A user account with `sudo` privileges
## Installing Docker
1. **Update the package index:**
```bash
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce
sudo systemctl status docker
sudo usermod -aG docker $USER
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker compose version

View File

@ -27,6 +27,7 @@ services:
container_name: backend
restart: always
command: /bin/sh -c "sleep 5 && venv/bin/python3 manage.py migrate --noinput && venv/bin/python3 manage.py runserver 0.0.0.0:8000"
#&& venv/bin/python manage.py collectstatic --noinput
volumes:
- helloword_project:/ft_transcendence/helloworld
ports:
@ -52,13 +53,13 @@ volumes:
driver: local
driver_opts:
type: none
device: /home/motoko/ft_transcendence/data/db
device: ${POSTGRES_DATA_PATH}
o: bind
helloword_project:
driver: local
driver_opts:
type: none
device: /home/motoko/ft_transcendence/helloworld
device: ${PROJECT_PATH}
o: bind
networks:

View File

@ -4,9 +4,12 @@ DEBUG=True
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
# PostgreSQL settings
POSTGRES_DB=
POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=
DB_HOST=db
DB_PORT=5432
PROJECT_PATH=${PWD}/helloworld
POSTGRES_DATA_PATH=${PWD}/data/db

View File

@ -1,4 +1,4 @@
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, CHAKIB!")
return HttpResponse("Hello, QWER!")

View File

@ -1,24 +1,44 @@
.PHONY: all build down clean logs
COMPOSE_FILE=docker-compose.yaml
COMPOSE=docker compose -f $(COMPOSE_FILE)
CONTAINER=$(c)
all: build
@echo "Building Docker images..."
sudo mkdir -p $$HOME/ft_transcendence/data/db
sudo docker compose -f ./docker-compose.yaml up -d --build
up:
sudo mkdir -p $$PWD/data/db
$(COMPOSE) build
$(COMPOSE) up -d $(CONTAINER)
build:
$(COMPOSE) build $(CONTAINER)
start:
$(COMPOSE) start $(CONTAINER)
stop:
$(COMPOSE) stop $(CONTAINER)
down:
@echo "Stopping Docker containers..."
sudo docker compose -f ./docker-compose.yaml down
$(COMPOSE) down $(CONTAINER)
clean:
@echo "Cleaning up Docker resources..."
sudo docker stop $$(docker ps -qa);\
sudo docker rm $$(docker ps -qa);\
sudo docker rmi $$(docker image ls -q);\
sudo docker volume rm $$(docker volume ls -q);\
sudo rm -rf $$HOME/ft_transcendence/data/db ;\
destroy:
$(COMPOSE) down -v --rmi all
sudo rm -rf $$PWD/data/db
logs:
@echo "Displaying Docker logs..."
sudo docker compose logs -f
$(COMPOSE) logs -f $(CONTAINER)
ps:
$(COMPOSE) ps
help:
@echo "Usage:"
@echo " make build [c=service] # Build images"
@echo " make up [c=service] # Start containers in detached mode"
@echo " make start [c=service] # Start existing containers"
@echo " make down [c=service] # Stop and remove containers"
@echo " make destroy # Stop and remove containers and volumes"
@echo " make stop [c=service] # Stop containers"
@echo " make restart [c=service] # Restart containers"
@echo " make logs [c=service] # Tail logs of containers"
@echo " make ps # List containers"
@echo " make help # Show this help"
re: down clean build