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

fix: Decouple from complex entrypoint script 🐳 #23

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .build/debug/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM oven/bun:alpine

WORKDIR /app

COPY . .

RUN bun install

# Expose the port the app runs on
EXPOSE 5384

# Entry script to handle conditional startup
COPY .build/debug/docker-entrypoint.sh ./docker-entrypoint.sh
RUN chmod +x ./docker-entrypoint.sh

ENTRYPOINT ["sh", "./docker-entrypoint.sh"]
22 changes: 22 additions & 0 deletions .build/debug/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
seda-data-proxy:
build:
context: ../..
dockerfile: .build/docker/Dockerfile
ports:
- "5384:5384"
# environment:
# # Provide the private key if available
# SEDA_DATA_PROXY_PRIVATE_KEY: ${SEDA_DATA_PROXY_PRIVATE_KEY}
#
# volumes:
# # Mount config.json if it exists in the host folder
# - ./config.json:/app/config.json:ro
# # Mount a data proxy private key file
# - ./data-proxy-private-key.json:/app/data-proxy-private-key.json:ro
networks:
- proxy-network

networks:
proxy-network:
driver: bridge
53 changes: 53 additions & 0 deletions .build/debug/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# Initialize flags for config.json and private key
CONFIG_EXISTS=false
PK_EXISTS=false

# Check if config.json exists
if [ -f /app/config.json ]; then
echo "config.json detected"
CONFIG_EXISTS=true
else
echo "config.json not found"
fi

# Check if data-proxy-private-key.json exists
if [ -f /app/data-proxy-private-key.json ]; then
echo "data-proxy-private-key.json detected"
PK_EXISTS=true
elif [ -n "$SEDA_DATA_PROXY_PRIVATE_KEY" ]; then
# If private key file does not exist, check if the private key is provided via environment variable
echo "Private key provided via environment variable"
echo "$SEDA_DATA_PROXY_PRIVATE_KEY" >/app/data-proxy-private-key.json
PK_EXISTS=true
else
echo "No private key provided"
fi

run_bun_command() {
if ! bun "$@"; then
echo "Failed to run: bun $*"
exit 1
fi
}

# Determine the command to run based on the presence of config.json and private key
if [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = true ]; then
# Both config.json and private key are provided
echo "Running with config and private key"
RUN_CMD="start run --config /app/config.json --private-key-file /app/data-proxy-private-key.json"
elif [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = false ]; then
# Only config.json is provided
echo "Running with config only"
run_bun_command start init
RUN_CMD="start run --config /app/config.json"
else
# Neither config.json nor private key is provided
echo "Running with --disable-proof"
run_bun_command start init
RUN_CMD="start run --disable-proof"
fi

# Execute the final command
run_bun_command $RUN_CMD
13 changes: 9 additions & 4 deletions .build/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ WORKDIR /app

COPY . .

RUN echo 'export PS1="\e[01;32m\u\e[m:\e[01;34m\w\e[m\$ "' >> /home/bun/.bashrc

RUN bun install
kaynetik marked this conversation as resolved.
Show resolved Hide resolved

RUN bun build --compile --minify --sourcemap ./workspace/data-proxy/src/index.ts --outfile dataproxy --target=bun-linux-arm64
kaynetik marked this conversation as resolved.
Show resolved Hide resolved

# Expose the port the app runs on
EXPOSE 5384

# Entry script to handle conditional startup
COPY .build/docker/docker-entrypoint.sh ./docker-entrypoint.sh
RUN chmod +x ./docker-entrypoint.sh
RUN chmod +x dataproxy

COPY .build/docker/docker-entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

ENTRYPOINT ["sh", "./docker-entrypoint.sh"]
ENTRYPOINT ["sh", "/app/entrypoint.sh"]
18 changes: 13 additions & 5 deletions .build/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ services:
dockerfile: .build/docker/Dockerfile
ports:
- "5384:5384"
### Provide the private key if available
# environment:
# # Provide the private key if available
# SEDA_DATA_PROXY_PRIVATE_KEY: ${SEDA_DATA_PROXY_PRIVATE_KEY}
#
# volumes:
# # Mount config.json if it exists in the host folder
# - ./config.json:/app/config.json:ro
# # Mount a data proxy private key file
# - ./data-proxy-private-key.json:/app/data-proxy-private-key.json:ro
### Provide the config file if available
volumes:
- type: bind
source: ../../config.json
target: /app/config.json
read_only: true
consistency: cached
- type: bind
source: ../../data-proxy-private-key.json
target: /app/data-proxy-private-key.json
read_only: true
consistency: cached
Thomasvdam marked this conversation as resolved.
Show resolved Hide resolved
networks:
- proxy-network

Expand Down
56 changes: 6 additions & 50 deletions .build/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,53 +1,9 @@
#!/bin/bash
#!/bin/sh

# Initialize flags for config.json and private key
CONFIG_EXISTS=false
PK_EXISTS=false

# Check if config.json exists
if [ -f /app/config.json ]; then
echo "config.json detected"
CONFIG_EXISTS=true
if [ -f "/app/config.json" ] && [ -f "/app/data-proxy-private-key.json" ]; then
echo "Config and private key files found. Running with specific configuration."
exec ./dataproxy run --config /app/config.json --private-key-file /app/data-proxy-private-key.json "$@"
else
echo "config.json not found"
echo "Config or private key file not found. Running with default configuration."
exec ./dataproxy run "$@"
kaynetik marked this conversation as resolved.
Show resolved Hide resolved
fi

# Check if data-proxy-private-key.json exists
if [ -f /app/data-proxy-private-key.json ]; then
echo "data-proxy-private-key.json detected"
PK_EXISTS=true
elif [ -n "$SEDA_DATA_PROXY_PRIVATE_KEY" ]; then
# If private key file does not exist, check if the private key is provided via environment variable
echo "Private key provided via environment variable"
echo "$SEDA_DATA_PROXY_PRIVATE_KEY" >/app/data-proxy-private-key.json
PK_EXISTS=true
else
echo "No private key provided"
fi

run_bun_command() {
if ! bun "$@"; then
echo "Failed to run: bun $*"
exit 1
fi
}

# Determine the command to run based on the presence of config.json and private key
if [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = true ]; then
# Both config.json and private key are provided
echo "Running with config and private key"
RUN_CMD="start run --config /app/config.json --private-key-file /app/data-proxy-private-key.json"
elif [ "$CONFIG_EXISTS" = true ] && [ "$PK_EXISTS" = false ]; then
# Only config.json is provided
echo "Running with config only"
run_bun_command start init
RUN_CMD="start run --config /app/config.json"
else
# Neither config.json nor private key is provided
echo "Running with --disable-proof"
run_bun_command start init
RUN_CMD="start run --disable-proof"
fi

# Execute the final command
run_bun_command $RUN_CMD
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

config.json
data-proxy-private-key.json