From 39dbb4c4fcd69c993fd54ceade18b439ede9b473 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 20 Feb 2022 22:46:41 +0000 Subject: [PATCH] :wrench: Change internal port to 8080, for non-sudo access --- Dockerfile | 136 ++++++++++++++++++++--------------------- docker-compose.yml | 94 ++++++++++++++-------------- server.js | 4 +- services/ssl-server.js | 2 +- 4 files changed, 118 insertions(+), 118 deletions(-) diff --git a/Dockerfile b/Dockerfile index e785e887..c002a383 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,68 +1,68 @@ -FROM node:16.13.2-alpine AS BUILD_IMAGE - -# Set the platform to build image for -ARG TARGETPLATFORM -ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} - -# Install additional tools needed if on arm64 / armv7 -RUN \ - case "${TARGETPLATFORM}" in \ - 'linux/arm64') apk add --no-cache python3 make g++ ;; \ - 'linux/arm/v7') apk add --no-cache python3 make g++ ;; \ - esac - -# Create and set the working directory -WORKDIR /app - -# Install app dependencies -COPY package.json yarn.lock ./ -RUN yarn install --frozen-lockfile --network-timeout 1000000 - -# Copy over all project files and folders to the working directory -COPY . ./ - -# Build initial app for production -RUN yarn build - -# Production stage -FROM node:16.13.2-alpine - -# Define some ENV Vars -ENV PORT=80 \ - DIRECTORY=/app \ - IS_DOCKER=true \ - USER=docker \ - UID=12345 \ - GID=23456 - -# Install tini for initialization and tzdata for setting timezone -RUN apk add --no-cache tzdata tini \ - # Add group - && addgroup --gid ${GID} "${USER}" \ - # Add user - && adduser \ - --disabled-password \ - --ingroup "${USER}" \ - --gecos "" \ - --home "${DIRECTORY}" \ - --no-create-home \ - --uid "$UID" \ - "$USER" - -USER ${USER} - -# Create and set the working directory -WORKDIR ${DIRECTORY} - -# Copy built application from build phase -COPY --from=BUILD_IMAGE --chown=${USER}:${USER} /app ./ - -# Finally, run start command to serve up the built application -ENTRYPOINT [ "/sbin/tini", "--" ] -CMD [ "yarn", "build-and-start" ] - -# Expose the port -EXPOSE ${PORT} - -# Run simple healthchecks every 5 mins, to check that everythings still great -HEALTHCHECK --interval=5m --timeout=2s --start-period=30s CMD yarn health-check +FROM node:16.13.2-alpine AS BUILD_IMAGE + +# Set the platform to build image for +ARG TARGETPLATFORM +ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} + +# Install additional tools needed if on arm64 / armv7 +RUN \ + case "${TARGETPLATFORM}" in \ + 'linux/arm64') apk add --no-cache python3 make g++ ;; \ + 'linux/arm/v7') apk add --no-cache python3 make g++ ;; \ + esac + +# Create and set the working directory +WORKDIR /app + +# Install app dependencies +COPY package.json yarn.lock ./ +RUN yarn install --frozen-lockfile --network-timeout 1000000 + +# Copy over all project files and folders to the working directory +COPY . ./ + +# Build initial app for production +RUN yarn build + +# Production stage +FROM node:16.13.2-alpine + +# Define some ENV Vars +ENV PORT=8080 \ + DIRECTORY=/app \ + IS_DOCKER=true \ + USER=docker \ + UID=12345 \ + GID=23456 + +# Install tini for initialization and tzdata for setting timezone +RUN apk add --no-cache tzdata tini \ + # Add group + && addgroup --gid ${GID} "${USER}" \ + # Add user + && adduser \ + --disabled-password \ + --ingroup "${USER}" \ + --gecos "" \ + --home "${DIRECTORY}" \ + --no-create-home \ + --uid "$UID" \ + "$USER" + +USER ${USER} + +# Create and set the working directory +WORKDIR ${DIRECTORY} + +# Copy built application from build phase +COPY --from=BUILD_IMAGE --chown=${USER}:${USER} /app ./ + +# Finally, run start command to serve up the built application +ENTRYPOINT [ "/sbin/tini", "--" ] +CMD [ "yarn", "build-and-start" ] + +# Expose the port +EXPOSE ${PORT} + +# Run simple healthchecks every 5 mins, to check that everythings still great +HEALTHCHECK --interval=5m --timeout=2s --start-period=30s CMD yarn health-check diff --git a/docker-compose.yml b/docker-compose.yml index 0d09a26a..d87e07ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,47 +1,47 @@ ---- -# Welcome to Dashy! To get started, run `docker compose up -d` -# You can configure your container here, by modifying this file -version: "3.8" -services: - dashy: - container_name: Dashy - - # Pull latest image from DockerHub - image: lissy93/dashy - - # To build from source, replace 'image: lissy93/dashy' with 'build: .' - # build: . - - # Or, to use a Dockerfile for your archtecture, uncomment the following - # context: . - # dockerfile: ./docker/Dockerfile-arm32v7 - - # You can also use an image with a different tag, or pull from a different registry, e.g: - # image: ghcr.io/lissy93/dashy or image: lissy93/dashy:arm64v8 - - # Pass in your config file below, by specifying the path on your host machine - # volumes: - # - /path/to/my-config.yml:/app/public/conf.yml - # - /path/to/item-icons:/app/public/item-icons - - # Set port that web service will be served on. Keep container port as 80 - ports: - - 4000:80 - - # Set any environmental variables - environment: - - NODE_ENV=production - # Specify your user ID and group ID. You can find this by running `id -u` and `id -g` - # - UID=1000 - # - GID=1000 - - # Specify restart policy - restart: unless-stopped - - # Configure healthchecks - healthcheck: - test: ['CMD', 'node', '/app/services/healthcheck'] - interval: 1m30s - timeout: 10s - retries: 3 - start_period: 40s +--- +# Welcome to Dashy! To get started, run `docker compose up -d` +# You can configure your container here, by modifying this file +version: "3.8" +services: + dashy: + container_name: Dashy + + # Pull latest image from DockerHub + image: lissy93/dashy + + # To build from source, replace 'image: lissy93/dashy' with 'build: .' + # build: . + + # Or, to use a Dockerfile for your archtecture, uncomment the following + # context: . + # dockerfile: ./docker/Dockerfile-arm32v7 + + # You can also use an image with a different tag, or pull from a different registry, e.g: + # image: ghcr.io/lissy93/dashy or image: lissy93/dashy:arm64v8 + + # Pass in your config file below, by specifying the path on your host machine + # volumes: + # - /path/to/my-config.yml:/app/public/conf.yml + # - /path/to/item-icons:/app/public/item-icons + + # Set port that web service will be served on. Keep container port as 8080 + ports: + - 4000:8080 + + # Set any environmental variables + environment: + - NODE_ENV=production + # Specify your user ID and group ID. You can find this by running `id -u` and `id -g` + # - UID=1000 + # - GID=1000 + + # Specify restart policy + restart: unless-stopped + + # Configure healthchecks + healthcheck: + test: ['CMD', 'node', '/app/services/healthcheck'] + interval: 1m30s + timeout: 10s + retries: 3 + start_period: 40s diff --git a/server.js b/server.js index 4cef9e23..1009b150 100644 --- a/server.js +++ b/server.js @@ -35,8 +35,8 @@ const ENDPOINTS = require('./src/utils/defaults').serviceEndpoints; // API endpo /* Checks if app is running within a container, from env var */ const isDocker = !!process.env.IS_DOCKER; -/* Checks env var for port. If undefined, will use Port 80 for Docker, or 4000 for metal */ -const port = process.env.PORT || (isDocker ? 80 : 4000); +/* Checks env var for port. If undefined, will use Port 8080 for Docker, or 4000 for metal */ +const port = process.env.PORT || (isDocker ? 8080 : 4000); /* Attempts to get the users local IP, used as part of welcome message */ const getLocalIp = () => { diff --git a/services/ssl-server.js b/services/ssl-server.js index a3dada05..18638321 100644 --- a/services/ssl-server.js +++ b/services/ssl-server.js @@ -12,7 +12,7 @@ module.exports = (app) => { }; const isDocker = !!process.env.IS_DOCKER; - const SSLPort = process.env.SSL_PORT || (isDocker ? 443 : 4001); + const SSLPort = process.env.SSL_PORT || (isDocker ? 8081 : 4001); const printSuccess = () => { console.log(`🔐 HTTPS server successfully started (port: ${SSLPort} ${isDocker ? 'of container' : ''})`);