Skip to content

Commit

Permalink
Refactor Dockerfile and server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Codycody31 committed Feb 1, 2024
1 parent 2e632c6 commit 5123509
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 30 deletions.
9 changes: 7 additions & 2 deletions docker/Dockerfile.server
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/* && \
apt-get autoremove -y

# Build the core
WORKDIR /app/core
COPY core/package*.json ./
RUN npm install
COPY core/ ./

# Build the server
WORKDIR /app/server
COPY server/package*.json ./
RUN npm ci --omit=dev
COPY core /app/core
COPY server/ ./
RUN npm install /app/core

# Build the web
# Build the web, including the fix for @rollup/rollup-linux-arm64-gnu
WORKDIR /app/web
COPY web/package*.json ./
COPY web/ ./
Expand Down
7 changes: 6 additions & 1 deletion docker/Dockerfile.server.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/* && \
apt-get autoremove -y

# Build the core
WORKDIR /app/core
COPY core/package*.json ./
RUN npm install
COPY core/ ./

# Build the server
WORKDIR /app/server
COPY server/package*.json ./
RUN npm ci --omit=dev
COPY core /app/core
COPY server/ ./
RUN npm install /app/core

Expand Down
5 changes: 1 addition & 4 deletions docker/nodejs-run
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/bin/sh
# Navigate to the Node.js server directory
cd /usr/local/server

# Start the Node.js application
exec node server.js
exec node /usr/local/server/server.js
53 changes: 30 additions & 23 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,39 @@ const server = http.createServer(app);
}

// Check connection to Elasticsearch
log.info("server", "Checking Elasticsearch connection...");
const client = new Client({
node: config.elasticsearch.url,
auth: {
apiKey: config.elasticsearch.apiKey,
},
tls: {
// ca: config.elasticsearch.ca,
ca: Buffer.from(config.elasticsearch.ca, "base64").toString("ascii"),
rejectUnauthorized: false,
},
});
if (config.elasticsearch.url && config.elasticsearch.apiKey) {
log.info("server", "Checking Elasticsearch connection...");
const client = new Client({
node: config.elasticsearch.url,
auth: {
apiKey: config.elasticsearch.apiKey,
},
tls: {
// ca: config.elasticsearch.ca,
ca: Buffer.from(config.elasticsearch.ca, "base64").toString("ascii"),
rejectUnauthorized: false,
},
});

try {
// API Key should have cluster monitor rights.
const resp = await client.info();
log.info(
try {
// API Key should have cluster monitor rights.
const resp = await client.info();
log.info(
"server",
"Elasticsearch connection successful, version: " + resp.version.number
);
} catch (err) {
if (config.exceptionless.apiKey && config.exceptionless.serverUrl) {
await Exceptionless.submitException(err);
}
log.error("server", "Error connecting to Elasticsearch: " + err);
process.exit(1);
}
} else {
log.warn(
"server",
"Elasticsearch connection successful, version: " + resp.version.number
"Elasticsearch URL or API key not set. Elasticsearch will be disabled."
);
} catch (err) {
if (config.exceptionless.apiKey && config.exceptionless.serverUrl) {
await Exceptionless.submitException(err);
}
log.error("server", "Error connecting to Elasticsearch: " + err);
process.exit(1);
}

// Check if we have RSA keys stored in the database, if not, generate them
Expand Down

0 comments on commit 5123509

Please sign in to comment.