Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NOXCIS committed Sep 19, 2024
1 parent d9fa642 commit ec08d15
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 44 deletions.
37 changes: 23 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
79 changes: 58 additions & 21 deletions client/src/components/RoomLink/index.jsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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 (
<form>
<div className="form-group">
<div>
<form>
<div className="form-group">
<div className="input-group">
<input id="room-url" className="form-control" type="text" readOnly value={roomUrl} />
<div className="input-group-append">
<button
id="copy-room"
data-testid="copy-room-button"
className="copy-room btn btn-secondary"
type="button"
onClick={handleCopyClick}
>
<Clipboard />
</button>
</div>
{showTooltip && (
<Tooltip
anchorId="copy-room"
content={tooltipMessage}
place="top"
events={[]}
isOpen={true}
/>
)}
</div>
</div>
</form>

<div className="form-group mt-3">
<label htmlFor="current-room-id">Change Room ID</label>
<div className="input-group">
<input id="room-url" className="form-control" type="text" readOnly value={roomUrl} />
<input
id="current-room-id"
className="form-control"
type="text"
value={currentRoomId}
onChange={handleRoomIdChange}
/>
<div className="input-group-append">
<button
id="copy-room"
data-testid="copy-room-button"
className="copy-room btn btn-secondary"
id="refresh-room-id"
data-testid="refresh-room-id-button"
className="btn btn-primary" // Change button class for visibility
type="button"
onClick={handleClick}
onClick={handleRefreshClick}
>
<Copy />
Go {/* Replace icon with text */}
</button>
</div>
{showTooltip && (
<Tooltip
anchorId="copy-room"
content={translations.copyButtonTooltip}
place="top"
events={[]}
isOpen={true}
/>
)}
</div>
</div>
</form>
</div>
);
};

Expand Down
4 changes: 2 additions & 2 deletions default.conf
Original file line number Diff line number Diff line change
@@ -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;



Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.0'

services:
darkwire:
build: .
Expand All @@ -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
- [email protected]
Expand All @@ -21,7 +21,7 @@ services:
networks:
- db
ports:
- 3001:80
- 3002:80
- 4001:443
- 5001:3001

Expand Down
25 changes: 21 additions & 4 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/sh


# We use this file to translate environmental variables to .env files used by the application
set_env() {
echo "
Expand Down Expand Up @@ -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

0 comments on commit ec08d15

Please sign in to comment.