代做INFS3208 – Cloud Computing Programming Assignment Task II代做数据库编程

2024-09-11 代做INFS3208 – Cloud Computing Programming Assignment Task II代做数据库编程

School of Electrical Engineering and Computer Science

INFS3208 – Cloud Computing

Programming Assignment Task II (10 Marks)

Background:

With your Dockerfile in the first assignment, you can develop a simple PHP-based website and swiftly deploy the lightweight website to the customer’s machine without worrying about environmental issues (e.g., software and hardware compatibility issues). Now, your manager has decided to adopt micro-services architecture in this project, which is shown in Figure 1:

1. Micro-service A (Nginx) is a web server with load balancing to respond to client requests.

2. Micro-service B (order.php) accepts all online order requests. To handle massive orders in a short period, MS-B pushes all the order requests onto a message queue and only confirms the products that have been ordered.

3. Micro-service C (Redis) is used as a simple message queue (FIFO), storing all the messages sent by Micro-service A in a queue.

4. Micro-service D (process.php) will periodically process the orders in the queue in MS-C. For each order that pops out from the message queue in MS-C, MS-D will check the product availability by sending queries to the main product database.

5. Micro-service E (MariaDB) is the main product database that stores the information of all the products (stock, price, etc.).

6. Micro-service F (phpMyAdmin) is one of the most popular PHP-based MySQL administration tools, which  supports a wide range  of operations like managing databases, relations, tables, columns, indexes, permissions, users, etc. via a graphical user interface.

Figure 1: Micro-service architecture.

Task Description for docker-compose.yml File:

In this project, you are asked to write a docker-compose.yml file to orchestrate the FIVE containers (MariaDB, Redis, PHP-FPM, Nginx and phpMyAdmin). You should be able to upload your PHP websites to the remote directory in the container and immediately test the web development without any problem. You will be provided with four web pages (index.html, index.php, order.php, and process.php), which are used to test whether the deployed containers work properly. The expected results of the testing web pages are shown in Figures 2 - 7.

Objectives:

1. Define a Network for Communications among Containers (0.5 marks):

•   Define a network with the bridge driver named “mynet” to enable communications among all containers (0.5 marks).

•   The dependencies among the containers should also be defined (refer to Figure 8 in the Appendix).

2. Deploy the MariaDB Container (0.75 mark):

•   Use the latest MariaDB image to run the container and name it “mysql” (0.25 marks).

•   Define the environment variables for the database as follows (0.5 marks):

o MYSQL_ROOT_PASSWORD = MyDBRoot123

o MYSQL_DATABASE = cloud_computing

o MYSQL_USER = php

o MYSQL_PASSWORD = php

•   Connect the MariaDB container to the predefined network “mynet” .

3. Deploy the Redis Container (0.25 marks):

•   Use the latest Redis image to run the container and name it "myredis" (0.25 marks).

•   Connect the Redis container to the predefined network “mynet” .

4. Deploy the PHP-FPM Container (1.75 marks):

•   Build an image based on the Dockerfile in cca2/src/php/dockerfile. Please refer to the Task Description for Dockerfile below for details.

•   Use the built image to run the container and name it “myphp” (0.25 marks).

•   Expose port 9000 (0.5 marks).

•   Mount the directory of web pages (i.e., cca2/src) to the root directory of web pages in the container (i.e., /var/www/html) (0.5 marks).

•   As PHP-FPM needs to communicate with MariaDB and Redis, this container (“myphp”) should depend on “mysql” and “myredis” (0.5 marks).

•   Connect the PHP-FPM container to the predefined network “mynet” .

•   Please note: The official PHP-FPM does not include the extensions (e.g., Redis and  MySQL), the test pages order.php and process .php would not work without the extensions installed. Ensure the required extensions (i.e., redis and mysqli) are installed in the Dockerfile so that order.php and process.php can work properly.

5. Deploy the Nginx Container (1.75 marks):

•   Use the latest Nginx image to run the container and name it "mynginx" (0.25 marks).

•   Map the internal port 80 to the external port 8080 (0.5 marks).

•   Copy the configuration file to the correct location in this container (0.25 marks).

o  Copy  cca2/src/nginx.ini to  /etc/nginx/conf.d/default.conf

•   Mount the directory of webpages (i.e., cca2/src) to the root directory of webpages in the container (i.e., /var/www/html) (0.25 marks).

•   This container (“mynginx”) should depend on “myphp” (0.5 marks).

•   Connect the Nginx container to the predefined network “mynet” .

6. Deploy the phpMyAdmin Container (2 marks):

•   Use the latest phpMyAdmin image to run the container and name it “phpmyadmin” (0.25 marks).

•   Map the internal port 80 to the external port 8082 (0.5 marks).

•   Specify a MySQL host in the “phpmyadmin” container using the hostname of “mysql” . Details of the database cloud_computing created in the mysql” container should be visible on the phpMyAdmin page (1.25 mark).

•   Connect the phpMyAdmin container to the predefined network “mynet” .

7. Completeness (2 marks):

•   To test the completeness of your solution, visit all the testing web pages as shown in

Figure 2 - 7 (0.5 marks for each webpage among index.php, order.php, process.php and phpMyAdmin).

Task Description for Dockerfile:

To successfully start these services by the docker-compose file, you will need a Dockerfile to properly set up all necessary extensions in the “myphp” container. You should complete the Dockerfile located at cca2/src/php/dockerfile to set up a PHP 8.2 environment with specific extensions. The desired environment is a PHP 8.2 with FastCGI Process Manager (FPM) support and should  have  the capability to communicate efficiently with both Redis and MySQL databases.

Objectives for Dockerfile:

1.   Base Image:

•   Use an official PHP image with version 8.2 and FPM support (as the provided base image in the Dockerfile).

2.   PHP Extensions (1 mark):

•   Integrate the igbinary extension for optimized serialization/deserialization. Incorporate the redis extension to facilitate PHP-Redis communication. Include the mysqli extension for MySQL database support in PHP (1 mark).

•   Ensure that the installed extensions are properly configured and loaded every time the “myphp” container starts.

Preparation:

In this individual coding assignment, you will apply your knowledge of docker-compose instructions (in Lecture 5) and the related fields.

•   Firstly, you should read the Background and Task Descriptions to understand the background, motivations, objectives, and technical requirements.

•   Secondly, you should practise docker commands and Linux commands to manually orchestrate the containers on your VM instance. Afterwards, you need to convert those deployment steps into a docker-compose file with the correct instructions. Notice that the deployment of Nginx, PHP-FPM, Redis, and MariaDB on a VM is described in Practical 5, while the setup of PHP extensions and the installation of phpMyAdmin are NOT included. You need to investigate how to create a Dockerfile to ensure order.php and process.php can be successfully running and run a phpMyAdmin docker container by yourself.

•   Lastly, you need to write a dockerfile and a docker-compose.yml by converting the docker commands and Linux commands    into docker-compose instructions. All technical requirements need to be fully met to achieve full marks.

You can practise either on the GCP’s VM or your local machine (requiring Oracle VirtualBox or Windows Subsystem for Linux) if you are unable to access GCP.

Assignment Submission:

•   You must compress the docker-compose.yml file and the dockerfile.

•   The name of the compressed file should be named FirstName_LastName_StudentNo.zip” .

•   You must make an online submission to Blackboard before 3:00 PM on Friday, 13/09/2024.

•   Only one extension application could be approved due to medical conditions.

Main Steps:

Step 1:

Log in to your VM and change to your home directory

Step 2:

git clone https://github.com/csenw/cca2.git && cd cca2/src/php

Run this command to download the required configuration file and testing web pages.

In the folder cca2/src/php/, please write the dockerfile to ensure the order.php and process.php can be shown without any error (1 mark).

Step 3:

cd ../.. && ls

In the folder cca2/, please write your docker-compose.yml (7 marks).

Step 4:

docker-compose up -d

Run all the containers:

Step 5:

Test the completeness of your solution. Check each of the pages (2 marks).

Visit the static web page: http://external_ip:8080/index.html (ensure the Nginx is running)

Figure 2: A Nginx test page.

Test the PHP web page:http://external_ip:8080/index.php(0.5 marks)

Figure 3: A PHP-FPM test page.

Test the connection between PHP-FPM and Redis:  http://external_ip:8080/order.php (0.5 marks)

Figure 4: A Redis test page.

Test the connection between PHP-FPM and MariaDB:  http://external_ip:8080/process.php (0.5 marks)

Figure 5: MariaDB test page.

Test phpMyAdmin: http://external_ip:8082 (0.5 marks)

Figure 6: A phpMyAdmin login page.

The created database “cloud_computing” can be viewed in the sidebar after logging in.

Figure 7: A phpMyAdmin test page.