Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

аа #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

аа #51

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .infrastructure/busybox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: todoapp
spec:
containers:
- name: busybox
image: ikulyk404/busyboxplus:curl
command: [ "sleep", "3600" ]
4 changes: 4 additions & 0 deletions .infrastructure/namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: todoapp
23 changes: 23 additions & 0 deletions .infrastructure/todoapp-pod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Pod
metadata:
name: todoapp
namespace: todoapp
spec:
containers:
- name: todoapp
image: zaebalsya13/todoapp:3.0.0
ports:
- containerPort: 8000
readinessProbe:
httpGet:
path: /api/readiness/
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /api/liveness/
port: 8000
initialDelaySeconds: 10
periodSeconds: 20
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.8-slim

WORKDIR /app

COPY src/requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY src/ .

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
16 changes: 16 additions & 0 deletions INSTRUCTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Instructions for ToDo App Deployment and Testing

## Prerequisites
Ensure you have the following installed:
- Kubernetes cluster (Minikube, Kind, or other).
- kubectl (configured to access your cluster).
- Docker (to build and push images).

---

## Steps to Deploy the Application

### 1. Create a Namespace
Apply the namespace manifest to create the `todoapp` namespace:
```bash
kubectl apply -f .infrastructure/namespace.yml
5 changes: 4 additions & 1 deletion src/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.urls import include, path
from . import views
from rest_framework.routers import DefaultRouter

from api import views
Expand All @@ -10,5 +11,7 @@

app_name = "api"
urlpatterns = [
path("", include(router.urls))
path("", include(router.urls)),
path("liveness/", views.liveness, name="liveness"),
path("readiness/", views.readiness, name="readiness"),
]
10 changes: 10 additions & 0 deletions src/api/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.auth.models import User
from django.http import JsonResponse
from rest_framework import permissions, viewsets

from api.serializers import TodoListSerializer, TodoSerializer, UserSerializer
Expand All @@ -8,6 +9,15 @@
from django.utils import timezone
import time

def liveness(request):
return JsonResponse({"status": "alive"})
def readiness(request):
try:
Todo.objects.exists()
return JsonResponse({"status": "ready"})
except Exception:
return JsonResponse({"status": "not ready"}, status=503)

class IsCreatorOrReadOnly(permissions.BasePermission):
"""
Object-level permission to only allow owners of an object to edit it.
Expand Down