Skip to content

Commit

Permalink
Merge pull request #514 from kiloutyg/511-add-the-finishing-touch-for…
Browse files Browse the repository at this point in the history
…-prod-ready-podman-infrastructure

switch from nonroot to www-data user
  • Loading branch information
kiloutyg authored Jan 24, 2025
2 parents a84323c + eb8b19d commit 48872d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ symfony copy.lock
.composer
.cache
.php-cs-fixer.dist.php


test.yml
18 changes: 7 additions & 11 deletions docker/dockerfileGHA.prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

FROM php:8.2-apache-bookworm AS base

# Create a non-root user and group
RUN addgroup --system nonroot \
&& adduser --system --ingroup nonroot nonroot

# Set the working directory inside the container
WORKDIR /var/www

# Copy custom php.ini configuration into the container
COPY ./docker/dockerfileGHA.dev/php.ini /usr/local/etc/php/php.ini
COPY ./docker/dockerfileGHA.prod/php.ini /usr/local/etc/php/php.ini

# Configure system settings and install necessary packages and extensions
RUN \
Expand Down Expand Up @@ -101,25 +97,25 @@ RUN \
# Move Symfony CLI to a global location
&& mv /root/.symfony5/bin/symfony /usr/local/bin/symfony \
# Change /var/www ownership
&& chown -R nonroot:nonroot /var/www
&& chown -R www-data:www-data /var/www

# Switch to non-root user
USER nonroot
USER www-data

# Building stage
FROM base AS building

# Switch to non-root user
USER nonroot
USER www-data


RUN mkdir -p /var/www/building \
&& chown -R nonroot:nonroot /var/www/building
&& chown -R www-data:www-data /var/www/building
# Set working directory
WORKDIR /var/www/building

# Copy application code with correct ownership
COPY --chown=nonroot:nonroot --chmod=755 . /var/www/building
COPY --chown=www-data:www-data --chmod=755 . /var/www/building

# Install dependencies and perform build steps
RUN cp .env.test .env \
Expand All @@ -134,4 +130,4 @@ RUN cp .env.test .env \

WORKDIR /var/www

CMD [ "exec apache2-foreground" ]
CMD [ "apache2-foreground" ]

0 comments on commit 48872d9

Please sign in to comment.