From 05205b4ecb6a6f5cbb747222dc2257f76b4efe35 Mon Sep 17 00:00:00 2001 From: Dave Lane Date: Thu, 29 Aug 2024 11:40:28 +1200 Subject: [PATCH] updated Dockerfile anddocker-compose.yml, along with README.md --- Dockerfile | 29 ++++++++++++++++++++--------- README.md | 24 +++++++++++++++++++++++- docker-compose.yml | 24 ++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 75013e9..8dd8374 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,26 @@ -# Dockerfile +# Use this image as the platform to build the app +FROM node:20.11-alpine AS external-website -FROM node:16-alpine - -RUN npm install -g pnpm +# A small line inside the image to show who made it +LABEL Developers="Dave Lane, dave@laneventures.nz" +# The WORKDIR instruction sets the working directory for everything that will happen next WORKDIR /app -COPY package.json pnpm-lock.yaml ./ -RUN pnpm install --frozen-lockfile +# Copy all local files into the image COPY . . -RUN pnpm build -EXPOSE 3000 -CMD ["node", "build"] +# Clean install all node modules +RUN npm ci + +# Build SvelteKit app +RUN npm run build + +# Delete source code files that were used to build the app that are no longer needed +RUN rm -rf src/ static/ emailTemplates/ docker-compose.yml + +# The USER instruction sets the user name to use as the default user for the remainder of the current stage +USER node:node + +# This is the command that will be run inside the image when you tell Docker to start the container +CMD ["node","build/index.js"] diff --git a/README.md b/README.md index 9da71d0..bbfb2b1 100644 --- a/README.md +++ b/README.md @@ -40,4 +40,26 @@ npm run build You can preview the production build with `npm run preview`. -> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. +## Deployment + +### To set up your SvelteKit project, ensure that your svelte.config.js file has this line: + + // import adapter from '@sveltejs/adapter-auto'; + import adapter from '@sveltejs/adapter-node'; + +and then run + + npm i -D @sveltejs/adapter-node + npm i dotenv + +### To build a new image + + docker-compose build + +### To start it up (and tail the logs - CTRL-C to quit out of the logs without affecting running container) + + docker-compose up -d && docker-compose logs -f + +### To clear out an old image (if it's running) + + docker-compose down --remove-orphans --rmi 'all' diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..757ac22 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +# docker-compose.yml + +services: + external: + container_name: external + # The name of the image that will be created when building this container + # Change this based on your app's name... + image: external-website:latest + build: + context: . + dockerfile: Dockerfile + user: "node" + environment: + # Internal server error messages will not send stacktrace to the browser in production + - NODE_ENV=production + # Sets the timezone of the containers OS + - TZ=Pacific/Auckland + # Points to a file with the sensitive environment variables + env_file: + - .env + restart: unless-stopped + ports: + # change the port on 127.0.0.1 to ensure it's not already in use on the host. + - 127.0.0.1:5050:5050