Skip to content

Commit

Permalink
Add GitHub Actions workflow for building and pushing images
Browse files Browse the repository at this point in the history
  • Loading branch information
Cdaprod committed Mar 10, 2024
1 parent 2d9cd7f commit 71b4275
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 4 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/build_and_push_images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build and Push Docker Image

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: |
cdaprod/cda-minio-control:latest
ghcr.io/cdaprod/cda-minio-control:latest
19 changes: 19 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file to the working directory
COPY requirements.txt .

# Install the Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code to the working directory
COPY . .

# Expose the port on which the FastAPI application will run
EXPOSE 8000

# Set the command to run the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
57 changes: 57 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Dockerizing Instructions

`docker build -t cdaprod/cda-minio-control .`

```bash
docker run -p 8000:8000 --name cda-minio-control \
-e OPENAI_API_KEY=<your-openai-api-key> \
-e MINIO_ENDPOINT=<your-minio-endpoint> \
-e MINIO_ACCESS_KEY=<your-minio-access-key> \
-e MINIO_SECRET_KEY=<your-minio-secret-key> \
cdaprod/cda-minio-control
```

`docker push cdaprod/cda-minio-control`

```yaml
name: Build and Push Docker Image

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: |
cdaprod/cda-minio-control:latest
ghcr.io/cdaprod/cda-minio-control:latest
```
7 changes: 7 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ async def execute_script_in_docker(self, execution_request: ScriptExecutionReque

app = FastAPI()

@app.get("/")
def read_root(settings: Settings = Depends(get_settings)):
return {"Hello": "World", "MinIO Endpoint": settings.minio_endpoint}

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)

@app.post("/execute/{bucket_name}/{script_name}")
async def execute_script(bucket_name: str, script_name: str):
orchestrator = MinIOSystemOrchestrator(
Expand Down
10 changes: 6 additions & 4 deletions app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
pydantic
fastapi
uvicorn
minio
weaviate
requests
unstructured
langchain[all]
langserve[all]
docker
openai
langchain
weaviate-client
83 changes: 83 additions & 0 deletions docs/dockerize_working_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Sure! Here's a Dockerfile that you can use to containerize your application:

```Dockerfile
# Use an official Python runtime as the base image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file to the working directory
COPY requirements.txt .

# Install the Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code to the working directory
COPY . .

# Expose the port on which the FastAPI application will run
EXPOSE 8000

# Set the command to run the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
```

To use this Dockerfile, follow these steps:

1. Create a new directory for your project and navigate to it in your terminal.

2. Create a file named `requirements.txt` in the project directory and add the following dependencies:

```
fastapi
uvicorn
minio
requests
unstructured
docker
openai
langchain
weaviate-client
```

3. Create a file named `app.py` in the project directory and copy the refined script code that I provided earlier into it.

4. Create a file named `Dockerfile` (without any extension) in the project directory and copy the Dockerfile code provided above into it.

5. Open a terminal in the project directory and build the Docker image by running the following command:

```bash
docker build -t cdaprod/cda-minio-control .
```

6. Once the image is built, you can run the container using the following command:

```bash
docker run -p 8000:8000 --name cda-minio-control \
-e OPENAI_API_KEY=<your-openai-api-key> \
-e MINIO_ENDPOINT=<your-minio-endpoint> \
-e MINIO_ACCESS_KEY=<your-minio-access-key> \
-e MINIO_SECRET_KEY=<your-minio-secret-key> \
cdaprod/cda-minio-control
```

Make sure to replace `<your-openai-api-key>`, `<your-minio-endpoint>`, `<your-minio-access-key>`, and `<your-minio-secret-key>` with your actual values.

7. The application should now be running inside the container. You can access the FastAPI endpoints using `http://localhost:8000` in your browser or API client.

To push the Docker image to Docker Hub, follow these steps:

1. Log in to Docker Hub using the `docker login` command in your terminal.

2. Push the image to Docker Hub using the following command:

```bash
docker push cdaprod/cda-minio-control
```

Make sure you have the necessary permissions to push to the `cdaprod` namespace on Docker Hub.

That's it! Your application is now containerized and pushed to Docker Hub. You can easily deploy and run it on any system that has Docker installed.

Let me know if you have any further questions!

0 comments on commit 71b4275

Please sign in to comment.