Skip to content

Commit

Permalink
Add Dockerfile & Modify github action file
Browse files Browse the repository at this point in the history
  • Loading branch information
parkm2ngyu00 committed Aug 17, 2024
1 parent a914d11 commit 9bb72d3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 9 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Django CI
name: Django CI/CD

on:
push:
Expand All @@ -8,13 +8,11 @@ on:

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -30,3 +28,24 @@ jobs:
run: |
cd backend
python manage.py test
docker:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main'
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/leafy-backend:${{ github.sha }}
19 changes: 19 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install --upgrade pip && pip install -r requirements.txt

# Copy project
COPY . /app/

# Run the application
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
6 changes: 6 additions & 0 deletions backend/categories/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path("", views.categories),
]
13 changes: 11 additions & 2 deletions backend/categories/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
from django.shortcuts import render
from rest_framework.decorators import api_view
from rest_framework.response import Response
from .models import Category

# Create your views here.
@api_view()
def categories(request):
return Response(
{
"ok": True,
"categories": Category.objects.all()
}
)
14 changes: 11 additions & 3 deletions backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@


# Application definition

INSTALLED_APPS = [
SYSTEM_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

THIRD_PARTY_APPS = [
'rest_framework',
]

CUSTOM_APPS = [
'users.apps.UsersConfig',
'rooms.apps.RoomsConfig',
'common.apps.CommonConfig',
Expand All @@ -46,9 +52,11 @@
'wishlists.apps.WishlistsConfig',
'bookings.apps.BookingsConfig',
'medias.apps.MediasConfig',
'direct_messages.apps.DirectMessagesConfig'
'direct_messages.apps.DirectMessagesConfig',
]

INSTALLED_APPS = SYSTEM_APPS + THIRD_PARTY_APPS + CUSTOM_APPS

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand Down
3 changes: 2 additions & 1 deletion backend/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path

urlpatterns = [
path('admin/', admin.site.urls),
path("categories/", include("categories.urls")),
]

0 comments on commit 9bb72d3

Please sign in to comment.