File tree 5 files changed +45
-5
lines changed
5 files changed +45
-5
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ COPY --from=builder /app/public ./public
46
46
# https://nextjs.org/docs/advanced-features/output-file-tracing
47
47
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
48
48
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
49
+ COPY --from=builder --chown=nextjs:nodejs /app/scripts ./scripts
49
50
50
51
USER nextjs
51
52
@@ -59,4 +60,5 @@ VOLUME /app/data
59
60
ARG RPC_CONFIG
60
61
ENV RPC_CONFIG="$RPC_CONFIG"
61
62
63
+ ENTRYPOINT ["node" , "scripts/initialize-environment.js" ]
62
64
CMD ["node" , "server.js" ]
Original file line number Diff line number Diff line change @@ -55,16 +55,19 @@ export abstract class LevelSensor {
55
55
56
56
async getLevel ( ) : Promise < number > {
57
57
const endpoint = `${ this . sensorEndpoint } /${ this . options . endpointPath } ` ;
58
+ const { retryCount, retryWait } = this . options ;
58
59
try {
59
60
const response : LevelSensorResponse = await this . piServer . requestJson ( {
60
61
endpoint,
61
- retryCount : this . options . retryCount ,
62
- retryWait : this . options . retryWait
62
+ retryCount,
63
+ retryWait
63
64
} ) ;
64
65
65
66
return response . distance ;
66
67
} catch ( error ) {
67
- this . log . error ( `Failed to get level at endpoint: '${ endpoint } '` ) ;
68
+ this . log . error (
69
+ `Failed to get level at endpoint: '${ endpoint } ' (retryCount: ${ retryCount } retryWait: ${ retryWait } )`
70
+ ) ;
68
71
throw error ;
69
72
}
70
73
}
Original file line number Diff line number Diff line change 1
1
const fs = require ( "fs" ) ;
2
2
const { env } = require ( "process" ) ;
3
+ const { version } = require ( "./package.json" ) ;
3
4
const { PHASE_PRODUCTION_SERVER } = require ( "next/constants" ) ;
4
5
const CONFIG_ENV_VAR_NAME = "RPC_CONFIG" ;
5
6
@@ -20,7 +21,9 @@ module.exports = (phase) => {
20
21
? `Config env variable '${ CONFIG_ENV_VAR_NAME } ' exists.`
21
22
: `No value found for config env variable '${ CONFIG_ENV_VAR_NAME } '. Skipping writing config file.` ;
22
23
23
- console . log ( `Initializing app in '${ mode } ' mode. ${ configInfo } ` ) ;
24
+ console . log (
25
+ `Initializing app version '${ version } ' in '${ mode } ' mode. ${ configInfo } `
26
+ ) ;
24
27
if ( saveConfigFile ) {
25
28
saveConfig ( config ) ;
26
29
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " raspberry-pi-client" ,
3
- "version" : " 1.0.0-rc.3 " ,
3
+ "version" : " 1.0.0-rc.4 " ,
4
4
"private" : true ,
5
5
"scripts" : {
6
6
"dev" : " next dev" ,
Original file line number Diff line number Diff line change
1
+ const fs = require ( "fs" ) ;
2
+ const { env } = require ( "process" ) ;
3
+ const { version } = require ( "./package.json" ) ;
4
+ const configEnvName = "RPC_CONFIG" ;
5
+ const configJson = env [ configEnvName ] ;
6
+ const nodeEnv = env [ "NODE_ENV" ] ;
7
+ const configFilePath = "./data/config.json" ;
8
+
9
+ function initializeConfig ( ) {
10
+ const hasConfig = Boolean ( configJson ) ;
11
+ const message = hasConfig
12
+ ? `Config env variable '${ CONFIG_ENV_VAR_NAME } ' exists. File will be written to disk.`
13
+ : `No value found for config env variable '${ CONFIG_ENV_VAR_NAME } '. Skipping writing config file.` ;
14
+
15
+ console . log ( message ) ;
16
+ if ( hasConfig ) {
17
+ saveConfig ( config ) ;
18
+ }
19
+ }
20
+
21
+ function saveConfig ( ) {
22
+ const configJson = env [ CONFIG_ENV_VAR_NAME ] ;
23
+ fs . writeFileSync ( configFilePath , configJson ) ;
24
+ console . log ( `Config file written to '${ configFilePath } '` ) ;
25
+ }
26
+
27
+ function initialize ( ) {
28
+ console . log ( `Initializing app version '${ version } ' in '${ nodeEnv } ' mode.` ) ;
29
+ initializeConfig ( ) ;
30
+ }
31
+
32
+ initialize ( ) ;
You can’t perform that action at this time.
0 commit comments