From 77c06da845cd46b8db5eb2d48c5fe7214ec0984f Mon Sep 17 00:00:00 2001 From: Li Chaoran Date: Wed, 12 Jul 2023 16:47:08 +0800 Subject: [PATCH] add docker compose support Signed-off-by: Li Chaoran --- .env | 7 +++++ Dockerfile | 8 ++++-- README.md | 50 ++++++++++++++++++++------------ docker-compose.yaml | 69 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 20 deletions(-) create mode 100644 .env create mode 100644 docker-compose.yaml diff --git a/.env b/.env new file mode 100644 index 0000000..cd12ab6 --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ +MYSQL_DATABASE=signatrust +MYSQL_PASSWORD=test +MYSQL_USER=test +MYSQL_ROOT_PASSWORD=root +REDIS_PASSWD=signatrust-redis +DATABASE_URL=mysql://test:test@database:3306/signatrust +RUST_LOG=debug diff --git a/Dockerfile b/Dockerfile index ad89ff5..ad967b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,13 +4,17 @@ LABEL Author=TommyLike WORKDIR /app COPY . /app + RUN cargo +nightly build --release --bin $BINARY --target x86_64-unknown-linux-musl +RUN cargo install sqlx-cli --no-default-features --features native-tls,mysql,openssl-vendored --root /app FROM openeuler/openeuler:22.03 ARG BINARY +ARG CONFIG=./config ENV BINARY=${BINARY} WORKDIR /app COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/$BINARY /app -COPY ./config /app/config +COPY --from=builder /app/bin/sqlx /app +COPY $CONFIG /app/config COPY ./migrations /app/migrations -ENTRYPOINT ["/app/$(echo ${BINARY})"] +ENTRYPOINT /app/$(echo $BINARY) diff --git a/README.md b/README.md index 2876d57..829d2b0 100644 --- a/README.md +++ b/README.md @@ -103,25 +103,39 @@ This project consists of several binaries: # Quick Start Guide ## Local development -Run these commands correspondingly to build or run project executable binary: -```shell -# build binary -cargo build --bin control-server/data-server/client/control-admin -# running command -RUST_BACKTRACE=full RUST_LOG=debug ./target/debug/ --config -``` +There are two ways to setup a local development enviroment: +- Build and run binary directly: + + Run these commands correspondingly to build or run project executable binary: + ```shell + # build binary + cargo build --bin control-server/data-server/client/control-admin + # running command + RUST_BACKTRACE=full RUST_LOG=debug ./target/debug/ --config + ``` + + Additionally, we have developed a script to set up the MySQL database in a Docker environment. To use the script, you will + need to install the Docker server, the MySQL binary, and the [Sqlx binary](https://github.com/launchbadge/sqlx/blob/main/sqlx-cli/README.md#enable-building-in-offline-mode-with-query). + Once you have these installed, simply run the command below to initialize the database. + ```shell + make db + ``` + +- Using docker compose: + + Alternately, you can using `docker compose` to setup a develop environment easily: + ```bash + docker compose up + ``` + This will build docker images for `redis`, `mysql`, `control-server` and `data-server` and start them + When using memory backend, to ensure the security of sensitive data, Signatrust requires an external KMS system for encryption and decryption. However, -to run the system locally for development purpose, you will need to configure a **dummy** KMS provider -```shell -[kms-provider] -type = "dummy" -``` -Additionally, we have developed a script to set up the MySQL database in a Docker environment. To use the script, you will -need to install the Docker server, the MySQL binary, and the [Sqlx binary](https://github.com/launchbadge/sqlx/blob/main/sqlx-cli/README.md#enable-building-in-offline-mode-with-query). -Once you have these installed, simply run the command below to initialize the database. -```shell -make db -``` + to run the system locally for development purpose, you will need to configure a **dummy** KMS provider + ```shell + [kms-provider] + type = "dummy" + ``` + In order to develop without the need of setting up the external OIDC server, simple run the prepared script which will generate the default admin&token and the default keys: ```shell make init diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..b7c0474 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,69 @@ +version: '3' +services: + data-server: + build: + context: . + args: + BINARY: data-server + CONFIG: ./docker + hostname: data-server + entrypoint: ["/bin/bash", "-cx", "/app/sqlx database create; /app/sqlx migrate run; /app/data-server"] + depends_on: + - redis + - database + stdin_open: true + tty: true + environment: + RUST_LOG: $RUST_LOG + DATABASE_URL: $DATABASE_URL + ports: + - "8088:8088" + + control-server: + build: + context: . + args: + BINARY: control-server + CONFIG: ./docker + hostname: control-server + hostname: control-server + depends_on: + - redis + - database + - data-server + stdin_open: true + tty: true + environment: + RUST_LOG: $RUST_LOG + entrypoint: ["/bin/bash", "-cx", "sleep 5; /app/control-server"] + ports: + - "8080:8080" + + redis: + image: openeuler/redis:6.2.7-22.03-lts + hostname: redis + command: /usr/bin/resalloc-server + stdin_open: true + tty: true + volumes: + - redis:/var/lib/redis/data + command: redis-server --requirepass $REDIS_PASSWD + ports: + - "6379:6379" + + database: + image: mysql:8.0 + hostname: database + volumes: + - database:/var/lib/mysql + environment: + MYSQL_DATABASE: $MYSQL_DATABASE + MYSQL_PASSWORD: $MYSQL_PASSWORD + MYSQL_USER: $MYSQL_USER + MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD + ports: + - "3306:3306" + +volumes: + database: + redis: -- Gitee