Skip to content

Commit 3b0075e

Browse files
committed
optimize build
1 parent 3556654 commit 3b0075e

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

build-docker/alpine/Dockerfile

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@
22
FROM rust:alpine AS builder
33
WORKDIR /app
44

5-
# Better build environment for Rust + musl
5+
# Install build dependencies
66
RUN apk add --no-cache \
77
build-base \
88
cmake \
9-
musl-dev \
10-
pkgconfig \
9+
musl-dev\
1110
perl \
11+
perl-utils \
12+
perl-dev \
1213
sqlite-dev \
13-
openssl-dev \
14-
openssl-libs-static
15-
16-
# Optimize Rust compilation for musl
17-
ENV RUSTFLAGS="-C target-feature=-crt-static -C link-arg=-s"
18-
ENV CARGO_BUILD_TARGET="x86_64-unknown-linux-musl"
19-
RUN rustup target add x86_64-unknown-linux-musl
14+
openssl-dev
2015

2116
COPY . .
22-
RUN cargo build -p router-cli --release --target x86_64-unknown-linux-musl
23-
RUN cargo build -p router-core --release --target x86_64-unknown-linux-musl
24-
RUN cargo build -p router-api --release --target x86_64-unknown-linux-musl
17+
RUN cargo build -p router-cli --release
18+
RUN cargo build -p router-core --release
19+
RUN cargo build -p router-api --release
2520

2621
# Runtime image stage
2722
FROM alpine:latest
@@ -31,7 +26,8 @@ WORKDIR /app
3126
RUN apk add --no-cache \
3227
ca-certificates \
3328
bash \
34-
sqlite-libs
29+
sqlite-libs \
30+
certbot
3531

3632
# Copy binaries from builder
3733
COPY --from=builder /app/target/release/router-core /usr/local/bin/router-core

build-docker/alpine/entrypoint.sh

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,42 @@ start_core() {
2525
# Start API service
2626
start_api() {
2727
log "Starting router-api..."
28+
29+
# First start the API service
2830
nohup /usr/local/bin/router-api > "$LOG_DIR/api.log" 2> "$LOG_DIR/api.error" &
29-
echo $! > "$PID_DIR/api.pid"
30-
log "router-api started (PID: $!)"
31+
local api_pid=$!
32+
echo $api_pid > "$PID_DIR/api.pid"
33+
log "router-api started (PID: $api_pid)"
34+
35+
# Wait a moment to check if API started successfully
36+
sleep 2
37+
38+
# Check if API is still running
39+
if kill -0 $api_pid 2>/dev/null; then
40+
# Check for config files in order of priority
41+
local config_file=""
42+
if [ -f "/data/config.yaml" ]; then
43+
config_file="/data/config.yaml"
44+
elif [ -f "$HOME/config.yaml" ]; then
45+
config_file="$HOME/config.yaml"
46+
elif [ -f "/app/config.yaml" ]; then
47+
config_file="/app/config.yaml"
48+
elif [ ! -z "$CONFIG_FILE" ]; then
49+
config_file="$CONFIG_FILE"
50+
fi
51+
52+
if [ ! -z "$config_file" ]; then
53+
log "API running successfully, starting gwrs with config: $config_file"
54+
nohup gwrs --osenv --config "$config_file" > "$LOG_DIR/gwrs.log" 2> "$LOG_DIR/gwrs.error" &
55+
echo $! > "$PID_DIR/gwrs.pid"
56+
log "gwrs started (PID: $!)"
57+
else
58+
log "API running successfully but no config file found, skipping gwrs"
59+
fi
60+
else
61+
log "API failed to start, not running gwrs"
62+
rm -f "$PID_DIR/api.pid"
63+
fi
3164
}
3265

3366
# Stop a service

0 commit comments

Comments
 (0)