From c317decd316a7defcda3bb1a6590c170681ce3c3 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 28 Aug 2022 22:39:15 +0200 Subject: docker: shorten command values --- Dockerfile | 3 +++ docker-compose.yml | 12 ++++++++---- src/CMakeLists.txt | 3 +++ src/const.h | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 368524b..3a5531d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,8 @@ FROM base AS builder RUN apk add --no-cache bsd-compat-headers build-base clang cmake libgit2-dev +ARG default_host=127.0.0.1 + ARG src_dir="/app/src" ARG build_dir="/app/build" ARG install_dir @@ -15,6 +17,7 @@ COPY [".", "$src_dir"] RUN mkdir -- "$build_dir" && \ cd -- "$build_dir" && \ cmake \ + -D "DEFAULT_HOST=$default_host" \ -D CMAKE_C_COMPILER=clang \ -D CMAKE_BUILD_TYPE=Release \ -D "CMAKE_INSTALL_PREFIX=$install_dir" \ diff --git a/docker-compose.yml b/docker-compose.yml index d80a5cd..2fa5367 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,10 @@ version: '3' x-cimple: &common - build: . + build: + context: . + args: + default_host: server image: egortensin/cimple restart: always @@ -12,14 +15,15 @@ services: - 5556 worker1: <<: *common - command: ["./cimple-worker", "--host", "server"] + command: ["./cimple-worker"] depends_on: [server] worker2: <<: *common - command: ["./cimple-worker", "--host", "server"] + command: ["./cimple-worker"] depends_on: [server] client: <<: *common command: [] - entrypoint: ["./cimple-client", "--host", "server"] + depends_on: [server] + entrypoint: ["./cimple-client"] restart: 'no' diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 10c7066..c647937 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,9 @@ add_compile_definitions(_GNU_SOURCE) add_compile_definitions(VERSION="${PROJECT_VERSION}") +set(DEFAULT_HOST "127.0.0.1" CACHE STRING "Set the default --host value") +add_compile_definitions(DEFAULT_HOST="${DEFAULT_HOST}") + function(add_my_executable name) list(POP_FRONT ARGV) add_executable("${name}" ${ARGV}) diff --git a/src/const.h b/src/const.h index 53b0364..8ac2e33 100644 --- a/src/const.h +++ b/src/const.h @@ -1,7 +1,9 @@ #ifndef __CONST_H__ #define __CONST_H__ +#ifndef DEFAULT_HOST #define DEFAULT_HOST "127.0.0.1" +#endif #define DEFAULT_PORT "5556" #endif -- cgit v1.2.3