From 3675ac4bb206069833f18a73d5c0c30dad9871c7 Mon Sep 17 00:00:00 2001 From: Bill Chirico Date: Mon, 6 Nov 2023 12:16:08 -0500 Subject: [PATCH] feat(Dockerfile): Add build step and run.sh script This commit adds a build step to the Dockerfile, which runs the `npm run build` command. It also introduces a new `run.sh` script that installs dependencies using `npm install` and starts the server with `npm run serve`. --- Dockerfile | 8 ++++---- run.sh | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 run.sh diff --git a/Dockerfile b/Dockerfile index d4c8e4c..e83376a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,11 @@ FROM node:lts-alpine AS deps WORKDIR /opt/app # Copy package.json and package-lock.json to the working directory COPY package.json package-lock.json ./ -COPY . . +COPY . / # Install production dependencies only RUN npm ci --only=production +# Build the application +RUN npm run build # Stage 2: Build the application FROM node:lts-alpine AS builder @@ -16,8 +18,6 @@ WORKDIR /opt/app # Copy node_modules from the "deps" stage COPY package.json package-lock.json ./ COPY --from=deps /opt/app/node_modules ./node_modules -# Build the application -RUN npm run build # Stage 3: Create the production image FROM node:lts-alpine AS runner @@ -30,4 +30,4 @@ EXPOSE 5000 COPY --from=builder /opt/app/build ./build COPY package.json package-lock.json ./ # Define the command to run the application -CMD ["sh", "-l", "-c", "npm run serve"] \ No newline at end of file +CMD run.sh \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..b76a2dc --- /dev/null +++ b/run.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Navigate to the directory containing your project's package.json file +# cd /path/to/your/project + +# Run npm install to install all dependencies +npm install + +# Run npm run serve to start the server +npm run serve