From 1447c27954faf5cc22339e70cc35cf30f339af2c Mon Sep 17 00:00:00 2001 From: ripaelit 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 5a8aa0e..a00eeff 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 a9557a6..da87c41 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 bd2da5a..cfab054 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 36e2841..d5e5861 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 8d51ad0..0e47f42 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 17e1bbf..0da60da 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: