Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Russell Green committed Jun 20, 2023
1 parent c5d74e6 commit dfb68f5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ COPY --from=builder /app/public ./public
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/scripts ./scripts

USER nextjs

Expand All @@ -59,4 +60,5 @@ VOLUME /app/data
ARG RPC_CONFIG
ENV RPC_CONFIG="$RPC_CONFIG"

ENTRYPOINT ["node", "scripts/initialize-environment.js"]
CMD ["node", "server.js"]
9 changes: 6 additions & 3 deletions lib/level/LevelSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,19 @@ export abstract class LevelSensor {

async getLevel(): Promise<number> {
const endpoint = `${this.sensorEndpoint}/${this.options.endpointPath}`;
const { retryCount, retryWait } = this.options;
try {
const response: LevelSensorResponse = await this.piServer.requestJson({
endpoint,
retryCount: this.options.retryCount,
retryWait: this.options.retryWait
retryCount,
retryWait
});

return response.distance;
} catch (error) {
this.log.error(`Failed to get level at endpoint: '${endpoint}'`);
this.log.error(
`Failed to get level at endpoint: '${endpoint}' (retryCount: ${retryCount} retryWait: ${retryWait})`
);
throw error;
}
}
Expand Down
5 changes: 4 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require("fs");
const { env } = require("process");
const { version } = require("./package.json");
const { PHASE_PRODUCTION_SERVER } = require("next/constants");
const CONFIG_ENV_VAR_NAME = "RPC_CONFIG";

Expand All @@ -20,7 +21,9 @@ module.exports = (phase) => {
? `Config env variable '${CONFIG_ENV_VAR_NAME}' exists.`
: `No value found for config env variable '${CONFIG_ENV_VAR_NAME}'. Skipping writing config file.`;

console.log(`Initializing app in '${mode}' mode. ${configInfo}`);
console.log(
`Initializing app version '${version}' in '${mode}' mode. ${configInfo}`
);
if (saveConfigFile) {
saveConfig(config);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raspberry-pi-client",
"version": "1.0.0-rc.3",
"version": "1.0.0-rc.4",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
32 changes: 32 additions & 0 deletions scripts/initialize-environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fs = require("fs");
const { env } = require("process");
const { version } = require("./package.json");
const configEnvName = "RPC_CONFIG";
const configJson = env[configEnvName];
const nodeEnv = env["NODE_ENV"];
const configFilePath = "./data/config.json";

function initializeConfig() {
const hasConfig = Boolean(configJson);
const message = hasConfig
? `Config env variable '${CONFIG_ENV_VAR_NAME}' exists. File will be written to disk.`
: `No value found for config env variable '${CONFIG_ENV_VAR_NAME}'. Skipping writing config file.`;

console.log(message);
if (hasConfig) {
saveConfig(config);
}
}

function saveConfig() {
const configJson = env[CONFIG_ENV_VAR_NAME];
fs.writeFileSync(configFilePath, configJson);
console.log(`Config file written to '${configFilePath}'`);
}

function initialize() {
console.log(`Initializing app version '${version}' in '${nodeEnv}' mode.`);
initializeConfig();
}

initialize();

0 comments on commit dfb68f5

Please sign in to comment.