Skip to content

Commit

Permalink
replace Docker node with Volta
Browse files Browse the repository at this point in the history
  • Loading branch information
joelclermont committed Dec 15, 2023
1 parent bf2fd26 commit 3651dea
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 43 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ jobs:
path: node_modules
key: npm-${{ hashFiles('package-lock.json') }}

- name: Build node image
run: docker build -t "$PROJECT_NAME-node" docker/node
- name: Set up Volta to manage Node/Npm versions
uses: volta-cli/action@v4

- name: Install JS dependencies
run: docker/bin/npm-ci ci && docker/bin/npm-ci run build
run: npm install && npm run build

- name: Cache routes
run: docker exec "$PROJECT_NAME-php-fpm" ./artisan route:cache
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Anytime you add a private package, make sure to add a sanitized config to `auth.

New Laravel installs default to Vite.

Follow the Docker instructions in the README to make sure all npm commands are run through Docker containers.
Follow the instructions in the README to setup Volta to make sure all node/npm commands are run with the correct version.

Instead of using a separate bootstrap file, we load any necessary code directly in `app.js`

Expand Down
23 changes: 8 additions & 15 deletions README_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Then, generate the certificates for this project and put them into a location ac

`mkcert -cert-file docker/nginx/ssl.pem -key-file docker/nginx/key.pem my-project.test`

### Node environment
The best option to ensure you're using the correct versions of Node and npm with this project is to install [Volta](https://volta.sh). Volta will read the pinned versions of Node and npm from the `package.json` so you can be sure you're using the correct versions.

### Get the project running in Docker

Docker is used for local development. It's self-contained, easy to set up, and matches the exact versions of key services
Expand All @@ -80,11 +83,6 @@ may take a few minutes to pull down images and build the containers. Subsequent

You can verify that your containers are in a running state with `docker compose ps`.

The one tool that we don't manage through Docker Compose is `node`/`npm`. The reason is that `node` only needs to run on demand,
and not be constantly run in the background while we're doing development.

To build the `node`/`npm` container, run: `docker build -t my-project-node docker/node`

**Composer licensing**

> If this project uses a paid Composer package, like Nova, document it here
Expand All @@ -106,8 +104,8 @@ about versions of tooling will no longer apply.
To make it easier to run tools via Docker, a collection of simple shell scripts exists in the project's `docker/bin` directory.

Run these commands to finish the local development setup
* `docker/bin/npm install`
* `docker/bin/npm run dev`
* `npm install`
* `npm run dev`
* `docker/bin/composer install`
* `docker/bin/composer run post-root-package-install`
* `docker/bin/composer run post-create-project-cmd`
Expand Down Expand Up @@ -222,16 +220,11 @@ container and run `php -v` from the terminal that launches.

### Node/npm

If you want to change the version of Node edit the first line in `docker/node/Dockerfile` to reflect the desired version
number. Make sure to pick the alpine version of any image.

To update npm, change the first RUN line to reference the correct version.

For either change, you'll need to rebuild the images: (we don't have to stop or remove since node isn't running all the time)
If you want to change the version of `node`, run `volta pin node@XYZ` where `XYZ` is the desired version. The same works for `npm` with `volta pin npm@XYZ`

1. Rebuild the containers: `docker build --no-cache -t my-project-node docker/node` (Bypassing the cache isn't always necessary, but it's a safe default)
This will update the corresponding sections of the `volta` object in `package.json`.

To verify the correct version is now running, you can run `docker/bin/npm -v`.
To verify the correct version is now running, you can run `node -v` or `npm -v`.

## Deployment / CI Process

Expand Down
6 changes: 0 additions & 6 deletions docker/bin/npm

This file was deleted.

6 changes: 0 additions & 6 deletions docker/bin/npm-ci

This file was deleted.

11 changes: 0 additions & 11 deletions docker/node/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@
"vite": "^3.0.0",
"vitest": "^0.21.1",
"vue": "^3.2.37"
},
"volta": {
"node": "20.10.0",
"npm": "10.2.5"
}
}

0 comments on commit 3651dea

Please sign in to comment.