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: