This commit is contained in:
Noxcis 2024-09-18 19:09:51 -05:00
parent d9fa642647
commit ec08d15eaf
5 changed files with 107 additions and 44 deletions

View File

@ -1,33 +1,42 @@
# Stage 1: Build Stage # Stage 1: Build Stage
FROM node:alpine3.19 AS builder FROM node:current-alpine AS builder
WORKDIR /home/node WORKDIR /opt/app
COPY --chown=node:node . . COPY . .
RUN apk update \ RUN apk update \
&& apk add --no-cache bash \ && apk add --no-cache bash \
&& chmod +x /home/node/start.sh \ && chmod +x /opt/app/start.sh \
&& npm install -g yarn@latest --force \ && npm install -g yarn@latest --force \
&& yarn install --flat --production --no-cache \ && yarn install --flat --production --no-cache \
&& yarn build --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 cache clean \
&& yarn autoclean --force && yarn autoclean --force
# Stage 2: Production Stage # Stage 2: Production Stage
FROM node:alpine3.19 FROM alpine:latest
WORKDIR /home/node WORKDIR /opt/app
COPY --from=builder /home/node .
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 \ HEALTHCHECK --interval=30s --timeout=30s --start-period=10s --retries=3 \
CMD [ "curl", "-f", "http://localhost:3001", "||", "exit", "1" ] CMD [ "curl", "-f", "http://localhost:3001", "||", "exit", "1" ]
CMD ["/home/node/start.sh"] CMD ["/opt/app/start.sh"]
STOPSIGNAL SIGTERM

View File

@ -1,13 +1,15 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; 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'; import { Tooltip } from 'react-tooltip';
const RoomLink = ({ roomId, translations }) => { const RoomLink = ({ roomId, translations }) => {
const [currentRoomId, setCurrentRoomId] = React.useState(roomId);
const [showTooltip, setShowTooltip] = React.useState(false); const [showTooltip, setShowTooltip] = React.useState(false);
const [tooltipMessage, setTooltipMessage] = React.useState('');
const mountedRef = React.useRef(true); const mountedRef = React.useRef(true);
const roomUrl = `${window.location.origin}/${roomId}`; const roomUrl = `${window.location.origin}/${currentRoomId}`;
React.useEffect(() => { React.useEffect(() => {
mountedRef.current = true; mountedRef.current = true;
@ -16,8 +18,9 @@ const RoomLink = ({ roomId, translations }) => {
}; };
}, []); }, []);
const handleClick = async () => { const handleCopyClick = async () => {
await navigator.clipboard.writeText(roomUrl); await navigator.clipboard.writeText(roomUrl);
setTooltipMessage(translations.copyButtonTooltip);
setShowTooltip(true); setShowTooltip(true);
setTimeout(() => { setTimeout(() => {
if (mountedRef.current) { if (mountedRef.current) {
@ -26,7 +29,16 @@ const RoomLink = ({ roomId, translations }) => {
}, 2000); }, 2000);
}; };
const handleRefreshClick = () => {
window.location.href = roomUrl; // Reload the page with the current room URL
};
const handleRoomIdChange = (e) => {
setCurrentRoomId(e.target.value);
};
return ( return (
<div>
<form> <form>
<div className="form-group"> <div className="form-group">
<div className="input-group"> <div className="input-group">
@ -37,15 +49,15 @@ const RoomLink = ({ roomId, translations }) => {
data-testid="copy-room-button" data-testid="copy-room-button"
className="copy-room btn btn-secondary" className="copy-room btn btn-secondary"
type="button" type="button"
onClick={handleClick} onClick={handleCopyClick}
> >
<Copy /> <Clipboard />
</button> </button>
</div> </div>
{showTooltip && ( {showTooltip && (
<Tooltip <Tooltip
anchorId="copy-room" anchorId="copy-room"
content={translations.copyButtonTooltip} content={tooltipMessage}
place="top" place="top"
events={[]} events={[]}
isOpen={true} isOpen={true}
@ -54,6 +66,31 @@ const RoomLink = ({ roomId, translations }) => {
</div> </div>
</div> </div>
</form> </form>
<div className="form-group mt-3">
<label htmlFor="current-room-id">Change Room ID</label>
<div className="input-group">
<input
id="current-room-id"
className="form-control"
type="text"
value={currentRoomId}
onChange={handleRoomIdChange}
/>
<div className="input-group-append">
<button
id="refresh-room-id"
data-testid="refresh-room-id-button"
className="btn btn-primary" // Change button class for visibility
type="button"
onClick={handleRefreshClick}
>
Go {/* Replace icon with text */}
</button>
</div>
</div>
</div>
</div>
); );
}; };

View File

@ -1,8 +1,8 @@
server { server {
listen 443 ssl; listen 443 ssl;
server_name localhost; server_name localhost;
ssl_certificate /home/node/certs/selfsigned.crt; ssl_certificate /opt/app/certs/selfsigned.crt;
ssl_certificate_key /home/node/certs/selfsigned.key; ssl_certificate_key /opt/app/certs/selfsigned.key;

View File

@ -1,4 +1,4 @@
version: '3.0'
services: services:
darkwire: darkwire:
build: . build: .
@ -9,7 +9,7 @@ services:
- VITE_API_HOST=localhost - VITE_API_HOST=localhost
- VITE_API_PROTOCOL=http - VITE_API_PROTOCOL=http
- VITE_COMMIT_SHA=some_sha - VITE_COMMIT_SHA=some_sha
- VITE_MAX_FILE_SIZE=4 - VITE_MAX_FILE_SIZE=20
- MAILGUN_API_KEY=api-key - MAILGUN_API_KEY=api-key
- MAILGUN_DOMAIN=darkwire.io - MAILGUN_DOMAIN=darkwire.io
- ABUSE_TO_EMAIL_ADDRESS=abuse@darkwire.io - ABUSE_TO_EMAIL_ADDRESS=abuse@darkwire.io
@ -21,7 +21,7 @@ services:
networks: networks:
- db - db
ports: ports:
- 3001:80 - 3002:80
- 4001:443 - 4001:443
- 5001:3001 - 5001:3001

View File

@ -1,6 +1,5 @@
#!/bin/sh #!/bin/sh
# We use this file to translate environmental variables to .env files used by the application # We use this file to translate environmental variables to .env files used by the application
set_env() { set_env() {
echo " echo "
@ -52,8 +51,26 @@ generate_self_signed_ssl() {
echo "Certificate signing request: $csr_file" 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 && set_env &&
# Start your application # Start your application
generate_self_signed_ssl && generate_self_signed_ssl generate_self_signed_ssl >> /dev/null 2>&1
nginx &&
yarn start #&
# Start the server
cd server
yarn install
cd ..
yarn start &&
nginx &
# Wait indefinitely to handle SIGTERM
wait