Skip to content

Commit

Permalink
Merge pull request #376 from biblioverse/docker-dev
Browse files Browse the repository at this point in the history
Improve dev/prod separation
  • Loading branch information
SergioMendolia authored Feb 7, 2025
2 parents 056d7b1 + 672703d commit 822974f
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 7 deletions.
86 changes: 86 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/.composer
/vendor/
docker-compose.override.yml
/backups/*.sql
/public/media/cache/*
!/public/images/.gitkeep
!/public/images/librairies
/public/images/librairies/*
!/public/images/librairies/.gitkeep
public/tmp
!/public/media/.gitkeep
/public/books
!/public/books/.gitkeep
/public/covers
!/public/covers/.gitkeep
/public/books/consume
!/public/books/consume/.gitkeep
/tests/coverage
!/tests/coverage/.gitkeep
###< symfony/framework-bundle ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###

###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> liip/imagine-bundle ###
/public/media/cache/
###< liip/imagine-bundle ###

###> symfony/webpack-encore-bundle ###
/node_modules/
/public/build/
npm-debug.log
yarn-error.log
###< symfony/webpack-encore-bundle ###

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###


# Custom docker override for https://github.com/typesense/typesense/issues/1351
typesense/*

# Test database
data/database.sqlite
*.pcap
.astro/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

###> php-cs-fixer/shim ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< php-cs-fixer/shim ###


### Dockerignore specific
doc
Dockerfile
docker-compose.yml
docker-compose.test.yml
justfile
phpstan.neon
phpunit.xml.dist
rector.php
renovate.json
upgrade.sh
tests
.git
43 changes: 39 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ARG NODE_VERSION=22

FROM ghcr.io/biblioverse/biblioteca-docker:2.0.2 AS base
WORKDIR /var/www/html

Expand All @@ -6,20 +8,53 @@ RUN mkdir -p /tmp && chown -R www-data:www-data /tmp && chmod -R 777 /tmp
RUN mkdir -p /var/run/ && chown -R www-data:www-data /var/run && chmod -R 777 /var/run
USER www-data

FROM base AS prod
# We install the dependencies in a separate layer as the frontend image also needs them
FROM base AS vendor
USER root
COPY . /var/www/html

RUN composer install
# Copying the full context is not great for caching
# But composer install executes symfony commands that need the full context
COPY composer.json composer.lock /var/www/html/

RUN composer install --no-interaction --no-progress --no-dev --no-scripts --optimize-autoloader

FROM node:${NODE_VERSION} AS frontend

WORKDIR /var/www/html

# Needed for some symfony specific modules
COPY --from=vendor /var/www/html/vendor /var/www/html/vendor

# Only copy what is needed, improves cacheability
COPY package.json package-lock.json webpack.config.js /var/www/html/
COPY assets/ /var/www/html/assets/

RUN npm install
RUN npm run build

RUN chown -R www-data:www-data /var/www/html
FROM base AS prod
USER root

COPY --chown=www-data:www-data . /var/www/html/

COPY --chown=www-data:www-data --from=vendor /var/www/html/vendor /var/www/html/vendor
COPY --chown=www-data:www-data --from=frontend /var/www/html/public/build /var/www/html/public/build

USER www-data

RUN composer install --no-interaction --no-progress --no-dev --optimize-autoloader

FROM base AS dev
USER root

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
wget \
git \
curl \
sudo \
vim \
nodejs

RUN /usr/local/bin/install-php-extensions xdebug

RUN echo ' \n\
Expand Down
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
services:
biblioteca:
image: ghcr.io/biblioverse/biblioteca-docker:2.0.2
build:
target: prod
target: dev
command: ["/bin/sh", "-c" , "apache2-foreground" ]
ports:
- "48480:8080" # Web
- "48181:8181" # NPM
depends_on:
- db
db:
condition: service_started
typesense:
condition: service_started
volumes:
- .:/var/www/html
- .composer:/home/.composer:cached
Expand Down

0 comments on commit 822974f

Please sign in to comment.