From 59e73c20497ed0faec2863765234c336911f9e0b Mon Sep 17 00:00:00 2001 From: Chingis Sandanov Date: Tue, 6 Mar 2018 13:51:50 +0700 Subject: [PATCH] Make wodby uid/gid configurable via build params https://github.com/wodby/php/issues/22#issuecomment-370675081 --- 5.3/Dockerfile | 13 +++++++++++-- 5.3/Makefile | 5 +++++ 5.6/Dockerfile | 13 +++++++++++-- 5.6/Makefile | 5 +++++ 7/Dockerfile | 13 +++++++++++-- 7/Makefile | 5 +++++ 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/5.3/Dockerfile b/5.3/Dockerfile index 5a8aa0e2..a00eeffc 100644 --- a/5.3/Dockerfile +++ b/5.3/Dockerfile @@ -4,6 +4,9 @@ FROM wodby/base-php:${FROM_TAG} ARG PHP_DEV +ARG WODBY_USER_ID=1000 +ARG WODBY_GROUP_ID=1000 + ENV PHP_DEV="${PHP_DEV}" \ SSHD_PERMIT_USER_ENV="yes" \ RABBITMQ_C_VER="0.8.0" \ @@ -31,8 +34,14 @@ ENV PHP_DEV="${PHP_DEV}" \ RUN set -xe; \ \ - addgroup -g 1000 -S wodby; \ - adduser -u 1000 -D -S -s /bin/bash -G wodby wodby; \ + # Delete existing user/group if uid/gid occupied. + existing_group=$(getent group "${WODBY_GROUP_ID}" | cut -d: -f1); \ + if [[ -n "${existing_group}" ]]; then delgroup "${existing_group}"; fi; \ + existing_user=$(getent passwd "${WODBY_USER_ID}" | cut -d: -f1); \ + if [[ -n "${existing_user}" ]]; then deluser "${existing_user}"; fi; \ + \ + addgroup -g "${WODBY_GROUP_ID}" -S wodby; \ + adduser -u "${WODBY_USER_ID}" -D -S -s /bin/bash -G wodby wodby; \ adduser wodby www-data; \ sed -i '/^wodby/s/!/*/' /etc/shadow; \ echo "PS1='\w\$ '" >> /home/wodby/.bashrc; \ diff --git a/5.3/Makefile b/5.3/Makefile index a9557a65..da87c41c 100644 --- a/5.3/Makefile +++ b/5.3/Makefile @@ -7,6 +7,9 @@ REPO = wodby/php NAME = php-$(PHP_VER_MINOR) FROM_TAG = $(PHP_VER) +WODBY_USER_ID ?= 1000 +WODBY_GROUP_ID ?= 1000 + ifeq ($(TAG),) ifneq ($(PHP_DEBUG),) TAG ?= $(PHP_VER_MINOR)-debug @@ -42,6 +45,8 @@ build: --build-arg FROM_TAG=$(FROM_TAG) \ --build-arg PHP_DEV=$(PHP_DEV) \ --build-arg PHP_DEBUG=$(PHP_DEBUG) \ + --build-arg WODBY_USER_ID=$(WODBY_USER_ID) \ + --build-arg WODBY_GROUP_ID=$(WODBY_GROUP_ID) \ ./ test: diff --git a/5.6/Dockerfile b/5.6/Dockerfile index bd2da5a0..cfab0549 100644 --- a/5.6/Dockerfile +++ b/5.6/Dockerfile @@ -5,6 +5,9 @@ FROM wodby/base-php:${FROM_TAG} ARG PHP_DEV ARG PHP_DEBUG +ARG WODBY_USER_ID=1000 +ARG WODBY_GROUP_ID=1000 + ENV PHP_DEV="${PHP_DEV}" \ PHP_DEBUG="${PHP_DEBUG}" \ SSHD_PERMIT_USER_ENV="yes" \ @@ -53,8 +56,14 @@ ENV APP_ROOT="/var/www/html" \ RUN set -xe; \ \ - addgroup -g 1000 -S wodby; \ - adduser -u 1000 -D -S -s /bin/bash -G wodby wodby; \ + # Delete existing user/group if uid/gid occupied. + existing_group=$(getent group "${WODBY_GROUP_ID}" | cut -d: -f1); \ + if [[ -n "${existing_group}" ]]; then delgroup "${existing_group}"; fi; \ + existing_user=$(getent passwd "${WODBY_USER_ID}" | cut -d: -f1); \ + if [[ -n "${existing_user}" ]]; then deluser "${existing_user}"; fi; \ + \ + addgroup -g "${WODBY_GROUP_ID}" -S wodby; \ + adduser -u "${WODBY_USER_ID}" -D -S -s /bin/bash -G wodby wodby; \ adduser wodby www-data; \ sed -i '/^wodby/s/!/*/' /etc/shadow; \ echo "PS1='\w\$ '" >> /home/wodby/.bashrc; \ diff --git a/5.6/Makefile b/5.6/Makefile index 36e2841a..d5e58618 100644 --- a/5.6/Makefile +++ b/5.6/Makefile @@ -7,6 +7,9 @@ REPO = wodby/php NAME = php-$(PHP_VER_MINOR) FROM_TAG = $(PHP_VER) +WODBY_USER_ID ?= 1000 +WODBY_GROUP_ID ?= 1000 + ifeq ($(TAG),) ifneq ($(PHP_DEBUG),) TAG ?= $(PHP_VER_MINOR)-debug @@ -42,6 +45,8 @@ build: --build-arg FROM_TAG=$(FROM_TAG) \ --build-arg PHP_DEV=$(PHP_DEV) \ --build-arg PHP_DEBUG=$(PHP_DEBUG) \ + --build-arg WODBY_USER_ID=$(WODBY_USER_ID) \ + --build-arg WODBY_GROUP_ID=$(WODBY_GROUP_ID) \ ./ test: diff --git a/7/Dockerfile b/7/Dockerfile index 8d51ad08..0e47f422 100644 --- a/7/Dockerfile +++ b/7/Dockerfile @@ -5,6 +5,9 @@ FROM wodby/base-php:${FROM_TAG} ARG PHP_DEV ARG PHP_DEBUG +ARG WODBY_USER_ID=1000 +ARG WODBY_GROUP_ID=1000 + ENV PHP_DEV="${PHP_DEV}" \ PHP_DEBUG="${PHP_DEBUG}" \ SSHD_PERMIT_USER_ENV="yes" \ @@ -56,8 +59,14 @@ ENV APP_ROOT="/var/www/html" \ RUN set -xe; \ \ - addgroup -g 1000 -S wodby; \ - adduser -u 1000 -D -S -s /bin/bash -G wodby wodby; \ + # Delete existing user/group if uid/gid occupied. + existing_group=$(getent group "${WODBY_GROUP_ID}" | cut -d: -f1); \ + if [[ -n "${existing_group}" ]]; then delgroup "${existing_group}"; fi; \ + existing_user=$(getent passwd "${WODBY_USER_ID}" | cut -d: -f1); \ + if [[ -n "${existing_user}" ]]; then deluser "${existing_user}"; fi; \ + \ + addgroup -g "${WODBY_GROUP_ID}" -S wodby; \ + adduser -u "${WODBY_USER_ID}" -D -S -s /bin/bash -G wodby wodby; \ adduser wodby www-data; \ sed -i '/^wodby/s/!/*/' /etc/shadow; \ echo "PS1='\w\$ '" >> /home/wodby/.bashrc; \ diff --git a/7/Makefile b/7/Makefile index 17e1bbf4..0da60daf 100644 --- a/7/Makefile +++ b/7/Makefile @@ -7,6 +7,9 @@ REPO = wodby/php NAME = php-$(PHP_VER_MINOR) FROM_TAG = $(PHP_VER) +WODBY_USER_ID ?= 1000 +WODBY_GROUP_ID ?= 1000 + ifeq ($(TAG),) ifneq ($(PHP_DEBUG),) TAG ?= $(PHP_VER_MINOR)-debug @@ -42,6 +45,8 @@ build: --build-arg FROM_TAG=$(FROM_TAG) \ --build-arg PHP_DEV=$(PHP_DEV) \ --build-arg PHP_DEBUG=$(PHP_DEBUG) \ + --build-arg WODBY_USER_ID=$(WODBY_USER_ID) \ + --build-arg WODBY_GROUP_ID=$(WODBY_GROUP_ID) \ ./ test: