From d59eb6ec8428e6061577ede047ab66268e98ffec Mon Sep 17 00:00:00 2001 From: Flook Peter Date: Mon, 15 Jul 2024 08:36:16 +0800 Subject: [PATCH] Add in user for kafka services --- docker-compose.yaml | 2 ++ run.sh | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index c4c8bd6..a59ca30 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -466,6 +466,7 @@ "environment": - "KAFKA_TOPICS=${KAFKA_TOPICS:-accounts,transactions}" "image": "confluentinc/confluent-local:${KAFKA_VERSION:-7.6.1}" + "user": "${CURRENT_UID}" "volumes": - "./data/kafka/init.sh:/tmp/scripts/init.sh" "kafka-server": @@ -485,6 +486,7 @@ "image": "confluentinc/confluent-local:7.6.1" "ports": - "9092:9092" + "user": "${CURRENT_UID}" "volumes": - "./data/kafka/persist:/var/lib/kafka/data" "keycloak": diff --git a/run.sh b/run.sh index 6edec98..8680de7 100755 --- a/run.sh +++ b/run.sh @@ -50,6 +50,14 @@ usage() { exit 0 } +set_user() { + if [ -z "$CURRENT_UID" ] + then + current_user="$(id -u):$(id -g)" + export CURRENT_UID="$current_user" + fi +} + connect_to_service() { if [ -z "$1" ] then @@ -72,6 +80,7 @@ connect_to_service() { } shutdown_service() { + set_user if [ -z "$1" ]; then echo "Shutting down all services..." docker-compose -f "$SCRIPT_DIR/docker-compose.yaml" down @@ -99,9 +108,10 @@ check_docker_installed() { } startup_services() { + set_user all_services=("$@") echo -e "${GREEN}Starting up services...${NC}" - docker-compose -f "$SCRIPT_DIR/docker-compose.yaml" up -d "$@" + docker-compose -f "$SCRIPT_DIR/docker-compose.yaml" up -d --quiet-pull "$@" if [ $? != 0 ]; then echo -e "${RED}Error: Failed to start up services${NC}" exit 1