Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
fix: #495 and #488 (#496)
Browse files Browse the repository at this point in the history
* fix: #495 and #488

* fix: tweaked ownership on var files

* fix: moved chown to last action b4 startup
  • Loading branch information
tobybatch authored Mar 24, 2023
1 parent 8d34178 commit 0fae66b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ RUN docker-php-ext-install -j$(nproc) xsl
# php extension redis
FROM ${BASE}-php-ext-base AS php-ext-redis
RUN yes no | pecl install redis && \
docker-php-ext-enable redis
docker-php-ext-enable redis

# php extension opcache
FROM ${BASE}-php-ext-base AS php-ext-opcache
Expand Down Expand Up @@ -258,8 +258,8 @@ ENV COMPOSER_MEMORY_LIMIT=-1
# If this set then the image will start, run a self test and then exit. It's used for the release process
ENV TEST_AND_EXIT=
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV USER_ID=1000
ENV GROUP_ID=1000
ENV USER_ID=
ENV GROUP_ID=

VOLUME [ "/opt/kimai/var" ]

Expand Down
2 changes: 2 additions & 0 deletions assets/service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ function handleStartup() {
}

function runServer() {
# Just while I'm fixing things
/opt/kimai/bin/console kimai:reload --env="$APP_ENV"
chown -R $USER_ID:$GROUP_ID /opt/kimai/var
if [ -e /use_apache ]; then
/usr/sbin/apache2ctl -D FOREGROUND
elif [ -e /use_fpm ]; then
Expand Down
43 changes: 21 additions & 22 deletions assets/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,52 +43,51 @@ function config() {
}

function handleStartup() {
set -x
# set mem limits and copy in custom logger config
if [ "${APP_ENV}" == "prod" ]; then
sed -i "s/128M/${memory_limit}M/g" /usr/local/etc/php/php.ini
if [ "${KIMAI:0:1}" -lt "2" ]; then
cp /assets/monolog-prod.yaml /opt/kimai/config/packages/prod/monolog.yaml
else
cp /assets/monolog.yaml /opt/kimai/config/packages/monolog.yaml
fi
sed -i "s/memory_limit.*/memory_limit=$memory_limit/g" /usr/local/etc/php/php.ini
if [ "${KIMAI:0:1}" -lt "2" ]; then
cp /assets/monolog-prod.yaml /opt/kimai/config/packages/prod/monolog.yaml
cp /assets/monolog-dev.yaml /opt/kimai/config/packages/dev/monolog.yaml
else
sed -i "s/128M/${memory_limit}M/g" /usr/local/etc/php/php.ini
if [ "${KIMAI:0:1}" -lt "2" ]; then
cp /assets/monolog-dev.yaml /opt/kimai/config/packages/dev/monolog.yaml
else
cp /assets/monolog.yaml /opt/kimai/config/packages/monolog.yaml
fi
cp /assets/monolog.yaml /opt/kimai/config/packages/monolog.yaml
fi
set +x

tar -zx -C /opt/kimai -f /var/tmp/public.tgz



if [ -z "$USER_ID" ]; then
USER_ID=$(id -u www-data)
fi
if [ -z "$GROUP_ID" ]; then
GROUP_ID=$(id -g www-data)
fi

chown -R $USER_ID:$GROUP_ID /opt/kimai
chown -R $USER_ID:$GROUP_ID /usr/local/etc/php/php.ini
# if group doesn't exist
if grep -w "$GROUP_ID" /etc/group &>/dev/null; then
echo Group already exists
else
echo www-kimai:x:"$GROUP_ID": >> /etc/group
pwconv
fi

# if user doesn't exist
if id $USER_ID &>/dev/null; then
if id "$USER_ID" &>/dev/null; then
echo User already exists
else
echo www-kimai:x:$USER_ID:$GROUP_ID:www-kimai:/var/www:/usr/sbin/nologin >> /etc/passwd
echo www-data:x:33: >> /etc/group
echo www-kimai:x:"$USER_ID":"$GROUP_ID":www-kimai:/var/www:/usr/sbin/nologin >> /etc/passwd
pwconv
fi

if [ -e /use_apache ]; then
export APACHE_RUN_USER=$(id -nu 33)
export APACHE_RUN_GROUP=$(id -ng 33)
echo "APACHE_RUN_USER=$(id -nu "$USER_ID")" >> /etc/apache2/envvars
# This doesn't _exactly_ run as the specified GID, it runs as the GID of the specified user but WTF
echo "APACHE_RUN_GROUP=$(id -ng "$USER_ID")" >> /etc/apache2/envvars
tail -n2 /etc/apache2/envvars
elif [ -e /use_fpm ]; then
sed -i "s/user = .*/user = $USER_ID/g" /usr/local/etc/php-fpm.d/www.conf
sed -i "s/group = .*/group = $GROUP_ID/g" /usr/local/etc/php-fpm.d/www.conf
echo "Setting fpm to run as ${USER_ID}:${GROUP_ID}"
else
echo "Error, unknown server type"
fi
Expand Down

0 comments on commit 0fae66b

Please sign in to comment.