From bfc86816f108c2a2f2731f770df696393d7e5109 Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Wed, 10 Apr 2024 18:03:08 -0700 Subject: [PATCH] move npm ci to startup script --- Dockerfile | 10 ---------- README.md | 9 ++++++--- dev/Dockerfile | 12 ++++++++++++ dev/startupservice.sh | 14 ++++++++++++++ docker-compose.yml | 7 ++----- publish.sh | 8 +++++--- 6 files changed, 39 insertions(+), 21 deletions(-) delete mode 100644 Dockerfile create mode 100644 dev/Dockerfile create mode 100644 dev/startupservice.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 906bb36b..00000000 --- a/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -# https://hub.docker.com/_/node/ -FROM node:14 - -WORKDIR /app -COPY package.json package-lock.json ./ -RUN npm install - -EXPOSE 8080 - -CMD ["npm", "run", "serve"] diff --git a/README.md b/README.md index 681b6ff4..b1af4711 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,9 @@ In order to have the code up and running on your machine, build the Docker conta docker-compose up ``` +If there is `node_modules` directory, it will perform a clean install from +`package-lock.json`. + ### Step 5: Access the Application Once the container is running, you can access the Creative Commons Chooser application by navigating to the following URL in your web browser: @@ -87,13 +90,13 @@ http://localhost:8080 ### Commands Run the following commands in order to have the code up and running on your machine: +Clean install dependencies from package-lock.json: ``` bash -# install dependencies -npm install +npm ci ``` +Build and serve assets with hot-reload ```bash -# Build and serve assets with hot-reload npm run serve ``` diff --git a/dev/Dockerfile b/dev/Dockerfile new file mode 100644 index 00000000..492544ac --- /dev/null +++ b/dev/Dockerfile @@ -0,0 +1,12 @@ +# https://docs.docker.com/reference/dockerfile/ + +# https://hub.docker.com/_/node/ +FROM node:14 + +WORKDIR /app + +EXPOSE 8080 + +COPY startupservice.sh /usr/local/sbin/startupservice.sh +RUN chmod +x /usr/local/sbin/startupservice.sh +CMD /usr/local/sbin/startupservice.sh diff --git a/dev/startupservice.sh b/dev/startupservice.sh new file mode 100644 index 00000000..da10f4be --- /dev/null +++ b/dev/startupservice.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -o errexit +set -o nounset + +cd /app + +if [[ ! -d node_modules ]] +then + echo 'Clean installing packages from package-lock.json' + npm ci + echo +fi + +npm run serve diff --git a/docker-compose.yml b/docker-compose.yml index e0fa39fc..d72d0819 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,15 +5,12 @@ version: '2.4' services: web: - # Build configuration in Dockerfile - build: . + # Build configuration in dev/Dockerfile + build: dev ports: - '8080:8080' restart: on-failure stdin_open: true tty: true volumes: - # Mount the current directory from the host to /app in the container - '.:/app' - # Mount the /app/node_modules directory from the host - - '/app/node_modules' diff --git a/publish.sh b/publish.sh index 9cec2d32..0abb47e5 100755 --- a/publish.sh +++ b/publish.sh @@ -1,5 +1,4 @@ #!/bin/bash - set -o errexit set -o errtrace set -o nounset @@ -12,10 +11,13 @@ trap '_es=${?}; echo "Deleting contents of dist folder" rm -rf dist/* +echo echo "Starting build" -npm run build-component +docker compose exec web npm run build-component echo "Finished build" +echo echo "Starting publish" -npm publish --access public \ No newline at end of file +docker compose exec web npm publish --access public +echo