In this assignment, you will containerize a Django application, deploy it using Kubernetes (Minikube), and set up GitHub Actions to automate testing.
-
Create a docker file
- Use a python base image
- Run this command to install all python package
pip install -r requirements.txt
- The command for running the Django server
python blog_project/manage.py runserver 0.0.0.0:8000
-
Build you docker image
-
Create a Docker container
-
Create a kubernetes deployment yaml file, that uses the Docker image from step 2
- remember to export port 8000
-
Crete a kubernetes service yaml file
-
Apply the kubernetes development and servics configuration
-
Create a Github Action workflow for testing
- The workflow should only work when creating a pull request to the main branch
- Use a postgres db service with these enviroment variables
POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: django_db
- Remember to use pip to install all package
pip install -r requirements.txt
- The last step to run the test you need to run two commands
run: | python blog_project/manage.py migrate python blog_project/manage.py test
-
Create pull request
-
Create docker compose yaml configuration
- Add db service
- db should use an postgres image
- Add this environment variable to the Db service
POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: django_db
- Add a volume that the db service can use
- with this /var/lib/postgresql/data
- Add web service
- Use local docker image
- the command to run the django server
python blog_project/manage.py runserver 0.0.0.0:8000
- Dont forget to expose container port 8000
- It should depend on db service
- Add db service
-
Build and start container
- When its running run this command in a seperate terminal
docker-compose exec web python blog_project/manage.py migrate
- Create django admin user
docker-compose exec web python blog_project/manage.py createsuperuser
- try to login
http://localhost:8000/admin/
- docker-compose.yml line 1
- Dockerfile line 2