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

My solution #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions .infrastructure/busybox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: todoapp
spec:
containers:
- name: busybox
image: ikulyk404/busyboxplus:curl
args:
- sleep
- "1000"
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: app
namespace: todoapp
spec:
containers:
- name: todoapp
image: lavryniuk/todoapp:3.0.0
ports:
- containerPort: 8081
livenessProbe:
httpGet:
path: api/health
port: 8081
initialDelaySeconds: 10
periodSeconds: 5
readinessProbe:
httpGet:
path: api/ready
port: 8081
initialDelaySeconds: 5
periodSeconds: 5
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG PYTHON_VERSION=3.8
FROM python:${PYTHON_VERSION}

# Set the working directory
WORKDIR /app
COPY . .

RUN pip install --upgrade pip && \
pip install -r src/requirements.txt

EXPOSE 8081

# Run database migrations and start the Django application
ENTRYPOINT ["sh", "-c", "python src/manage.py migrate && python src/manage.py runserver 0.0.0.0:8081"]
56 changes: 19 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,37 @@
# Django ToDo list

This is a todo list web application with basic features of most web apps, i.e., accounts/login, API, and interactive UI. To do this task, you will need:
This is a todo list web application with basic features of most web apps, i.e., accounts/login, API, and interactive UI

- CSS | [Skeleton](http://getskeleton.com/)
- JS | [jQuery](https://jquery.com/)
![ToDo logo](https://i.ibb.co/YDdCcZR/2.png)

## Explore

Try it out by installing the requirements (the following commands work only with Python 3.8 and higher, due to Django 4):
## Setup

1. You need apply all manifests
```
pip install -r requirements.txt
kubectl apply -f .infrastructure
```

Create a database schema:

2. To test app using browser you need write the next command
```
python manage.py migrate
kubectl port-forward pod/app 8081:8081 -n todoapp
```

And then start the server (default is http://localhost:8000):

3. Open browser via link
```
python manage.py runserver
http://localhost:8081/
```

Now you can browse the [API](http://localhost:8000/api/) or start on the [landing page](http://localhost:8000/).

## Task
4. To test using busybox and curl, you need to know the ip address of todoapp pod
```
kubectl get pods -o wide -n todoapp
```

Create a kubernetes manifest for a pod which will containa ToDo app container:
5. The next command enable you enter busybox
```
kubectl exec -it -n todoapp busybox -- sh
```

1. Fork this repository.
1. Create a simple `Dockerfile` for the ToDo application
7. Add readiness endpoint code to `api` of the appliation (modify `api/views.py` and `api/urls.py`)
1. Add liveness endpoint cide to `api` of the application (modify `api/views.py` and `api/urls.py`)
1. Build your image and push to your personal Docker Hub account into the `todoapp` repository with the `3.0.0` tag (`todoapp:3.0.0`)
1. All manifests should be located under `.infrastructure` folder
1. Create a `manifest` which can be used to create a namespace. File should be named `namespace.yml` and should contain the following content:
6. Inside busybox write the next command. To get out write 'exit'
```
apiVersion: v1
kind: Namespace
metadata:
name: todoapp
curl <pod ip adress>:8081
```
8. Creata a pod `manifest` which will start a `ikulyk404/busyboxplus:curl` container in a cluster. File should be named `busybox.yml`.
1. Create a pod `manifest` which will be using previously created image with tag `{yourname}/todoapp:3.0.0`. File should be named `todoapp-pod.yml`.
1. ToDo app pod `manifest` should have a readiness probe configured
1. ToDo app pod `manifest` should have a liveness probe configured
1. `README.md` file should contain instructions on how to apply all manifests
1. `README.md` file should contain instructions on how to test ToDo application using the `port-forward` command
1. `README.md` file should contain instructions on how to test application using the
`busyboxplus:curl` container
1. Create PR with your changes and attach it for validation on a platform.
2 changes: 2 additions & 0 deletions src/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

app_name = "api"
urlpatterns = [
path("ready/", views.readiness, name="readiness"),
path("health/", views.health_check, name="liveness"),
path("", include(router.urls))
]
14 changes: 12 additions & 2 deletions src/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from api.serializers import TodoListSerializer, TodoSerializer, UserSerializer
from lists.models import Todo, TodoList

from django.http import HttpResponse
from django.http import HttpResponse, JsonResponse
from django.utils import timezone
import time

Expand Down Expand Up @@ -55,4 +55,14 @@ class TodoViewSet(viewsets.ModelViewSet):
def perform_create(self, serializer):
user = self.request.user
creator = user if user.is_authenticated else None
serializer.save(creator=creator)
serializer.save(creator=creator)

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

def health_check(request):
return JsonResponse({"status": "Healthy"}, status=200)