Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to add npm (or yarn) #186

Closed
wants to merge 1 commit into from

Conversation

rowanparker
Copy link
Contributor

As per #129

docs/build-css-js.md Outdated Show resolved Hide resolved
docs/build-css-js.md Outdated Show resolved Hide resolved
docs/build-css-js.md Outdated Show resolved Hide resolved
docs/build-css-js.md Outdated Show resolved Hide resolved
docs/build-css-js.md Outdated Show resolved Hide resolved
docs/build-css-js.md Outdated Show resolved Hide resolved
docs/build-css-js.md Outdated Show resolved Hide resolved
@dunglas
Copy link
Owner

dunglas commented Dec 16, 2021

@maxhelias do you think we can merge this one?

@maxhelias
Copy link
Collaborator

I unresolve some of the suggested changes because they have not been apply, unless that has changed and I apologize.

@rowanparker
Copy link
Contributor Author

I unresolve some of the suggested changes because they have not been apply, unless that has changed and I apologize.

Sorry, I forgot all about this PR. I've accepted the suggested changes!

@maxhelias
Copy link
Collaborator

@dunglas Like that, it seems fair to me

docs/build-css-js.md Outdated Show resolved Hide resolved
@louismariegaborit
Copy link

I tried the suggested configuration but HMR not working.
What configuration did I missed ?

@vasilvestre
Copy link

vasilvestre commented Feb 12, 2022

If you are using symfony ux, you can encounter an issue with dependencies located in vendor not found.

error Package "" refers to a non-existing file '"/srv/app/vendor/symfony/ux-chartjs/Resources/assets"'.

I'm working on a fix, that copy vendor volume from php image to the temporary node and then copy the build result to caddy but any help would be welcome

@belmeopmenieuwesim
Copy link

belmeopmenieuwesim commented Feb 20, 2022

If you are using symfony ux, you can encounter an issue with dependencies located in vendor not found.

error Package "" refers to a non-existing file '"/srv/app/vendor/symfony/ux-chartjs/Resources/assets"'.

I'm working on a fix, that copy vendor volume from php image to the temporary node and then copy the build result to caddy but any help would be welcome

If you did not solve it yourself already, I solved it like this:

## pre stage "php_build" (notice this is not the final stage, it will be used as a base for the final stage later on)
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_php_build
# ... original lines ...


## final stage "node"
FROM node:${NODE_VERSION}-alpine AS symfony_node
WORKDIR /srv/app
# this COPY makes sure we get all files including vendor from the `symfony_php_build` stage
COPY --from=symfony_php_build /srv/app .
RUN yarn install
## If you are building your code for production
# RUN npm ci --only=production
RUN yarn run build

## final stage "php"
FROM symfony_php_build AS symfony_php
COPY --from=symfony_node /srv/app/public/build public/build

## final stage "caddy"
# ... original lines ...

@mario-fehr
Copy link

Any plans to fix and merger this?

@maxhelias maxhelias force-pushed the main branch 2 times, most recently from e2c2e08 to 1d347dd Compare July 28, 2022 09:11
@maxhelias maxhelias requested a review from dunglas July 28, 2022 09:13
@maxhelias
Copy link
Collaborator

I updated the PR to move forward on this topic, however the remark about Symfony UX is still valid, I haven't thought about the problem yet

@maxhelias maxhelias added help wanted documentation Documentation needs adjustment labels Jul 28, 2022
@maxhelias maxhelias mentioned this pull request Jul 28, 2022
@dunglas
Copy link
Owner

dunglas commented Jul 31, 2022

In #271 I introduced a dev stage. Maybe could we install Node in this dev image?

Create build-css-js.md

Update build-css-js.md

Update README.md

Update .dockerignore

Update docs/build-css-js.md

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

Update docs/build-css-js.md

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

Update docs/build-css-js.md

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

Update docs/build-css-js.md

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

Update docs/build-css-js.md

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

Update docs/build-css-js.md

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

Update build-css-js.md

Update build-css-js.md

Update build-css-js.md

Update build-css-js.md

Rework
@Spomky
Copy link

Spomky commented Feb 3, 2023

Hi,

Thank you for this PR. I followed the steps and it works fine.
However, sometimes the url given after compilation starts with https://0.0.0.0 instead of the expected https://localhost:8080.
Have I missed something?

Regards.

@Spomky
Copy link

Spomky commented Feb 4, 2023

Also, another issue I have:

failed to solve: executor failed running [/bin/sh -c npm install --force]: exit code: 254
make: *** [Makefile:25: build] Error 17

It started to appear when I added Symfony UX dependencies.
These deps add new entries in packages.json that are not available as composer install is called later.

"@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/assets",
"@symfony/ux-live-component": "file:vendor/symfony/ux-live-component/assets",

Any ideas on how to solve this?

@maxhelias
Copy link
Collaborator

Hi @Spomky,

Hum, It's been a while since I took up the subject and I remember that Symfony UX packages were a problem for the compilation.

For SymfonyUX, I think we should rethink the approach with either making a new build stage or including nodejs in the dev stage

@Spomky
Copy link

Spomky commented Feb 5, 2023

Hello @maxhelias

Hereafter a working configuration for NPM, heavily inspired by the work of @CedricHerzog in #365 (with some extra parameters).
The host/port issue in #186 (comment) is still there, but now it is building successfully.

--- Dockerfile	2023-02-05 09:59:06.335530332 +0100
+++ Dockerfile	2023-02-05 10:01:48.285534169 +0100
@@ -4,6 +4,11 @@
 # https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
 # https://docs.docker.com/compose/compose-file/#target
 
+ARG PHP_VERSION=8.2
+ARG CADDY_VERSION=2.6
+ARG NODE_VERSION=19
+
+
 # Builder images
 FROM composer/composer:2-bin AS composer
 
@@ -19,7 +24,7 @@
 	--with github.com/dunglas/vulcain/caddy
 
 # Prod image
-FROM php:8.2-fpm-alpine AS app_php
+FROM php:${PHP_VERSION}-fpm-alpine AS app_composer
 
 # Allow to use development versions of Symfony
 ARG STABILITY="stable"
@@ -101,6 +106,22 @@
 		chmod +x bin/console; sync; \
     fi
 
+# node "stage"
+FROM node:${NODE_VERSION}-alpine AS symfony_node
+
+COPY --link --from=app_composer /srv/app /app/
+
+WORKDIR /app
+
+RUN npm install --force
+RUN npm run build
+## If you are building your code for production
+# RUN npm ci --only=production
+
+FROM app_composer AS app_php
+COPY --from=symfony_node --link /app/public/build /srv/app/public/build/
+
+
 # Dev image
 FROM app_php AS app_php_dev
 
@@ -119,10 +140,11 @@
 RUN rm -f .env.local.php
 
 # Caddy image
-FROM caddy:2.6-alpine AS app_caddy
+FROM caddy:${CADDY_VERSION}-alpine AS app_caddy
 
 WORKDIR /srv/app
 
 COPY --from=app_caddy_builder --link /usr/bin/caddy /usr/bin/caddy
 COPY --from=app_php --link /srv/app/public public/
 COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile
+COPY --from=symfony_node --link /app/public/build /srv/app/public/build/

@packagespace
Copy link

packagespace commented Mar 8, 2023

For anyone trying to get this to work:

  • Use these changes: Document how to add npm (or yarn) #186 (comment)
  • Modify .dockerignore and docker-compose.override.yml as per the PR contents
  • Change the volume for the node container in docker-compose.override.yml from ./:/srv/app to ./:/app Sorry, huge misunderstanding on my part on how webpack dev-server works. Seems to be an issue with what files are being watched however. Seems to work fine after all, but the node container command needs to have --public https://localhost:8080 added to it. Hot Module Reloading seems to not work.

@packagespace
Copy link

Managed to get this to work with HMR as well:

  • Follow the steps in my last comment
  • Change node container command in docker-compose.override.yml to 'sh -c "npm install; npm run dev-server -- --server-type https --client-web-socket-url https://localhost:8080/ws --host 0.0.0.0 --public https://localhost:8080"'

Haven't tested the config in production yet.

@Spomky
Copy link

Spomky commented Mar 18, 2023

Hi @packagespace,

I confirm it works fine in a dev env. You rock!
I don't have any opportunity to push it in production as this template is only used for a local context.
In addition to the proposed change here above, I also followed the steps described in this thread. It could be great if this repository could also take advantages if the suggested modifications in this PR. WDYT?

@packagespace
Copy link

@Spomky Thanks for the feedback. I'll have a chance to try it in production soon but since the build seems to work fine in the node stage I don't think there will be any issues.

I looked at the thread you linked and I'm curious about a few things now (bear in mind I'm not very experienced with Docker and node):

  • Is it necessary to copy the entire /srv/app directory to the node image?
    • I understand that copying package*.json is not sufficient due to the Symfony UX deps needing some files in /vendor, but what if we copied only package*.json and /vendor?
    • I imagine /assets and webpack.config.js are also needed for the npm build step, could these also be copied explicitly after running npm install to avoid invalidating the cache?
    • Here's an attempt at it (unsure about my use of trailing slashes):
FROM node:${NODE_VERSION}-alpine AS symfony_node

COPY --link --from=app_composer /srv/app/package*.json /app/
COPY --link --from=app_composer /srv/app/vendor /app/vendor

WORKDIR /app

RUN npm install --force

COPY --link --from=app_composer /srv/app/assets /app/assets
COPY --link --from=app_composer /srv/app/webpack.config.js /app/

RUN npm run build
  • I'm wondering about the necessity of having both npm install and npm ci --production-only in the Dockerfile. As far as I understand the node_modules folder for this step is never copied to any other image? I suppose it would make sense if you wanted to have a node container in production? If that's the case, maybe it could be stated more explicitly?

@lchhieu
Copy link

lchhieu commented Jun 6, 2023

It does not work, Any update or solution?

@Romaixn
Copy link

Romaixn commented Jun 6, 2023

@lchhieu What's wrong? I tried it a while ago and everything worked fine. If you have any errors or concerns, don't hesitate to post them - it's hard to help you like this!

@lchhieu
Copy link

lchhieu commented Jun 6, 2023

@lchhieu What's wrong? I tried it a while ago and everything worked fine. If you have any errors or concerns, don't hesitate to post them - it's hard to help you like this!

I tried add this code before caddy image but public/build does not copied

FROM app_php AS symfony_php
COPY --from=symfony_node /srv/app/public/build public/build
# Caddy image
FROM caddy:2-alpine AS app_caddy

@Jioleoo
Copy link

Jioleoo commented Jun 6, 2023

I did it a few weeks, I followed this thread and found a way to make it work:

in Dockerfile
I changed the name of the base php image

# Prod image
- FROM php:8.2-fpm-alpine AS app_php
+ FROM php:${PHP_VERSION}-fpm-alpine AS app_composer

then under of all the PHP prod stage

# node "stage"
FROM node:${NODE_VERSION}-alpine AS symfony_node

COPY --link --from=app_composer /srv/app /app/

WORKDIR /app

RUN npm install --force
RUN npm run build
## If you are building your code for production
# RUN npm ci --only=production
FROM app_composer AS app_php
COPY --from=symfony_node --link /app/public/build /srv/app/public/build/

and add this line at the bottom of Dockerfile (dont know if its relevant because we already had this line before):

COPY --from=symfony_node --link /app/public/build /srv/app/public/build/

And in docker-compose.override.yml :

  node:
      build:
        context: .
        target: symfony_node
      volumes:
        - ./:/app
      ports:
      - target: 8080
        published: 8080
        protocol: tcp
      command: 'sh -c "npm install; npm run dev-server -- --server-type https --client-web-socket-url https://localhost:8080/ws --host 0.0.0.0 --public https://localhost:8080"'

And you can had the versions envvar at the top of Dockerfile or elsewhere :

ARG PHP_VERSION=8.2
ARG CADDY_VERSION=2.6
ARG NODE_VERSION=19

In your case this line FROM app_php AS symfony_php is before caddy that's why it doesn't work, it has to be under the app_php stage.

@lchhieu
Copy link

lchhieu commented Jun 6, 2023

@Jioleoo Could you give me your full Dockerfile. Although I followed your idea but public/build still not exist


ARG PHP_VERSION=8.2
ARG CADDY_VERSION=2.6
ARG NODE_VERSION=19

FROM caddy:2.7-builder-alpine AS app_caddy_builder

RUN xcaddy build v2.6.4 \
	--with github.com/dunglas/mercure/caddy \
	--with github.com/dunglas/vulcain/caddy

# Prod image
FROM php:${PHP_VERSION}-fpm-alpine AS app_php

# Allow to use development versions of Symfony
ARG STABILITY="stable"
ENV STABILITY ${STABILITY}

# Allow to select Symfony version
ARG SYMFONY_VERSION=""
ENV SYMFONY_VERSION ${SYMFONY_VERSION}

ENV APP_ENV=prod

WORKDIR /srv/app

# php extensions installer: https://github.com/mlocati/docker-php-extension-installer
COPY --from=mlocati/php-extension-installer:latest --link /usr/bin/install-php-extensions /usr/local/bin/

# persistent / runtime deps
# hadolint ignore=DL3018
RUN apk add --no-cache \
		acl \
		fcgi \
		file \
		gettext \
		git \
	;

RUN set -eux; \
    install-php-extensions \
		apcu \
		intl \
		opcache \
		zip \
    ;

###> recipes ###
###> doctrine/doctrine-bundle ###
RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev; \
	docker-php-ext-install -j"$(nproc)" pdo_pgsql; \
	apk add --no-cache --virtual .pgsql-rundeps so:libpq.so.5; \
	apk del .pgsql-deps
###< doctrine/doctrine-bundle ###
###< recipes ###

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY --link docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/
COPY --link docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/

COPY --link docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
RUN mkdir -p /var/run/php

COPY --link docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck

HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]

COPY --link docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PATH="${PATH}:/root/.composer/vendor/bin"

COPY --from=composer/composer:2-bin --link /composer /usr/bin/composer

# prevent the reinstallation of vendors at every changes in the source code
COPY --link composer.* symfony.* ./
RUN set -eux; \
    if [ -f composer.json ]; then \
		composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress; \
		composer clear-cache; \
    fi

# copy sources
COPY --link  . ./
RUN rm -Rf docker/

RUN set -eux; \
	mkdir -p var/cache var/log; \
    if [ -f composer.json ]; then \
		composer dump-autoload --classmap-authoritative --no-dev; \
		composer dump-env prod; \
		composer run-script --no-dev post-install-cmd; \
		chmod +x bin/console; sync; \
    fi

# Dev image
FROM app_php AS app_php_dev

ENV APP_ENV=dev XDEBUG_MODE=off
VOLUME /srv/app/var/

RUN rm "$PHP_INI_DIR/conf.d/app.prod.ini"; \
	mv "$PHP_INI_DIR/php.ini" "$PHP_INI_DIR/php.ini-production"; \
	mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

COPY --link docker/php/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/

RUN set -eux; \
	install-php-extensions \
    	xdebug \
    ;

RUN rm -f .env.local.php

# node "stage"
FROM node:${NODE_VERSION}-alpine AS symfony_node

COPY --link --from=app_php /srv/app /app/

WORKDIR /app

RUN npm install --force
RUN npm run build
## If you are building your code for production
# RUN npm ci --only=production
FROM app_php AS app_php_dev
COPY --from=symfony_node --link /app/public/build /srv/app/public/build/


# Caddy image
FROM caddy:2-alpine AS app_caddy

WORKDIR /srv/app

COPY --from=app_caddy_builder --link /usr/bin/caddy /usr/bin/caddy
COPY --from=app_php --link /srv/app/public public/
COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile
COPY --from=symfony_node --link /app/public/build /srv/app/public/build/

@Jioleoo
Copy link

Jioleoo commented Jun 9, 2023

@lchhieu

#syntax=docker/dockerfile:1.4

# The different stages of this Dockerfile are meant to be built into separate images
# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
# https://docs.docker.com/compose/compose-file/#target

ARG PHP_VERSION=8.2
ARG CADDY_VERSION=2.6
ARG NODE_VERSION=19

# Builder images
FROM composer/composer:2-bin AS composer

FROM mlocati/php-extension-installer:latest AS php_extension_installer

# Build Caddy with the Mercure and Vulcain modules
FROM caddy:${CADDY_VERSION}-builder-alpine AS app_caddy_builder

RUN xcaddy build \
	--with github.com/dunglas/mercure \
	--with github.com/dunglas/mercure/caddy \
	--with github.com/dunglas/vulcain \
	--with github.com/dunglas/vulcain/caddy

# Prod image
FROM php:${PHP_VERSION}-fpm-alpine AS app_composer

# Allow to use development versions of Symfony
ARG STABILITY="stable"
ENV STABILITY ${STABILITY}

# Allow to select Symfony version
ARG SYMFONY_VERSION=""
ENV SYMFONY_VERSION ${SYMFONY_VERSION}

ENV APP_ENV=prod

WORKDIR /srv/app

# php extensions installer: https://github.com/mlocati/docker-php-extension-installer
COPY --from=php_extension_installer --link /usr/bin/install-php-extensions /usr/local/bin/

# persistent / runtime deps
RUN apk add --no-cache \
		acl \
		fcgi \
		file \
		gettext \
		git \
	;

RUN set -eux; \
    install-php-extensions \
    	apcu \
    	intl \
		opcache \
    	zip \
    ;

###> recipes ###
###> doctrine/doctrine-bundle ###
RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev; \
	docker-php-ext-install -j"$(nproc)" pdo_pgsql; \
	apk add --no-cache --virtual .pgsql-rundeps so:libpq.so.5; \
	apk del .pgsql-deps
###< doctrine/doctrine-bundle ###
###< recipes ###

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY --link docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/
COPY --link docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/

COPY --link docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
RUN mkdir -p /var/run/php

COPY --link docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck

HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]

COPY --link docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PATH="${PATH}:/root/.composer/vendor/bin"

COPY --from=composer --link /composer /usr/bin/composer

# prevent the reinstallation of vendors at every changes in the source code
COPY --link composer.* symfony.* ./
RUN set -eux; \
    if [ -f composer.json ]; then \
		composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress; \
		composer clear-cache; \
    fi

# copy sources
COPY --link  . ./
RUN rm -Rf docker/

RUN set -eux; \
	mkdir -p var/cache var/log; \
    if [ -f composer.json ]; then \
		composer dump-autoload --classmap-authoritative --no-dev; \
		composer dump-env prod; \
		composer run-script --no-dev post-install-cmd; \
		chmod +x bin/console; sync; \
    fi


# node "stage"
FROM node:${NODE_VERSION}-alpine AS symfony_node

COPY --link --from=app_composer /srv/app /app/

WORKDIR /app

RUN npm install --force
RUN npm run build
## If you are building your code for production
# RUN npm ci --only=production
FROM app_composer AS app_php
COPY --from=symfony_node --link /app/public/build /srv/app/public/build/


# Dev image
FROM app_php AS app_php_dev

ENV APP_ENV=dev XDEBUG_MODE=off
VOLUME /srv/app/var/

RUN rm "$PHP_INI_DIR/conf.d/app.prod.ini"; \
	mv "$PHP_INI_DIR/php.ini" "$PHP_INI_DIR/php.ini-production"; \
	mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

COPY --link docker/php/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/

RUN set -eux; \
	install-php-extensions \
    	xdebug \
    ;

RUN rm -f .env.local.php

# Caddy image
FROM caddy:${CADDY_VERSION}-alpine AS app_caddy

WORKDIR /srv/app

COPY --from=app_caddy_builder --link /usr/bin/caddy /usr/bin/caddy
COPY --from=app_php --link /srv/app/public public/
COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile
COPY --from=symfony_node --link /app/public/build /srv/app/public/build/

@ikakarov
Copy link

Why not add node directly on php container ? Symfony at this stage has requered NODE and yarn. I can't see reason to not use node in dev container.

@packagespace
Copy link

@rowanparker @dunglas @maxhelias
Hello

Considering we have a working configuration for this as per @Spomky's and my comments (#186 (comment) #186 (comment) #186 (comment) #186 (comment)), should we see if this PR can be modified and merged in order to avoid confusion as seen above?

If opening up a new PR would be easier to parse, I wouldn't mind taking care of it either.

@maxhelias
Copy link
Collaborator

Hi @packagespace,

I didn't really take the time for this topic but I reread the whole thread. I think opening a new PR with your work will be easier to analyze and compare.

Thanks for your time on this

@paweelkopec
Copy link

@lchhieu

#syntax=docker/dockerfile:1.4

# The different stages of this Dockerfile are meant to be built into separate images
# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
# https://docs.docker.com/compose/compose-file/#target

ARG PHP_VERSION=8.2
ARG CADDY_VERSION=2.6
ARG NODE_VERSION=19

# Builder images
FROM composer/composer:2-bin AS composer

FROM mlocati/php-extension-installer:latest AS php_extension_installer

# Build Caddy with the Mercure and Vulcain modules
FROM caddy:${CADDY_VERSION}-builder-alpine AS app_caddy_builder

RUN xcaddy build \
	--with github.com/dunglas/mercure \
	--with github.com/dunglas/mercure/caddy \
	--with github.com/dunglas/vulcain \
	--with github.com/dunglas/vulcain/caddy

# Prod image
FROM php:${PHP_VERSION}-fpm-alpine AS app_composer

# Allow to use development versions of Symfony
ARG STABILITY="stable"
ENV STABILITY ${STABILITY}

# Allow to select Symfony version
ARG SYMFONY_VERSION=""
ENV SYMFONY_VERSION ${SYMFONY_VERSION}

ENV APP_ENV=prod

WORKDIR /srv/app

# php extensions installer: https://github.com/mlocati/docker-php-extension-installer
COPY --from=php_extension_installer --link /usr/bin/install-php-extensions /usr/local/bin/

# persistent / runtime deps
RUN apk add --no-cache \
		acl \
		fcgi \
		file \
		gettext \
		git \
	;

RUN set -eux; \
    install-php-extensions \
    	apcu \
    	intl \
		opcache \
    	zip \
    ;

###> recipes ###
###> doctrine/doctrine-bundle ###
RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev; \
	docker-php-ext-install -j"$(nproc)" pdo_pgsql; \
	apk add --no-cache --virtual .pgsql-rundeps so:libpq.so.5; \
	apk del .pgsql-deps
###< doctrine/doctrine-bundle ###
###< recipes ###

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY --link docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/
COPY --link docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/

COPY --link docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
RUN mkdir -p /var/run/php

COPY --link docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck

HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]

COPY --link docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PATH="${PATH}:/root/.composer/vendor/bin"

COPY --from=composer --link /composer /usr/bin/composer

# prevent the reinstallation of vendors at every changes in the source code
COPY --link composer.* symfony.* ./
RUN set -eux; \
    if [ -f composer.json ]; then \
		composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress; \
		composer clear-cache; \
    fi

# copy sources
COPY --link  . ./
RUN rm -Rf docker/

RUN set -eux; \
	mkdir -p var/cache var/log; \
    if [ -f composer.json ]; then \
		composer dump-autoload --classmap-authoritative --no-dev; \
		composer dump-env prod; \
		composer run-script --no-dev post-install-cmd; \
		chmod +x bin/console; sync; \
    fi


# node "stage"
FROM node:${NODE_VERSION}-alpine AS symfony_node

COPY --link --from=app_composer /srv/app /app/

WORKDIR /app

RUN npm install --force
RUN npm run build
## If you are building your code for production
# RUN npm ci --only=production
FROM app_composer AS app_php
COPY --from=symfony_node --link /app/public/build /srv/app/public/build/


# Dev image
FROM app_php AS app_php_dev

ENV APP_ENV=dev XDEBUG_MODE=off
VOLUME /srv/app/var/

RUN rm "$PHP_INI_DIR/conf.d/app.prod.ini"; \
	mv "$PHP_INI_DIR/php.ini" "$PHP_INI_DIR/php.ini-production"; \
	mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

COPY --link docker/php/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/

RUN set -eux; \
	install-php-extensions \
    	xdebug \
    ;

RUN rm -f .env.local.php

# Caddy image
FROM caddy:${CADDY_VERSION}-alpine AS app_caddy

WORKDIR /srv/app

COPY --from=app_caddy_builder --link /usr/bin/caddy /usr/bin/caddy
COPY --from=app_php --link /srv/app/public public/
COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile
COPY --from=symfony_node --link /app/public/build /srv/app/public/build/

Could you give me an example for branch master?

I tried this: COPY --from=symfony_node --link /app/public/build /srv/app/public/build/

But after build the public directory contains index.php only

@LaurentSanson
Copy link

Hi all,

Have we got anything new on this please?

Best,

Laurent

@maxhelias
Copy link
Collaborator

The reworking of the project for FrankenPHP calls this integration into question.

What's more, with the new AssetMapper component, it might be more interesting to concentrate on it.

Thank you for your contribution in spite of everything. And if anyone would like to try with AssetMapper, a PR is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation needs adjustment enhancement help wanted
Projects
None yet
Development

Successfully merging this pull request may close these issues.