-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Docker Images Workflow for main branch to deploy services.
- Loading branch information
Showing
10 changed files
with
309 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# cdaprod/cda.deploy-to-swarm | ||
## .github/workflows/. | ||
### Build and Push Docker Images Workflow (build-latest.yml) | ||
|
||
This workflow is triggered on pushes or pull requests to the main branch that modify files in the minio, weaviate, or nginx directories. It can also be manually initiated. The workflow’s primary function is to build and push Docker images for specified services to Docker Hub. | ||
|
||
#### Triggers: | ||
- Pushes or pull requests affecting minio/**, weaviate/**, nginx/**. | ||
- Manual (workflow_dispatch). | ||
#### Jobs: | ||
- build-and-push: Executes the following steps for each service: | ||
- Checkout code: Fetches the latest version of the code from the repository. | ||
- Set up Docker Buildx: Prepares the environment for building multi-platform Docker images. | ||
- Login to Docker Hub: Authenticates to Docker Hub using credentials stored in GitHub secrets. | ||
- Build and push images: Constructs the Docker image for each service (MinIO, Weaviate, NGINX) and uploads them to Docker Hub, tagging them as latest and targeting linux/amd64 and linux/arm64 platforms. | ||
|
||
### Deploy Services Workflow (deploy-latest.yml) | ||
|
||
This workflow is set to run upon the successful completion of the "Build and Push Docker Images" workflow on the main branch, facilitating the deployment of services to Docker Swarm. It can also be initiated manually. | ||
|
||
#### Triggers: | ||
- Completion of the "Build and Push Docker Images" workflow (workflow_run). | ||
- Manual (workflow_dispatch). | ||
#### Jobs: | ||
- deploy: Executes the deployment process, encompassing the following actions: | ||
- Checkout Repository: Obtains the most current codebase from the repository. | ||
- Log in to Docker Hub: Authenticates to Docker Hub to ensure access to Docker images. | ||
- Deploy Stacks: Utilizes docker stack deploy with specific docker-compose files for deploying each service stack (MinIO, Weaviate, NGINX) to Docker Swarm. For MinIO, it sets environment variables like MINIO_ROOT_USER and MINIO_ROOT_PASSWORD from GitHub secrets for secure deployment. | ||
|
||
### Best Practices and Considerations | ||
|
||
- Ensure version specificity in Docker tags beyond latest for predictable deployments. | ||
- Keep sensitive data like passwords and API keys secure using GitHub secrets. | ||
- Consider deployment strategies and rollback plans for maintaining service availability. | ||
- Documentation within README.md should include clear descriptions of each workflow and step, ensuring maintainability and clarity for team members. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM jupyter/datascience-notebook | ||
|
||
# Install Edge TPU Python API library | ||
RUN echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list && \ | ||
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - && \ | ||
sudo apt-get update && \ | ||
sudo apt-get install libedgetpu1-std python3-edgetpu | ||
|
||
# Install Clients | ||
RUN pip install minio weaviate-client transformers openai langchain | ||
|
||
# Install requirements for OpenAI and LangChain integration | ||
RUN pip install pydantic bs4 poetry fastapi uvicorn docker unstructured |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## Dockerfile | ||
|
||
To deploy docker jupyter lab container run the following commands on docker swarm leader (rpi-swarm runner), which is connected to Google Coral TPU | ||
|
||
`docker build -t cda-jupyter .` | ||
|
||
`docker run -it --privileged -v /dev/bus/usb/001/002:/dev/bus/usb -p 8888:8888 cda-jupyter` | ||
|
||
## Docker Compose | ||
|
||
- USB Access Volume: The first volume binding ../usb/001/002:/dev/bus/usb/001/002 assumes you have a specific USB device directory structure (../usb/001/002) on the host system that you want to map directly to the container. This path might need adjustment based on your host’s actual USB device path. It’s crucial for giving the Docker container access to the Coral TPU. | ||
- Persistent Data Volume for Notebooks: The jupyter_data volume is defined to persist your Jupyter notebooks and any other important data. It is mapped to /home/jovyan/work inside the container, which is the default working directory for Jupyter notebooks in the Docker image. The driver_opts section under the volumes definition sets up a bind mount from a local directory (${PWD}/jupyter_data) to the volume, ensuring data persistence across container restarts or rebuilds. | ||
|
||
### Running the Docker Compose File | ||
|
||
To deploy your service with these volumes, navigate to the directory containing your docker-compose.jupyter.yaml and run: | ||
|
||
`docker-compose -f docker-compose.jupyter.yaml up --build` | ||
|
||
This command builds the image if not present and starts the JupyterLab service, making it accessible at http://localhost:8888. Notebooks and other data saved in /home/jovyan/work inside the container will persist in the jupyter_data volume on your host machine. | ||
|
||
Important Note | ||
|
||
Remember, Docker and Docker Compose paths and volume bindings must accurately reflect your system’s directory structure and device file paths. The given example paths may need to be adjusted to match your environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
version: '3.8' | ||
|
||
services: | ||
jupyterlab: | ||
build: | ||
context: ./jupyter | ||
image: custom-jupyterlab:latest | ||
ports: | ||
- "8888:8888" | ||
volumes: | ||
- ../usb/001/002:/dev/bus/usb/001/002 # Bind mount for Coral TPU USB access | ||
- jupyter_data:/home/jovyan/work # Persistent volume for notebooks and data | ||
networks: | ||
- app_network | ||
environment: | ||
- JUPYTER_ENABLE_LAB=yes | ||
privileged: true | ||
|
||
networks: | ||
app_network: | ||
external: true | ||
|
||
volumes: | ||
jupyter_data: | ||
driver: local | ||
driver_opts: | ||
type: none | ||
device: ${PWD}/jupyter_data | ||
o: bind |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# My Default Buckets | ||
|
||
weaviate-backups | ||
cda-datasets | ||
raw-objects | ||
clean-objects | ||
my-prompt-bucket | ||
feature-store-bucket | ||
|
||
## How to Programatically create default bucket data | ||
|
||
Building and populating data in MinIO buckets programmatically can be achieved using various methods, depending on your specific needs and the nature of the data you're dealing with. You can use the MinIO Client (`mc`), MinIO's SDKs for different programming languages, or direct REST API calls. Below, I'll outline methods using the MinIO Client and Python SDK, as these are among the most common and versatile approaches. | ||
|
||
### Using MinIO Client (`mc`) | ||
|
||
The MinIO Client (`mc`) can be used for a wide range of bucket and object management tasks, including file uploads, setting policies, and mirroring data. To programmatically upload data to your buckets, you could write shell scripts that use `mc cp` or `mc mirror` for uploading files. | ||
|
||
#### Uploading a Single File | ||
|
||
```sh | ||
mc cp /path/to/your/file.txt myminio/your-bucket-name | ||
``` | ||
|
||
#### Uploading Multiple Files or Directories | ||
|
||
```sh | ||
mc cp --recursive /path/to/your/directory myminio/your-bucket-name | ||
``` | ||
|
||
#### Example Script for Uploading Data | ||
|
||
```sh | ||
#!/bin/sh | ||
|
||
# Define your bucket names and data sources | ||
declare -A buckets_and_data=( | ||
["weaviate-backups"]="/path/to/backup/data" | ||
["cda-datasets"]="/path/to/datasets" | ||
# Add more as needed | ||
) | ||
|
||
# Loop through the associative array | ||
for bucket in "${!buckets_and_data[@]}"; do | ||
data_source="${buckets_and_data[$bucket]}" | ||
echo "Uploading data from $data_source to $bucket..." | ||
mc cp --recursive "$data_source" myminio/"$bucket" | ||
done | ||
``` | ||
|
||
### Using Python and MinIO Python SDK | ||
|
||
The MinIO Python SDK is a powerful tool for interacting with MinIO in a programmatic way, allowing for more complex operations and integration into your Python applications. | ||
|
||
First, ensure you have the MinIO Python SDK installed: | ||
|
||
```sh | ||
pip install minio | ||
``` | ||
|
||
Then, you can write a Python script to upload files: | ||
|
||
#### Python Script Example | ||
|
||
```python | ||
from minio import Minio | ||
from minio.error import S3Error | ||
import os | ||
|
||
def upload_directory_to_bucket(minio_client, bucket_name, directory_path): | ||
for root, _, files in os.walk(directory_path): | ||
for file in files: | ||
file_path = os.path.join(root, file) | ||
# Define the object name in the bucket; here, it keeps the directory structure | ||
object_name = os.path.relpath(file_path, start=directory_path) | ||
try: | ||
minio_client.fput_object(bucket_name, object_name, file_path) | ||
print(f"Uploaded {file_path} as {object_name} in bucket {bucket_name}") | ||
except S3Error as exc: | ||
print(f"Failed to upload {file_path} to {bucket_name}: {exc}") | ||
|
||
if __name__ == "__main__": | ||
# Create a MinIO client | ||
minio_client = Minio( | ||
"minio:9000", | ||
access_key="your-access-key", | ||
secret_key="your-secret-key", | ||
secure=False # Set to True for https | ||
) | ||
|
||
# Define your buckets and corresponding data directories | ||
buckets_and_data = { | ||
"weaviate-backups": "/path/to/backup/data", | ||
"cda-datasets": "/path/to/datasets", | ||
# Add more as needed | ||
} | ||
|
||
# Upload data for each bucket | ||
for bucket, data_dir in buckets_and_data.items(): | ||
upload_directory_to_bucket(minio_client, bucket, data_dir) | ||
``` | ||
|
||
This Python script demonstrates how to upload an entire directory's worth of files to specific MinIO buckets, maintaining the directory structure within the bucket. It iterates over a dictionary of bucket names and their corresponding local directories, uploading each file found within those directories to the correct bucket. | ||
|
||
By using these approaches, you can programmatically build and populate your MinIO buckets with the necessary data, either through shell scripts utilizing the `mc` tool or via Python scripts using MinIO's Python SDK. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters