Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Dockerfile): add docker file for the storage provider #120

Merged
merged 12 commits into from
Jul 9, 2024
35 changes: 35 additions & 0 deletions ci/Dockerfile.provider
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
################
cernicc marked this conversation as resolved.
Show resolved Hide resolved
##### Chef
FROM rust:1.79 AS chef
cernicc marked this conversation as resolved.
Show resolved Hide resolved
RUN cargo install cargo-chef
WORKDIR /app

################
##### Planer
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

################
##### Builder
FROM chef AS builder

RUN apt update && apt upgrade -y
RUN apt install -y protobuf-compiler
RUN apt install -y clang

# Copy required files
COPY --from=planner /app/recipe.json recipe.json
COPY --from=planner /app/rust-toolchain.toml rust-toolchain.toml
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
cernicc marked this conversation as resolved.
Show resolved Hide resolved
COPY . .
RUN cargo build --release --bin polka-storage-provider

################
##### Runtime
FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/polka-storage-provider /usr/local/bin
ENTRYPOINT ["/usr/local/bin/polka-storage-provider"]
48 changes: 48 additions & 0 deletions ci/PROVIDER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Build the Docker Image

To build the Docker image for the provider, execute the following command:

`docker build -t eiger/provider --file ./ci/Dockerfile.provider .`
cernicc marked this conversation as resolved.
Show resolved Hide resolved

This command uses the Dockerfile located at ./ci/Dockerfile.provider to create an image named `eiger/provider`.

## Start the Storage Provider Server

### Create a Docker Volume

First, create a Docker volume that the storage provider will use to store uploaded files:

`docker volume create storage_provider`

This command creates a volume named storage_provider.

### Start the Storage Server

Next, start the storage server using the created volume:

`docker run --net=host --mount source=storage_provider,destination=/app/uploads eiger/provider storage`
cernicc marked this conversation as resolved.
Show resolved Hide resolved

- `--net=host`: Uses the host network, allowing the container to communicate with the host machine.
- `--mount source=storage_provider,destination=/app/uploads`: Mounts the storage_provider volume to /app/uploads inside the container.
- `eiger/provider storage`: Runs the eiger/provider image with the storage command.

## Upload a file

To upload a file to the provider's server, use the following curl command. Replace image.jpg with the path to your file:

`curl -X POST --data-binary "@image.jpg" http://localhost:9000/upload`

This command uploads the file image.jpg to the server running at http://localhost:9000/upload. The server converts the uploaded content to a CAR file and saves it to the mounted volume.

## Download the CAR File

After uploading, you will receive a CID (Content Identifier) for the file. Use this CID to download the corresponding CAR file. Replace `:cid` with the actual CID provided:

`curl -v -X GET http://localhost:9000/download/:cid --output ./content.car`

- `-v`: Enables verbose mode, providing detailed information about the request.
- `-X GET`: Specifies the GET request method.
- `http://localhost:9000/download/:cid`: The URL to download the CAR file, with :cid being the placeholder for the actual CID.
- `--output ./content.car`: Saves the downloaded CAR file as content.car in the current directory.

By following these steps, you can successfully build the Docker image, start the storage provider server, upload a file, and download the CAR file.