Browse Source

add docker support for cdk-mintd (#480)

Darrell 4 months ago
parent
commit
d4975c7170
2 changed files with 54 additions and 0 deletions
  1. 40 0
      Dockerfile
  2. 14 0
      crates/cdk-mintd/README.md

+ 40 - 0
Dockerfile

@@ -0,0 +1,40 @@
+# Use the official NixOS image as the base image
+FROM nixos/nix:latest AS builder
+
+# Set the working directory
+WORKDIR /usr/src/app
+
+# Copy workspace files and crates directory into the container
+COPY flake.nix ./flake.nix
+COPY Cargo.toml ./Cargo.toml
+COPY crates ./crates
+
+# Start the Nix daemon and develop the environment
+RUN nix develop --extra-experimental-features nix-command --extra-experimental-features flakes --command cargo build --release --bin cdk-mintd
+
+# Create a runtime stage
+FROM debian:bookworm-slim
+
+# Set the working directory
+WORKDIR /usr/src/app
+
+# Install needed runtime dependencies (if any)
+RUN apt-get update && \
+    apt-get install -y --no-install-recommends patchelf && \
+    rm -rf /var/lib/apt/lists/*
+
+# Copy the built application from the build stage
+COPY --from=builder /usr/src/app/target/release/cdk-mintd /usr/local/bin/cdk-mintd
+
+# Detect the architecture and set the interpreter accordingly
+RUN ARCH=$(uname -m) && \
+    if [ "$ARCH" = "aarch64" ]; then \
+        patchelf --set-interpreter /lib/ld-linux-aarch64.so.1 /usr/local/bin/cdk-mintd; \
+    elif [ "$ARCH" = "x86_64" ]; then \
+        patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /usr/local/bin/cdk-mintd; \
+    else \
+        echo "Unsupported architecture: $ARCH"; exit 1; \
+    fi
+
+# Set the entry point for the container
+CMD ["cdk-mintd"]

+ 14 - 0
crates/cdk-mintd/README.md

@@ -26,3 +26,17 @@
 ```sh
   vi ~/.cdk-mintd/config.toml
 ```
+
+## Running with Docker 
+
+### Build the Docker image
+
+```sh
+  docker build -t cdk-mintd .
+```
+
+### Run the Docker container with the configuration file mapped
+
+```sh
+  docker run -v ~/.cdk-mintd/config.toml:/root/.cdk-mintd/config.toml cdk-mintd
+```