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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
**/Thumbs.db
.github/
docs/
node_modules/
public/bundles/
tests/
var/
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ A [Docker](https://www.docker.com/)-based installer and runtime for the [Symfony
1. [Build options](docs/build.md)
2. [Using Symfony Docker with an existing project](docs/existing-project.md)
3. [Support for extra services](docs/extra-services.md)
4. [Deploying in production](docs/production.md)
5. [Debugging with Xdebug](docs/xdebug.md)
6. [Using a Makefile](docs/makefile.md)
7. [Troubleshooting](docs/troubleshooting.md)
4. [Building CSS and JS](docs/build-css-js.md)
5. [Deploying in production](docs/production.md)
6. [Debugging with Xdebug](docs/xdebug.md)
7. [Using a Makefile](docs/makefile.md)
8. [Troubleshooting](docs/troubleshooting.md)

## Credits

Expand Down
71 changes: 71 additions & 0 deletions docs/build-css-js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Building CSS and JS

For security reason and limit the size of the container, the default stack doesn't include any development "artifacts".
To add it to the project and your development workflow follow this guide.

*This example uses `npm` and [Webpack Encore](https://symfony.com/doc/current/frontend.html).*

Modify `Dockerfile` to build your assets :

- At the top of the file before anything else
```diff
ARG PHP_VERSION=8.1
ARG CADDY_VERSION=2
+ARG NODE_VERSION=18
+
+# node "stage"
+FROM node:${NODE_VERSION}-alpine AS symfony_node
+
+WORKDIR /srv/app
+
+COPY package*.json ./
+
+RUN npm install
+## If you are building your code for production
+# RUN npm ci --only=production
+
+## You need to copy everything to use PostCSS, Tailwinds, ...
+COPY . .
+
+RUN npm run build

# "php" stage
```

- Then copy the built output in `public/build` (the configuration default) to the `php` container (which will then be copied later to `caddy`).

```diff
VOLUME /srv/app/var

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

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

FROM caddy:${CADDY_VERSION}-builder-alpine AS symfony_caddy_builder
```

Modify `docker-compose.override.yml` to add a `node` container in your development environment.
This will provide you with hot module reloading.

```diff
caddy:
volumes:
- ./docker/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
- ./public:/srv/app/public:ro

+ node:
+ build:
+ context: .
+ target: symfony_node
+ volumes:
+ - ./:/srv/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 --host 0.0.0.0"'
```

If file changes are not picked up, refer to this page:
https://symfony.com/doc/current/frontend/encore/virtual-machine.html#file-watching-issues