diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 031f019..0000000 --- a/.dockerignore +++ /dev/null @@ -1,8 +0,0 @@ -docker-compose.yaml -Dockerfile -.dockerignore -.env -.git -.gitignore -makefile -venv diff --git a/.gitignore b/.gitignore index 798e509..d3b77e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ +.gitignore .env - -# virtualenv +docker-compose.yaml +makefile venv/ - __pycache__ - data/ diff --git a/Dockerfile b/Dockerfile index d66e6d4..10f5083 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,20 +7,12 @@ ENV PYTHONUNBUFFERED 1 WORKDIR /transcendence RUN apt update && apt upgrade -y -RUN apt install -y vim COPY requirements.txt . +COPY manage.py . RUN python3 -m venv venv RUN venv/bin/pip3 install --upgrade pip RUN venv/bin/pip3 install --no-cache-dir -r requirements.txt -COPY . . - -# Collect static files during the build -RUN venv/bin/python manage.py collectstatic --noinput - EXPOSE 80 - -# CMD ["venv/bin/python", "manage.py", "runserver", "0.0.0.0:80"] -CMD ["daphne", "-b", "0.0.0.0", "-p", "80", "pong.asgi:application"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9cc4390 --- /dev/null +++ b/README.md @@ -0,0 +1,107 @@ +# 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 + ``` + +2. **Install required packages:** + + ```bash + sudo apt install apt-transport-https ca-certificates curl software-properties-common + ``` + +3. **Add Docker's official GPG key:** + + ```bash + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + ``` + +4. **Set up the Docker repository:** + + ```bash + sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + ``` + +5. **Update the package index again:** + + ```bash + sudo apt update + ``` + +6. **Install Docker CE:** + + ```bash + sudo apt install docker-ce + ``` + +7. **Check the Docker service status:** + + ```bash + sudo systemctl status docker + ``` + +8. **Add your user to the `docker` group to run Docker commands without `sudo`:** + + ```bash + sudo usermod -aG docker $USER + ``` + +9. **Log out and log back in to apply the group changes.** + +## Installing Docker Compose + +1. **Download Docker Compose:** + + ```bash + 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 + ``` + +2. **Apply executable permissions to the Docker Compose binary:** + + ```bash + sudo chmod +x /usr/local/bin/docker-compose + ``` + +3. **Verify the installation:** + + ```bash + docker-compose --version + ``` + +## Verifying Docker and Docker Compose Installation + +1. **Run a simple Docker container:** + + ```bash + docker run hello-world + ``` + + This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message. + +2. **Check Docker Compose version:** + + ```bash + docker-compose --version + ``` + + This command outputs the version of Docker Compose installed. + +Congratulations! You have successfully installed Docker and Docker Compose on your Ubuntu system. + +## Additional Resources + +- [Docker Documentation](https://docs.docker.com/) +- [Docker Compose Documentation](https://docs.docker.com/compose/) + + diff --git a/docker-compose.yaml b/docker-compose.yaml index 7265c83..351dbe4 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -29,9 +29,10 @@ services: command: /bin/sh -c "sleep 5 && venv/bin/python manage.py makemigrations --noinput && venv/bin/python manage.py migrate --noinput && + venv/bin/python manage.py collectstatic --noinput && venv/bin/daphne -b 0.0.0.0 -p 80 pong.asgi:application" volumes: - - ./pong:/transcendence/pong + - pong:/transcendence/pong ports: - "80:80" depends_on: @@ -53,6 +54,16 @@ services: volumes: postgres_data: driver: local + driver_opts: + type: none + device: ${POSTGRES_DATA_PATH} + o: bind + pong: + driver: local + driver_opts: + type: none + device: ${PROJECT_PATH} + o: bind networks: app-network: diff --git a/env_template b/env_template new file mode 100644 index 0000000..ffa026a --- /dev/null +++ b/env_template @@ -0,0 +1,15 @@ +# Django settings +SECRET_KEY= +DEBUG=True +DJANGO_ALLOWED_HOSTS=['*'] + +# PostgreSQL settings +POSTGRES_DB= +POSTGRES_USER= +POSTGRES_PASSWORD= + +DB_HOST=db +DB_PORT=5432 + +PROJECT_PATH=${PWD}/pong +POSTGRES_DATA_PATH=${PWD}/data/db diff --git a/makefile b/makefile deleted file mode 100644 index b73923b..0000000 --- a/makefile +++ /dev/null @@ -1,25 +0,0 @@ -.PHONY: all build down clean logs - -all: build - @echo "Building Docker images..." - @sudo mkdir -p data/db - @sudo docker compose -f ./docker-compose.yaml up --build - -down: - @echo "Stopping Docker containers..." - @sudo docker compose -f ./docker-compose.yaml down - -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 docker network rm $$(docker network ls -q) ;\ - sudo rm -rf data ;\ - -logs: - @echo "Displaying Docker logs..." - @sudo docker compose logs -f - -re: down clean build