From ec08d15eaf4301031457da160d183a2282437c50 Mon Sep 17 00:00:00 2001 From: Noxcis Date: Wed, 18 Sep 2024 19:09:51 -0500 Subject: [PATCH] updates --- Dockerfile | 37 ++++++----- client/src/components/RoomLink/index.jsx | 79 +++++++++++++++++------- default.conf | 4 +- docker-compose.yaml | 6 +- start.sh | 25 ++++++-- 5 files changed, 107 insertions(+), 44 deletions(-) diff --git a/Dockerfile b/Dockerfile index e6c97584..c8728fef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,42 @@ # Stage 1: Build Stage -FROM node:alpine3.19 AS builder +FROM node:current-alpine AS builder -WORKDIR /home/node -COPY --chown=node:node . . +WORKDIR /opt/app +COPY . . RUN apk update \ && apk add --no-cache bash \ - && chmod +x /home/node/start.sh \ + && chmod +x /opt/app/start.sh \ && npm install -g yarn@latest --force \ && yarn install --flat --production --no-cache \ && yarn build --no-cache \ - && rm -rf /home/node/node_modules \ + && rm -rf /opt/app/node_modules \ + && rm -rf /opt/app/server/node_modules \ && yarn cache clean \ && yarn autoclean --force # Stage 2: Production Stage -FROM node:alpine3.19 +FROM alpine:latest -WORKDIR /home/node -COPY --from=builder /home/node . +WORKDIR /opt/app + +COPY --from=builder /opt/app/client/dist /opt/app/client/dist +COPY --from=builder /opt/app/server /opt/app/server +COPY package.json /opt/app/package.json +COPY default.conf /etc/nginx/http.d/ +COPY start.sh /opt/app/start.sh + + + + +RUN apk add --no-cache nginx yarn openssl && \ + chmod +x /opt/app/start.sh -RUN apk add --no-cache curl nginx openssl && \ - rm /etc/nginx/http.d/default.conf && \ - mv /home/node/default.conf /etc/nginx/http.d/ && \ - chmod +x /home/node/start.sh -STOPSIGNAL SIGINT HEALTHCHECK --interval=30s --timeout=30s --start-period=10s --retries=3 \ CMD [ "curl", "-f", "http://localhost:3001", "||", "exit", "1" ] -CMD ["/home/node/start.sh"] +CMD ["/opt/app/start.sh"] + +STOPSIGNAL SIGTERM \ No newline at end of file diff --git a/client/src/components/RoomLink/index.jsx b/client/src/components/RoomLink/index.jsx index 8e2de8b3..815541ef 100644 --- a/client/src/components/RoomLink/index.jsx +++ b/client/src/components/RoomLink/index.jsx @@ -1,13 +1,15 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Copy } from 'react-feather'; +import { Clipboard } from 'react-feather'; // Import Clipboard icon for the copy button import { Tooltip } from 'react-tooltip'; const RoomLink = ({ roomId, translations }) => { + const [currentRoomId, setCurrentRoomId] = React.useState(roomId); const [showTooltip, setShowTooltip] = React.useState(false); + const [tooltipMessage, setTooltipMessage] = React.useState(''); const mountedRef = React.useRef(true); - const roomUrl = `${window.location.origin}/${roomId}`; + const roomUrl = `${window.location.origin}/${currentRoomId}`; React.useEffect(() => { mountedRef.current = true; @@ -16,8 +18,9 @@ const RoomLink = ({ roomId, translations }) => { }; }, []); - const handleClick = async () => { + const handleCopyClick = async () => { await navigator.clipboard.writeText(roomUrl); + setTooltipMessage(translations.copyButtonTooltip); setShowTooltip(true); setTimeout(() => { if (mountedRef.current) { @@ -26,34 +29,68 @@ const RoomLink = ({ roomId, translations }) => { }, 2000); }; + const handleRefreshClick = () => { + window.location.href = roomUrl; // Reload the page with the current room URL + }; + + const handleRoomIdChange = (e) => { + setCurrentRoomId(e.target.value); + }; + return ( -
-
+
+ +
+
+ +
+ +
+ {showTooltip && ( + + )} +
+
+ + +
+
- +
- {showTooltip && ( - - )}
- +
); }; diff --git a/default.conf b/default.conf index 22479bb1..c843f7bb 100644 --- a/default.conf +++ b/default.conf @@ -1,8 +1,8 @@ server { listen 443 ssl; server_name localhost; - ssl_certificate /home/node/certs/selfsigned.crt; - ssl_certificate_key /home/node/certs/selfsigned.key; + ssl_certificate /opt/app/certs/selfsigned.crt; + ssl_certificate_key /opt/app/certs/selfsigned.key; diff --git a/docker-compose.yaml b/docker-compose.yaml index bb55fd17..db381607 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,4 @@ -version: '3.0' + services: darkwire: build: . @@ -9,7 +9,7 @@ services: - VITE_API_HOST=localhost - VITE_API_PROTOCOL=http - VITE_COMMIT_SHA=some_sha - - VITE_MAX_FILE_SIZE=4 + - VITE_MAX_FILE_SIZE=20 - MAILGUN_API_KEY=api-key - MAILGUN_DOMAIN=darkwire.io - ABUSE_TO_EMAIL_ADDRESS=abuse@darkwire.io @@ -21,7 +21,7 @@ services: networks: - db ports: - - 3001:80 + - 3002:80 - 4001:443 - 5001:3001 diff --git a/start.sh b/start.sh index 20b3bb76..2fc15dab 100644 --- a/start.sh +++ b/start.sh @@ -1,6 +1,5 @@ #!/bin/sh - # We use this file to translate environmental variables to .env files used by the application set_env() { echo " @@ -52,8 +51,26 @@ generate_self_signed_ssl() { echo "Certificate signing request: $csr_file" } +# Graceful shutdown function +shutdown_nginx() { + echo "Shutting down Nginx..." + nginx -s quit + exit 0 +} + +# Trap SIGTERM signal and call shutdown_nginx +trap 'shutdown_nginx' SIGTERM + set_env && # Start your application -generate_self_signed_ssl && -nginx && -yarn start #& +generate_self_signed_ssl generate_self_signed_ssl >> /dev/null 2>&1 + + +# Start the server +cd server +yarn install +cd .. +yarn start && +nginx & +# Wait indefinitely to handle SIGTERM +wait