Skip to content

Commit 83bb4f0

Browse files
committed
RU-T47 Working on Web and App support
1 parent 3c7709e commit 83bb4f0

29 files changed

Lines changed: 3484 additions & 79 deletions

Dockerfile

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,59 @@
11
### STAGE 1: Build ###
2-
FROM node:18.16.0-alpine AS build
3-
WORKDIR /usr/src/app
4-
COPY package.json package-lock.json ./
5-
RUN npm ci
2+
FROM node:20-alpine AS build
3+
4+
# Install build dependencies
5+
RUN apk add --no-cache python3 make g++
6+
7+
WORKDIR /app
8+
9+
# Copy package files
10+
COPY package.json yarn.lock ./
11+
12+
# Install dependencies
13+
RUN yarn install --frozen-lockfile
14+
15+
# Copy source files
616
COPY . .
7-
RUN npm run build -- --configuration=production
17+
18+
# Build the web application
19+
RUN yarn web:build
820

921
### STAGE 2: Run ###
10-
FROM nginx:1.21.6-alpine
22+
FROM nginx:1.25-alpine
23+
24+
# Install sed for the entrypoint script
25+
RUN apk add --no-cache sed
26+
27+
# Copy nginx configuration
1128
COPY nginx.conf /etc/nginx/nginx.conf
12-
COPY --from=build /usr/src/app/www /usr/share/nginx/html
29+
30+
# Copy built web app from build stage
31+
COPY --from=build /app/dist /usr/share/nginx/html
32+
33+
# Copy entrypoint script
34+
COPY docker/docker-entrypoint.sh /docker-entrypoint.sh
35+
RUN chmod +x /docker-entrypoint.sh
1336

1437
# Expose port 80
1538
EXPOSE 80
1639

17-
# When the container starts, replace the env.js with values from environment variables
18-
CMD ["/bin/sh", "-c", "envsubst < /usr/share/nginx/html/assets/env.prod.js > /usr/share/nginx/html/assets/env.js && exec nginx -g 'daemon off;'"]
40+
# Set default environment variables
41+
ENV APP_ENV=production \
42+
UNIT_NAME="Resgrid Unit" \
43+
UNIT_SCHEME="ResgridUnit" \
44+
UNIT_VERSION="0.0.1" \
45+
UNIT_BASE_API_URL="https://api.resgrid.com" \
46+
UNIT_API_VERSION="v4" \
47+
UNIT_RESGRID_API_URL="/api/v4" \
48+
UNIT_CHANNEL_HUB_NAME="eventingHub" \
49+
UNIT_REALTIME_GEO_HUB_NAME="geolocationHub" \
50+
UNIT_LOGGING_KEY="" \
51+
UNIT_APP_KEY="" \
52+
UNIT_MAPBOX_PUBKEY="" \
53+
UNIT_SENTRY_DSN="" \
54+
UNIT_COUNTLY_APP_KEY="" \
55+
UNIT_COUNTLY_SERVER_URL=""
56+
57+
# Use entrypoint to inject environment variables at runtime
58+
ENTRYPOINT ["/docker-entrypoint.sh"]
59+
CMD ["nginx", "-g", "daemon off;"]

docker-compose.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Docker Compose for local development and testing
2+
# Run: docker-compose up --build
3+
4+
services:
5+
web:
6+
build:
7+
context: .
8+
dockerfile: Dockerfile
9+
ports:
10+
- "8080:80"
11+
environment:
12+
- APP_ENV=production
13+
- UNIT_NAME=Resgrid Unit
14+
- UNIT_SCHEME=ResgridUnit
15+
- UNIT_VERSION=0.0.1
16+
- UNIT_BASE_API_URL=https://api.resgrid.com
17+
- UNIT_API_VERSION=v4
18+
- UNIT_RESGRID_API_URL=/api/v4
19+
- UNIT_CHANNEL_HUB_NAME=eventingHub
20+
- UNIT_REALTIME_GEO_HUB_NAME=geolocationHub
21+
- UNIT_LOGGING_KEY=
22+
- UNIT_APP_KEY=
23+
- UNIT_MAPBOX_PUBKEY=
24+
- UNIT_SENTRY_DSN=
25+
- UNIT_COUNTLY_APP_KEY=
26+
- UNIT_COUNTLY_SERVER_URL=
27+
restart: unless-stopped
28+
healthcheck:
29+
test: ["CMD", "wget", "-q", "--spider", "http://localhost/health"]
30+
interval: 30s
31+
timeout: 10s
32+
retries: 3
33+
start_period: 10s

docker/docker-entrypoint.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Directory where the built web app is served
5+
HTML_DIR="/usr/share/nginx/html"
6+
7+
# Create the env-config.js file with environment variables
8+
cat > "${HTML_DIR}/env-config.js" << EOF
9+
// Runtime environment configuration - generated by docker-entrypoint.sh
10+
// This file is generated at container startup and injects environment variables
11+
window.__ENV__ = {
12+
APP_ENV: "${APP_ENV:-production}",
13+
NAME: "${UNIT_NAME:-Resgrid Unit}",
14+
SCHEME: "${UNIT_SCHEME:-ResgridUnit}",
15+
VERSION: "${UNIT_VERSION:-0.0.1}",
16+
BASE_API_URL: "${UNIT_BASE_API_URL:-https://api.resgrid.com}",
17+
API_VERSION: "${UNIT_API_VERSION:-v4}",
18+
RESGRID_API_URL: "${UNIT_RESGRID_API_URL:-/api/v4}",
19+
CHANNEL_HUB_NAME: "${UNIT_CHANNEL_HUB_NAME:-eventingHub}",
20+
REALTIME_GEO_HUB_NAME: "${UNIT_REALTIME_GEO_HUB_NAME:-geolocationHub}",
21+
LOGGING_KEY: "${UNIT_LOGGING_KEY:-}",
22+
APP_KEY: "${UNIT_APP_KEY:-}",
23+
UNIT_MAPBOX_PUBKEY: "${UNIT_MAPBOX_PUBKEY:-}",
24+
IS_MOBILE_APP: false,
25+
SENTRY_DSN: "${UNIT_SENTRY_DSN:-}",
26+
COUNTLY_APP_KEY: "${UNIT_COUNTLY_APP_KEY:-}",
27+
COUNTLY_SERVER_URL: "${UNIT_COUNTLY_SERVER_URL:-}"
28+
};
29+
EOF
30+
31+
echo "Generated env-config.js with runtime environment variables"
32+
33+
# Check if index.html exists
34+
if [ ! -f "${HTML_DIR}/index.html" ]; then
35+
echo "Error: index.html not found in ${HTML_DIR}"
36+
exit 1
37+
fi
38+
39+
# Inject the env-config.js script into index.html if not already present
40+
if ! grep -q "env-config.js" "${HTML_DIR}/index.html"; then
41+
# Insert script tag right after the opening <head> tag
42+
sed -i 's|<head>|<head>\n <script src="/env-config.js"></script>|' "${HTML_DIR}/index.html"
43+
echo "Injected env-config.js script tag into index.html"
44+
else
45+
echo "env-config.js already present in index.html"
46+
fi
47+
48+
echo "Starting nginx..."
49+
50+
# Execute the CMD (nginx)
51+
exec "$@"

electron-builder.config.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* Electron Builder Configuration
3+
* https://www.electron.build/configuration/configuration
4+
*/
5+
module.exports = {
6+
appId: 'com.resgrid.unit',
7+
productName: 'Resgrid Unit',
8+
copyright: 'Copyright © 2024 Resgrid',
9+
10+
directories: {
11+
output: 'electron-dist',
12+
buildResources: 'assets',
13+
},
14+
15+
files: [
16+
'dist/**/*',
17+
'electron/**/*',
18+
'!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme}',
19+
'!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}',
20+
'!**/node_modules/.bin',
21+
],
22+
23+
// macOS configuration
24+
mac: {
25+
category: 'public.app-category.productivity',
26+
target: [
27+
{ target: 'dmg', arch: ['x64', 'arm64'] },
28+
{ target: 'zip', arch: ['x64', 'arm64'] },
29+
],
30+
icon: 'assets/icon.icns',
31+
hardenedRuntime: true,
32+
gatekeeperAssess: false,
33+
entitlements: 'electron/entitlements.mac.plist',
34+
entitlementsInherit: 'electron/entitlements.mac.plist',
35+
darkModeSupport: true,
36+
},
37+
38+
dmg: {
39+
contents: [
40+
{ x: 130, y: 220 },
41+
{ x: 410, y: 220, type: 'link', path: '/Applications' },
42+
],
43+
window: {
44+
width: 540,
45+
height: 380,
46+
},
47+
},
48+
49+
// Windows configuration
50+
win: {
51+
target: [
52+
{ target: 'nsis', arch: ['x64'] },
53+
{ target: 'portable', arch: ['x64'] },
54+
],
55+
icon: 'assets/icon.ico',
56+
publisherName: 'Resgrid',
57+
},
58+
59+
nsis: {
60+
oneClick: false,
61+
allowToChangeInstallationDirectory: true,
62+
installerIcon: 'assets/icon.ico',
63+
uninstallerIcon: 'assets/icon.ico',
64+
installerHeaderIcon: 'assets/icon.ico',
65+
createDesktopShortcut: true,
66+
createStartMenuShortcut: true,
67+
shortcutName: 'Resgrid Unit',
68+
license: 'LICENSE',
69+
},
70+
71+
// Linux configuration
72+
linux: {
73+
target: [
74+
{ target: 'AppImage', arch: ['x64'] },
75+
{ target: 'deb', arch: ['x64'] },
76+
{ target: 'rpm', arch: ['x64'] },
77+
],
78+
category: 'Office',
79+
icon: 'assets/icon.png',
80+
maintainer: 'Resgrid <support@resgrid.com>',
81+
vendor: 'Resgrid',
82+
desktop: {
83+
Name: 'Resgrid Unit',
84+
Comment: 'Resgrid Unit Management Application',
85+
Category: 'Office;Utility;',
86+
StartupWMClass: 'resgrid-unit',
87+
},
88+
},
89+
90+
// Extra metadata
91+
extraMetadata: {
92+
main: 'electron/main.js',
93+
},
94+
};

electron/entitlements.mac.plist

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.cs.allow-jit</key>
6+
<true/>
7+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
8+
<true/>
9+
<key>com.apple.security.cs.disable-library-validation</key>
10+
<true/>
11+
<key>com.apple.security.automation.apple-events</key>
12+
<true/>
13+
<!-- Network access for API calls -->
14+
<key>com.apple.security.network.client</key>
15+
<true/>
16+
<!-- Microphone access for voice calls -->
17+
<key>com.apple.security.device.audio-input</key>
18+
<true/>
19+
<!-- Location access -->
20+
<key>com.apple.security.personal-information.location</key>
21+
<true/>
22+
<!-- Camera access (future use) -->
23+
<key>com.apple.security.device.camera</key>
24+
<true/>
25+
</dict>
26+
</plist>

0 commit comments

Comments
 (0)