To find the specifications, please click on the following link
Name : NDIAYE
Username: Mansour
Eazytraining's DevOps bootcamp
Made the 23rd March 2023
POZOS is an IT company located in France and develops software for High School. The innovation department want to disrupt the existing infrastructure to ensure that it can be scalable, easily deployed with a maximum of automation.
POZOS wants you to build a POC to show how docker can help you and how much this technology is efficient. For this POC, POZOS will give you an application and want you to build a "decouple" infrastructure based on Docker. Currently, the application is running on a single server with any scalability and any high availability. When POZOS needs to deploy a new release, every time some goes wrong.
In conclusion, POZOS needs agility on its software farm.
The company wants to build an application able to show student list with their ages.
The current application has two modules :
- A REST API (with basic authentication needed) who send the desire list of the student based on JSON file
- A web app written in HTML + PHP who enable end-user to get a list of students
The objectives of this project are :
- Build a docker based environment to improve the existing application into deployment,
- Add versioning to the infrastructure released,
- Address best practice when implementing docker infrastructure
- Build Infrastructure As Code
My work has to :
- Build one container for each module
- Make containers created to interact each other
- Provide a private registry to deploy the image built to the delivery
In the delivery, you will have three files : Dockerfile, docker-compose.yml and docker-compose_registry.yml.
- docker-compose.yml : To launch the application API and Website
- docker-compose-registry.yml : To launch the local registry and its frontend
- simple_api/student_age.py : Contains the source code of the python API
- simple_api/student_age.json : Contains student name with age and JSON format
- index.php : PHP page for the user interface with the service to list students with their age
- simple_api/Dockerfile : Build the API image based with the source code and personnalised parameters
- Dockerfile to build the API image :
FROM python:2.7-stretch
MAINTAINER mndiaye (mndiayepro97@gmail.com)
RUN apt-get update -y && apt-get install python-dev python3-dev libsasl2-dev python-dev libldap2-dev libssl-dev -y && \
pip install flask==1.1.2 flask_httpauth==4.1.0 flask_simpleldap python-dotenv==0.14.0
COPY * /
VOLUME /data
EXPOSE 5000
CMD [ "python", "./student_age.py" ]
- Clone the current application project and add Dockerfile into it :
git clone https://github.com/diranetafen/student-list.git
cd student-list/simple-api/
docker build . -t student_list_api.img
docker images
- Create a bridge-type network for the two containers to interact each other by their names :
docker network create student_list_network --driver=bridge
docker network ls
- Run the API image as a container :
docker run --rm -d --name=student_list_api --network=student_list_network -v ./simple_api:/data student_list_api.img
Firstly, on the built image, port 5000 was already exposed so I didn't had to add port argument on the command.
Secondly, I mounted the volume ./simple_api on the local directory to the /data of the internal container, so that the JSON file student_age.json will be accessible inside the api container.
- Update the
index.php
file :
You need to update the following line before running the website container to make api_ip_or_name and port fit your deployment $url = 'http://<api_ip_or_name:port>/pozos/api/v1.0/get_student_ages'
Given that a bridge network permit two containers to interact each other via names, we can easily use the api container's name to make the API accessible by the website.
- Run the frontend webapp container :
docker run --rm -d --name=webapp_student_list -p 80:80 --network=student_list_network -v ./website:/var/www/html -e USERNAME=toto -e PASSWORD=python php:apache
docker ps
- Test the API through the website :
- By using command line :
docker exec -it webapp_student_list curl -u toto:python -X GET http://student_list_api:5000/pozos/api/v1.0/get_student_ages
- By using a web browser :
For example, I'm using VirtualBox VMs, so I can add port forwarding option via VirtualBox to be able to access the Website.
Now, I can access the website on http://127.0.0.1:8080
directly on my local machine.
- Clean the workspace
Each when work has been done successfully, we can clean the workspace. Thanks to the --rm
argument used while creating containers, they will be removed automatically when they stop.
docker stop student_list_api
docker stop webapp_student_list
docker network rm student_list_network
Given that the Build and Test part has been successfully, we can now composerize our infrastructure into a docker-compose.yml
file.
- Write the docker-compose file and run the application (api + webapp)
docker-compose -f docker-compose.yml up -d
In the docker-compose file, I added an option to permit which container must start first. In this case, the API container must start first because the webapp depends on it.
Now, the application works :
- Create a registry and its frontend
To create a private registry, I used registry:2
image and joxit/docker-registry-ui:static
for its frontend GUI and passed some environment variables :
docker-compose -f docker-compose_registry.yml up -d
- Push the image and test the GUI
We have to tag and push the image as below (:latest
is optional) :
docker tag student_list_api.img:latest pozos-registry:5000/pozos/student_list_api.img:latest
docker push pozos-registry:5000/pozos/student_list_api.img:latest
Here is the delivery of my Docker mini-project, hope you enjoy it !