Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ ztm_agent.db
ztm_agent_db*

# buck2 out
buck-out
buck-out

# docker files
docker/mega_mono_dockerfile
docker/mega_moon_dockerfile
docker/mega_pg_dockerfile
22 changes: 12 additions & 10 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
# cd root of the project

# build postgres image
docker buildx build -t mega-db:1.0 -f ./docker/mega_pg_dockerfile .
docker buildx build -t mega-db:0.1-pre-release -f ./docker/mega_pg_dockerfile .

# build backend mono image
docker buildx build -t mega-mono:1.0 -f ./docker/mega_mono_dockerfile .
# build backend mono image (default in release mode)
docker buildx build -t mega-mono:0.1-pre-release -f ./docker/mega_mono_dockerfile .
# build backend mono in debug mode
# docker buildx build -t mega-mono:1.0 -f ./docker/mega_mono_dockerfile --build-arg BUILD_TYPE=debug .

# build frontend moon image
docker buildx build -t mega-moon:1.0 -f ./docker/mega_moon_dockerfile .
docker buildx build -t mega-moon:0.1-pre-release -f ./docker/mega_moon_dockerfile .
```

# test mono and moon
Expand All @@ -22,8 +24,8 @@ docker buildx build -t mega-moon:1.0 -f ./docker/mega_moon_dockerfile .
# create network
docker network create mega-network

docker run --rm -it -d --network mega-network --name mega-mono -v ./mega_base:/etc/mega mega-mono:1.0
docker run --rm -it -d --network mega-network -e NEXT_PUBLIC_API_URL=http://mega-mono:8000 -p 3000:3000 mega-moon:1.0
docker run --rm -it -d --network mega-network --name mega-mono -v ./mega_base:/opt/mega/etc mega-mono:0.1-pre-release
docker run --rm -it -d --network mega-network -e NEXT_PUBLIC_API_URL=http://mega-mono:8000 -p 3000:3000 mega-moon:0.1-pre-release
```

visit http://localhost:3000 to see the frontend
Expand All @@ -37,13 +39,13 @@ visit http://localhost:3000 to see the frontend
docker network create mega-network

# run postgres
docker run --rm -it -d --network mega-network --name mega-db mega-db:1.0
docker run --rm -it -d --network mega-network --name mega-db mega-db:0.1-pre-release
```

2. create default config

```bash
docker run --rm -it -d --network mega-network --name mega-mono -v ./mega_base:/etc/mega mega-mono:1.0
docker run --rm -it -d --network mega-network --name mega-mono -v ./mega_base:/opt/mega/etc mega-mono:0.1-pre-release
docker stop mega-mono
```

Expand All @@ -63,6 +65,6 @@ db_url = "postgres://mega:mega@mega-db:5432/mega"
4. Start the mono again, and run the frontend.

```bash
docker run --rm -it -d --network mega-network --name mega-mono -v ./mega_base:/etc/mega mega-mono:1.0
docker run --rm -it -d --network mega-network -e NEXT_PUBLIC_API_URL=http://mega-mono:8000 -p 3000:3000 mega-moon:1.0
docker run --rm -it -d --network mega-network --name mega-mono -v ./mega_base:/opt/mega/etc mega-mono:0.1-pre-release
docker run --rm -it -d --network mega-network -e NEXT_PUBLIC_API_URL=http://mega-mono:8000 -p 3000:3000 mega-moon:0.1-pre-release
```
34 changes: 29 additions & 5 deletions docker/mega_mono_dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
FROM debian:bookworm-slim
FROM debian:bookworm-slim AS builder

WORKDIR /opt/mega

# build args, to specify the build type, release or debug
ARG BUILD_TYPE=release

# check arg value
RUN if [ "$BUILD_TYPE" != "release" ] && [ "$BUILD_TYPE" != "debug" ]; then \
echo "Invalid BUILD_TYPE: $BUILD_TYPE, must be release or debug"; \
exit 1; \
fi

# set mirror for apt
# RUN echo "deb http://mirrors.ustc.edu.cn/debian bookworm main contrib non-free" > /etc/apt/sources.list && \
# echo "deb http://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free" >> /etc/apt/sources.list && \
Expand All @@ -28,11 +37,26 @@ ENV PATH=/root/.cargo/bin:$PATH!

# copy the source code, the context must be the root of the project
COPY . .
RUN chmod +x /opt/mega/docker/start_mono.sh

# build
RUN cargo build -p mono
RUN if [ "$BUILD_TYPE" = "release" ]; then \
cargo build -p mono --release; \
else \
cargo build -p mono; \
fi

# final image
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y libssl-dev

ARG BUILD_TYPE=release

COPY --from=builder /opt/mega/target/$BUILD_TYPE/mono /usr/local/bin/mono
COPY --from=builder /opt/mega/docker/start_mono.sh /usr/local/bin/start_mono.sh
RUN chmod +x /usr/local/bin/start_mono.sh
RUN chmod +x /usr/local/bin/mono

VOLUME /etc/mega
VOLUME /opt/mega/etc

CMD ["bash", "-c", "/opt/mega/docker/start_mono.sh"]
CMD ["bash", "-c", "/usr/local/bin/start_mono.sh"]
10 changes: 6 additions & 4 deletions docker/start_mono.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/sh

CONFIG_FILE="/etc/mega"
MEGA_BASE_DIR="/etc/mega"
export MEGA_BASE_DIR="/opt/mega/etc"
CONFIG_FILE="$MEGA_BASE_DIR/config.toml"

# check if config file exists
if [ -f "$CONFIG_FILE" ]; then
exec /opt/mega/target/debug/mono -c "$CONFIG_FILE" service http --host 0.0.0.0
echo "Using config file: $CONFIG_FILE"
exec /usr/local/bin/mono -c "$CONFIG_FILE" service http --host 0.0.0.0
else
exec /opt/mega/target/debug/mono service http --host 0.0.0.0
exec /usr/local/bin/mono service http --host 0.0.0.0
fi