From b5bc219cd625e33582e7f284fcce130a0630b1a8 Mon Sep 17 00:00:00 2001 From: Adrien Audebert Date: Thu, 18 Jul 2024 13:55:01 +0200 Subject: [PATCH] update --- Dockerfile | 8 ------- README.md | 36 ++++++++++++++++++++++++++++++ docker-compose.yaml | 5 +++-- env_template | 5 ++++- helloworld/views.py | 2 +- makefile | 54 +++++++++++++++++++++++++++++++-------------- 6 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 README.md diff --git a/Dockerfile b/Dockerfile index ce4e9e3..e551db2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..375af57 --- /dev/null +++ b/README.md @@ -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 + diff --git a/docker-compose.yaml b/docker-compose.yaml index d67d45c..0c2b571 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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: diff --git a/env_template b/env_template index eaef9b2..6cfd911 100644 --- a/env_template +++ b/env_template @@ -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 diff --git a/helloworld/views.py b/helloworld/views.py index ceff077..9faf885 100644 --- a/helloworld/views.py +++ b/helloworld/views.py @@ -1,4 +1,4 @@ from django.http import HttpResponse def index(request): - return HttpResponse("Hello, CHAKIB!") + return HttpResponse("Hello, QWER!") diff --git a/makefile b/makefile index e892915..ca790f2 100644 --- a/makefile +++ b/makefile @@ -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