Skip to content
Snippets Groups Projects
Commit a3ad0a5d authored by mohamad.moussa's avatar mohamad.moussa
Browse files

Add README

parent d64331e2
No related branches found
No related tags found
No related merge requests found
# Lab : Distributed Algorithm - Message Passing
## Overview
This project implements a distributed algorithm for communication between nodes in a network using **Sockets**. The code is designed to be containerized using Docker and deployed on different hosts, such as AWS VMs.
## Prerequisites
- Python 3.x
- Docker and Docker Compose
- AWS account
- Dockerhub account
## Initial Setup
1. **Create Virtual Machines**:
- Create *n* EC2 instances on Amazon.
- Save the private IP addresses in the file `instance_privateIPs.txt`
2. **Install Docker and Docker Compose**:
- Use the provided script `install-docker.sh` to install Docker and Docker Compose on each VM. **Note:** This script is for installing Docker and Docker Compose on Ubuntu.
- First, upload the `install-docker.sh` script to each VM.
- Run the following commands to make the script executable and run it
```bash
chmod +x install-docker.sh
./install-docker.sh
```
3. **Create a Docker Swarm**:
- On one of the VMs, initialize the Docker Swarm and note the join token:
```bash
docker swarm init
```
- Copy the `docker swarm join` command displayed after initialization.
- On all other VMs, join the Docker Swarm using the command copied from the previous step:
```bash
docker swarm join --token <SWARM_JOIN_TOKEN> <VM1_IP>:2377
```
## Building and Pushing Docker Image
To deploy your distributed algorithm, you need to create and build a Docker image using the provided `Dockerfile` and push it to Docker Hub. Follow these steps:
1. **Prepare Dockerfile**:
- Use the provided `Dockerfile` to define the specifications of your Docker image. Ensure that the source code is on a machine with the same CPU architecture as your target devices. For simplicity, you can use one of the VMs.
2. **Build Docker Image**:
- Navigate to the directory containing your Dockerfile and execute the following command to build the Docker image. Replace `<your_image_name>` with a suitable name for your image.
```
docker build -t <your_image_name> .
```
3. **Push to Docker Hub**:
- Log in to your Docker Hub account using the command:
```
docker login
```
- Push your Docker image to Docker Hub using the following command. Replace `<your_image_name>` with the name of the image you built and `<your_dockerhub_username>` with your Docker Hub username.
```
docker tag <your_image_name> <your_dockerhub_username>/<your_image_name>:<tag>
docker push <your_dockerhub_username>/<your_image_name>:<tag>
```
**Note:** Ensure that the source code is on a machine with the same CPU architecture as your target device. For the sake of simplicity, use one of the VMs.
## Deployment
These deployment steps should be performed on the master node of the Docker Swarm:
1. **Create Neighbors Configuration**:
- Create a `neighbors.json` file that specifies the neighbors for each node in your distributed algorithm network.
2. **Create Docker Config**:
- Use the `docker config create` command to create a Docker config from your `neighbors.json` file:
```bash
docker config create <config_name> neighbors.json
```
3. **Generate Docker Compose File**:
- Use the provided script `generate-docker-compose.py` to generate a Docker Compose configuration for deploying your distributed algorithm.
- Before running the script, ensure to replace line 10 in the script with the URL of your previously created Docker image:
```python
image = "<Docker Hub ID>/<registry ID>:latest"
```
- Additionally, replace lines 12 and 38 in the script `generate-docker-compose.py` with the `<config_name>` created
- Run the script:
```bash
python generate-docker-compose.py
```
4. **Deploy the Stack**:
- Once the Docker Compose file is generated, deploy the stack to your Docker Swarm using the following command:
```bash
docker stack deploy -c docker-compose.yml <stack_name>
```
Replace `<stack_name>` with a suitable name for your Docker stack.
5. **Monitor Deployment**:
- Monitor the deployment and check the logs of individual containers
## Troubleshooting
- Review container logs
- **Verify that the required ports are open in the security groups to enable communication between nodes**.
#!/bin/bash
# Set non-interactive mode for apt-get
export DEBIAN_FRONTEND=noninteractive
# Update package list and install prerequisites
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
# Set up Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add Docker's official APT repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update the package list with the new repository and install Docker packages
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Add the current user to the Docker group
sudo groupadd docker || true
sudo usermod -aG docker $USER
# Download Docker Compose binary and set permissions
sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Inform the user to log out and log back in for the group changes to take effect
echo "Docker and Docker Compose installation is complete."
echo "Please log out and log back in to apply the Docker group changes."
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment