From bc1f6edc5a409bc68c2901bed2aa8fbfa91e4ebf Mon Sep 17 00:00:00 2001 From: NOXCIS Date: Mon, 30 Oct 2023 04:02:28 -0500 Subject: [PATCH] + --- .dockerignore | 2 +- Dockerfile | 32 ++++++++------------------------ build.sh | 2 +- client/vite.config.ts | 2 +- docker-compose.yaml | 24 +++++++++++++++++++----- server/src/index.js | 2 +- docker-entrypoint.sh => start.sh | 17 ++++++++++++----- 7 files changed, 43 insertions(+), 38 deletions(-) rename docker-entrypoint.sh => start.sh (81%) mode change 100755 => 100644 diff --git a/.dockerignore b/.dockerignore index 24d401f..fb1ea22 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,8 +1,8 @@ * !package.json !yarn.lock -!docker-entrypoint.sh !build.sh +!start.sh !server/* !client/* **/node_modules/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 1d08804..603acc5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,19 @@ -FROM node:18-bullseye-slim +#FROM nginx:alpine3.18 +FROM node:20.9.0-alpine3.18 + +RUN apk update && apk add --no-cache bash USER node:node WORKDIR /home/node -# Server environmental variables will be put into server/.env -ENV MAILGUN_API_KEY=api-key \ - MAILGUN_DOMAIN=darkwire.io \ - ABUSE_TO_EMAIL_ADDRESS=abuse@darkwire.io \ - ABUSE_FROM_EMAIL_ADDRESS="Darkwire " \ - CLIENT_DIST_DIRECTORY='client/dist/'\ - ROOM_HASH_SECRET='some-uuid'\ - SITE_URL=https://darkwire.io \ - STORE_BACKEND=memory - -# Client configuration will be put into client/.env -ENV TZ=UTC \ - VITE_API_HOST=localhost \ - VITE_API_PROTOCOL=http \ - VITE_API_PORT=3001 \ - VITE_COMMIT_SHA=some_sha \ - VITE_MAX_FILE_SIZE=4 - COPY --chown=node:node . . RUN yarn && yarn build STOPSIGNAL SIGINT -EXPOSE 3001 -HEALTHCHECK --interval=30s --timeout=30s --start-period=10s --retries=3 \ - CMD [ "curl", "-f", "${VITE_API_PROTOCOL}://localhost:${VITE_API_PORT}", "||", "exit", "1" ] -ENTRYPOINT [ "docker-entrypoint.sh" ] -CMD ["yarn", "start"] \ No newline at end of file +RUN chmod +x /home/node/start.sh + +# Start the startup script +CMD ["/home/node/start.sh"] \ No newline at end of file diff --git a/build.sh b/build.sh index 55ae7a3..c2a6559 100755 --- a/build.sh +++ b/build.sh @@ -15,5 +15,5 @@ cd ../ echo "building server..." cd server -yarn --production=false +yarn --production=true yarn build \ No newline at end of file diff --git a/client/vite.config.ts b/client/vite.config.ts index 460b8c2..707d1f8 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -20,5 +20,5 @@ export default defineConfig({ }, build:{ chunkSizeWarningLimit: 1000 - } + }, }); diff --git a/docker-compose.yaml b/docker-compose.yaml index 90f2f58..d698961 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,9 +3,23 @@ services: darkwire.io: build: context: . - networks: - - db + environment: + - TZ=UTC + - VITE_API_PORT=80 + - VITE_API_HOST=localhost + - VITE_API_PROTOCOL=http + - VITE_COMMIT_SHA=some_sha + - VITE_MAX_FILE_SIZE=4 + - MAILGUN_API_KEY=api-key + - MAILGUN_DOMAIN=darkwire.io + - ABUSE_TO_EMAIL_ADDRESS=abuse@darkwire.io + - ABUSE_FROM_EMAIL_ADDRESS=Darkwire + - CLIENT_DIST_DIRECTORY='client/dist' + - ROOM_HASH_SECRET='some-uuid' + - SITE_URL=https://darkwire.io + - STORE_BACKEND=memory + #- STORE_HOST=$STORE_HOST + ports: - - 3001:3001 -networks: - db: + - 80:80 + diff --git a/server/src/index.js b/server/src/index.js index 2a7f55c..28d74d6 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -20,7 +20,7 @@ dotenv.config(); const env = process.env.NODE_ENV || 'development'; const app = new Koa(); -const PORT = process.env.PORT || 3001; +const PORT = process.env.VITE_API_PORT; const router = new Router(); const koaBody = new KoaBody(); diff --git a/docker-entrypoint.sh b/start.sh old mode 100755 new mode 100644 similarity index 81% rename from docker-entrypoint.sh rename to start.sh index d73d431..e44923c --- a/docker-entrypoint.sh +++ b/start.sh @@ -1,7 +1,7 @@ -#!/bin/bash +#!/bin/sh # We use this file to translate environmental variables to .env files used by the application - +set_env() { set -e @@ -17,7 +17,7 @@ VITE_COMMIT_SHA=$VITE_COMMIT_SHA # Set max transferable file size in MB VITE_MAX_FILE_SIZE=$VITE_MAX_FILE_SIZE -" > client/.env +" > client/.env.dist echo" @@ -35,6 +35,13 @@ SITE_URL=$SITE_URL # Store configuration STORE_BACKEND=$STORE_BACKEND STORE_HOST=$STORE_HOST -" > server/.env +" > server/.env.dist -exec "$@" \ No newline at end of file +exec "$@" +} +set_env && +# Start your application +yarn start #& + +# Start Nginx +#nginx -g "daemon off;"