From 3651dea6efdf1725ca749ac5042f56aa05ed1890 Mon Sep 17 00:00:00 2001 From: Joel Clermont Date: Fri, 15 Dec 2023 14:07:14 -0600 Subject: [PATCH] replace Docker node with Volta --- .github/workflows/ci.yml | 6 +++--- README.md | 2 +- README_TEMPLATE.md | 23 ++++++++--------------- docker/bin/npm | 6 ------ docker/bin/npm-ci | 6 ------ docker/node/Dockerfile | 11 ----------- package-lock.json | 2 +- package.json | 4 ++++ 8 files changed, 17 insertions(+), 43 deletions(-) delete mode 100755 docker/bin/npm delete mode 100755 docker/bin/npm-ci delete mode 100644 docker/node/Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf67b17..f21071a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/README.md b/README.md index 93f4928..f364007 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md index cb55b0f..38ce672 100644 --- a/README_TEMPLATE.md +++ b/README_TEMPLATE.md @@ -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 @@ -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 @@ -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` @@ -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 diff --git a/docker/bin/npm b/docker/bin/npm deleted file mode 100755 index 69e868c..0000000 --- a/docker/bin/npm +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -source "`dirname $0`/../../.env" - -# this docker script is different because the node container only runs as we need it -docker run -it --rm -e "TERM=xterm-256color" -v $(pwd):/usr/src/app -w /usr/src/app -p 30098:30098 --name "$COMPOSE_PROJECT_NAME"-node "$COMPOSE_PROJECT_NAME"-node npm "$@" diff --git a/docker/bin/npm-ci b/docker/bin/npm-ci deleted file mode 100755 index ea3559c..0000000 --- a/docker/bin/npm-ci +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -source "`dirname $0`/../../.env" - -# this docker script is different because the node container only runs as we need it -docker run --rm -e npm_config_cache=/tmp -v $(pwd):/usr/src/app -w /usr/src/app "$COMPOSE_PROJECT_NAME"-node npm "$@" diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile deleted file mode 100644 index ead5d15..0000000 --- a/docker/node/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM --platform=linux/amd64 node:16.18.0-alpine3.16 - -# starting with node 16 the default work directory changed to someplace with existing files, we set it to a clean folder -WORKDIR /usr/app - -# after installing a specific npm version, we move it into the correct location and clean up the remaining source files -RUN npm install npm@8.15.0 \ - && rm -rf /usr/local/lib/node_modules/npm \ - && mv /usr/app/node_modules/npm /usr/local/lib/node_modules/npm \ - && rm -rf /usr/app/node_modules \ - && rm /usr/app/package.json /usr/app/package-lock.json diff --git a/package-lock.json b/package-lock.json index 6925576..945596c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "app", + "name": "laravel-project-standard", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index d049c13..81f8868 100644 --- a/package.json +++ b/package.json @@ -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" } }