diff --git a/.gitignore b/.gitignore index d9abce8f..29c6f6e2 100644 --- a/.gitignore +++ b/.gitignore @@ -100,6 +100,7 @@ tags # queries *.sql *.sh +!docker-entrypoint.sh # modules node_modules diff --git a/Dockerfile b/Dockerfile index 4a0633fc..130819fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,79 @@ -FROM lsvih/gcc-cmake-boost:v1 -RUN apt -qqy update \ - && apt install -qqy --no-install-recommends \ - libssl-dev libcurl4-openssl-dev libreadline-dev uuid-dev \ - && ldconfig -v \ - && echo "* - nofile 65535" >> /etc/security/limits.conf \ - && echo "* - noproc 65535" >> /etc/security/limits.conf +# SPDX-License-Identifier: BSD-3-Clause + +FROM debian:buster-slim AS builder + +LABEL vendor="pkumod" +LABEL description="gStore RDF Database Engine" + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + libboost-regex-dev \ + libboost-system-dev \ + libboost-thread-dev \ + libboost-system-dev \ + curl \ + libcurl4 \ + libcurl4-openssl-dev \ + libssl-dev \ + libzmq3-dev \ + pkg-config \ + wget \ + zlib1g-dev \ + uuid-dev \ + libjemalloc-dev \ + libreadline-dev + +RUN mkdir -p /src -COPY . /usr/src/gstore WORKDIR /usr/src/gstore -ENV LANG C.UTF-8 +# Compile gStore dependencies +COPY tools/ /usr/src/gstore/tools + +COPY makefile /usr/src/gstore/ + +RUN mkdir -p lib && make pre + +# Copy gStore source code; run `make tarball` to generate this file +ADD gstore.tar.gz /usr/src/gstore + +RUN make + +FROM debian:buster-slim AS runtime + +RUN apt-get update && apt-get install -y \ + libboost-regex1.67.0 \ + libboost-system1.67.0 \ + libboost-thread1.67.0 \ + libcurl4 \ + libssl1.1 \ + libzmq5 \ + uuid-runtime \ + libjemalloc2 \ + libreadline7 \ + libopenmpi3 \ + coreutils \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /usr/src/gstore/bin/ /usr/local/bin/ + +COPY --from=builder /usr/src/gstore/lib/ /docker-init/lib/ + +COPY backup.json init.conf conf.ini ipAllow.config ipDeny.config slog.properties slog.stdout.properties \ + /docker-init/ +COPY data/ /docker-init/data/ +COPY docker-entrypoint.sh / + +WORKDIR /app/ +VOLUME [ "/app/" ] + +RUN echo "* - nofile 65535" >> /etc/security/limits.conf \ + && echo "* - noproc 65535" >> /etc/security/limits.conf + +EXPOSE 9000 + +ENTRYPOINT [ "sh", "/docker-entrypoint.sh" ] -RUN make pre -j && make -j FIRST_BUILD=y \ - && apt autoclean && apt clean \ - && rm -rf /usr/src/gstore/.git \ - && rm -rf /usr/src/gstore/tools \ - && rm -rf /tmp/* /var/tmp/* \ - && rm -rf /usr/share/doc/* \ - && rm -rf /var/lib/apt/lists/* +CMD [ "/usr/local/bin/ghttp" ] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 00000000..f668f93c --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +BLUE='\033[0;34m' +RED='\033[0;31m' +NC='\033[0m' + +if [ ! -f /app/init.conf ]; then + echo "${BLUE}[INIT] No init.conf file found. Copying default...${NC}" + cp -r /docker-init/* /app/ + + # Check if GSTORE_ROOT_PASSWORD is set + if [ -z "$GSTORE_ROOT_PASSWORD" ]; then + echo "${RED}[INIT] GSTORE_ROOT_PASSWORD is not set. We strongly recommend setting a strong password.${NC}" + else + echo "${BLUE}[INIT] Setting root password...${NC}" + # Replace the line in the file + sed -i -e "s/^#\\?\\s*root_password=.*/root_password=${GSTORE_ROOT_PASSWORD}/" init.conf + fi + +fi + +if [ ! -d /app/bin ]; then + echo "${BLUE}[INIT] Creating directories...${NC}" + mkdir -p bin lib backups data logs .tmp +fi + +if [ ! -d /app/system.db ]; then + echo "${BLUE}[INIT] Creating system.db...${NC}" + /usr/local/bin/ginit --make + + # list all directories in /app/data + for dir in /app/data/*; do + # get the directory name + dir_name=$(basename "$dir") + if [ $dir_name != "system" ] && [ -d "data/$dir_name" ] && [ -f "data/$dir_name/$dir_name.nt" ] ; then + # create the database + echo "${BLUE}[INIT] Creating $dir_name...${NC}" + /usr/local/bin/gbuild -db "$dir_name" -f "data/$dir_name/$dir_name.nt" + fi + done +fi + +echo "${BLUE}[INIT] Command: $@${NC}" + +exec "$@" \ No newline at end of file diff --git a/docs/DOCKER_DEPLOY_EN.md b/docs/DOCKER_DEPLOY_EN.md index 2be570ee..c561c42f 100644 --- a/docs/DOCKER_DEPLOY_EN.md +++ b/docs/DOCKER_DEPLOY_EN.md @@ -18,6 +18,28 @@ After having the correct Docker environment and network, use `git clone` to down After the building, using `docker run -p 9000:80 -it gstore` directly to start and enter the container and execute other operations. +### Playground Mode + +The docker image has been built with some sample data. You can run the following command to start the container in playground mode: + +```bash +docker run --rm -it gstore sh -c "(/usr/local/bin/ghttp &); bash" +``` + +Press Enter to start the bash shell. Then you can play with the sample data in the container. + +```bash +gquery -db small -q data/small/small_q0.sql +``` + +### Server Mode + +Expose the port 9000, persist the data and run the container in background: + +```bash +docker run -d -p 9000:9000 -v /path/to/data:/app gstore +``` + ## 0x02. pulling the mirror directly to run Instead of downloading project or building on your own, input `docker pull pkumodlab/gstore:latest` to pull the mirror which has been automatically built well on the docker hub. Then input `docker run -p 9000:80 -it pkumodlab/gstore:latest` to start and enter the container and execute other operations. diff --git a/makefile b/makefile index 3c5f44a1..4f194ffd 100644 --- a/makefile +++ b/makefile @@ -745,10 +745,11 @@ dist: clean rm -rf backups/*.db tarball: - tar -czvf gstore.tar.gz api backups bin lib tools .debug .tmp .objs scripts docs data logs \ - Main Database KVstore Util Query Signature VSTree Parser Server README.md init.conf conf.ini StringIndex COVERAGE \ - Dockerfile LICENSE makefile Trie - + tar -czvf gstore.tar.gz api backups bin lib tools .debug .tmp .objs scripts data logs \ + Main Database KVstore Util Query Signature Parser Server StringIndex Trie GRPC COVERAGE \ + makefile init.conf conf.ini backup.json ipAllow.config ipDeny.config slog.properties slog.stdout.properties \ + README.md LICENSE + APIexample: $(api_cpp) $(api_socket) $(MAKE) -C api/http/cpp/example $(MAKE) -C api/socket/cpp/example