Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
+set -euo pipefail
set -euo pipefail

echo "=== Container Starting ==="
echo "Running initialization script..."
Expand Down
9 changes: 6 additions & 3 deletions docker/frankenphp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ ENV COMPOSER_ALLOW_SUPERUSER=1
# Change PHP config
COPY docker/php/php.ini /usr/local/etc/php/conf.d/base.ini

# Install supervisord and Node.js (includes npm)
RUN apt-get update && apt-get install -y \
# Install supervisord, Node.js, and su-exec
RUN apt-get update && apt-get install -y --no-install-recommends \
supervisor \
curl \
--no-install-recommends \
gosu \
&& curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Apply the user/group IDs to www-data
RUN usermod -u ${USER_ID} www-data && groupmod -g ${GROUP_ID} www-data

# Copy supervisord config
COPY docker/frankenphp/supervisord/supervisord.conf /etc/supervisor/supervisord.conf

Expand Down
28 changes: 20 additions & 8 deletions docker/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,33 @@ echo -e "${GREEN}Setup completed.${NC}"
if [ -f "/app/composer.json" ] && [ ! -d "/app/vendor" ]; then
echo -e "${YELLOW}Installing Composer dependencies...${NC}"

# Install dependencies based on environment
# Set up composer environment variables for www-data user
export HOME=/var/www
export COMPOSER_HOME=/var/www/.composer
export COMPOSER_CACHE_DIR=/var/www/.composer/cache

# Create composer cache directory and set ownership
echo -e "${YELLOW}Setting up composer cache...${NC}"
mkdir -p /var/www/.composer/cache
chown -R www-data:www-data /var/www/.composer

# Make /app writable by www-data (critical for mounted volumes)
echo -e "${YELLOW}Ensuring /app is writable...${NC}"
chmod 777 /app

# Install dependencies based on environment AS www-data user
if [ "$YII_ENV" = "prod" ]; then
# Production: exclude dev dependencies and optimize autoloader
composer install --no-dev --optimize-autoloader --no-interaction
gosu www-data env HOME=/var/www COMPOSER_HOME=/var/www/.composer COMPOSER_CACHE_DIR=/var/www/.composer/cache \
composer install --no-dev --optimize-autoloader --no-interaction
else
# Development: include dev dependencies
composer install --optimize-autoloader --no-interaction
fi

# Set proper ownership for vendor directory if possible
if chown -R www-data:www-data /app/vendor 2>/dev/null; then
echo -e "${GREEN}✓ Vendor directory ownership set${NC}"
gosu www-data env HOME=/var/www COMPOSER_HOME=/var/www/.composer COMPOSER_CACHE_DIR=/var/www/.composer/cache \
composer install --optimize-autoloader --no-interaction
fi

echo -e "${GREEN}✓ Composer dependencies installed successfully.${NC}"
echo -e "${GREEN}✓ Both vendor/ and node_modules/ should have correct permissions.${NC}"
fi

echo -e "${GREEN}Starting supervisord...${NC}"
Expand Down
Loading