Skip to content

Commit

Permalink
add docker and compose file
Browse files Browse the repository at this point in the history
  • Loading branch information
koloz193 committed Oct 29, 2024
1 parent db0a557 commit 5715248
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Step 1: Use the official Rust image as the build environment
FROM rust:latest AS builder

# Step 2: Create a new directory for the app
WORKDIR /usr/src/era-test-node

# Step 3: Copy the local files to the container
COPY . .

# Step 4: Build the Rust program
RUN cargo build --release

# Use a newer base image for the runtime
FROM ubuntu:latest

ARG CHAIN_ID
ENV CHAIN_ID=${CHAIN_ID}

# Set up dependencies
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*

# Step 7: Set up a user for running the server
ENV USER=era-test-node
RUN useradd -m $USER

# Step 8: Copy the compiled binary from the build container
COPY --from=builder /usr/src/era-test-node/target/release/era_test_node /usr/local/bin/era_test_node

# Step 9: Verify and set execute permissions
RUN ls -l /usr/local/bin/era_test_node # List permissions for debugging
RUN chmod +x /usr/local/bin/era_test_node && \
chown -R $USER:$USER /usr/local/bin/era_test_node

# Step 10: Switch to the new user
USER root

# Step 11: Expose the server port
EXPOSE 8011

# Step 12: Explicitly run the server binary with its full path
CMD ["sh", "-c", "/usr/local/bin/era_test_node --chain-id ${CHAIN_ID}"]
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.8'

services:
era-test-node1:
build:
context: .
dockerfile: Dockerfile
args:
CHAIN_ID: 500
ports:
- "8012:8011"
environment:
- NODE_NAME=era-test-node1
networks:
- era-network

era-test-node2:
build:
context: .
dockerfile: Dockerfile
args:
CHAIN_ID: 501
ports:
- "8013:8011"
environment:
- NODE_NAME=era-test-node2
networks:
- era-network

networks:
era-network:
driver: bridge

0 comments on commit 5715248

Please sign in to comment.