diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..733c07d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +__pycache__/ +*.pyc +*.pyo +*.pyd +.Python +env/ +venv/ +.venv/ +.git/ +.gitignore +*.log +*.sqlite3 +*.py[cod] +*.env +.DS_Store +.idea/ +.vscode/ \ No newline at end of file diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..db784a8 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,30 @@ +name: Docker Build and Push + +on: + push: + branches: ["master"] + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: rubonrwra12/taskmanagersystem:latest diff --git a/.gitignore b/.gitignore index 7c460c4..dd7d843 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ db.sqlite3 # Environments .env +.env.docker .venv/ venv/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..62283f2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use the official Python image +FROM python:3.12-slim + +# Set environment variables +ENV PYTHONUNBUFFERED=1 \ + DJANGO_SETTINGS_MODULE=TaskManagerSystem.settings + +# Set working directory +WORKDIR /app + +# Copy and install Python dependencies +COPY requirements.txt . +RUN pip install --upgrade pip \ + && pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application code +COPY . . + +# Expose Django port +EXPOSE 8000 + +# Run the application with Gunicorn +CMD ["gunicorn", "TaskManagerSystem.wsgi:application", "--bind", "0.0.0.0:8000"] diff --git a/TaskManagerSystem/settings.py b/TaskManagerSystem/settings.py index 6d0fc22..ff72cf1 100644 --- a/TaskManagerSystem/settings.py +++ b/TaskManagerSystem/settings.py @@ -18,7 +18,7 @@ DEBUG = config("DEBUG", default=True, cast=bool) ALLOWED_HOSTS = config( "ALLOWED_HOSTS", - default="localhost,127.0.0.1", + default="localhost,127.0.0.1,0.0.0.0", cast=lambda v: [s.strip() for s in v.split(",")], ) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..223a26a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3.9' + +services: + web: + build: . + container_name: taskmanagersystem + command: gunicorn TaskManagerSystem.wsgi:application --bind 0.0.0.0:8000 + ports: + - "8000:8000" + volumes: + - .:/app + env_file: + - .env.docker + depends_on: + - db + + db: + image: postgres:17 + container_name: postgres-db + restart: always + volumes: + - postgres_data:/var/lib/postgresql/data + environment: + POSTGRES_DB: ${DB_NAME} + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + ports: + - "5432:5432" + +volumes: + postgres_data: diff --git a/requirements.txt b/requirements.txt index 16dddb9..b498bf1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,11 +12,12 @@ djangorestframework==3.15.2 djangorestframework_simplejwt==5.4.0 drf-nested-routers==0.94.1 drf-yasg==1.21.10 +gunicorn==23.0.0 idna==3.10 inflection==0.5.1 packaging==24.2 pip-tools==7.4.1 -psycopg2==2.9.10 +psycopg2-binary==2.9.10 PyJWT==2.10.1 pyproject_hooks==1.2.0 python-decouple==3.8