navapbc / template-application-nextjs

Next.js, TypeScript, USWDS, and Storybook template, including CI/CD, for teams at Nava building web applications
Apache License 2.0
10 stars 2 forks source link

Fix AWS health check #325

Closed sawyerh closed 2 months ago

sawyerh commented 2 months ago

Ticket

Resolves #305

Changes

Context for reviewers

This was copied from the Next.js Docker example. I tried a few other formats, but none of those worked.

Testing

Tested on the Platform test app

CleanShot 2024-04-26 at 10 03 31@2x

github-actions[bot] commented 2 months ago

Coverage report for app

St.:grey_question:
Category Percentage Covered / Total
🟒 Statements 93.1% 81/87
🟒 Branches 82.35% 14/17
🟒 Functions 93.33% 14/15
🟒 Lines 93.59% 73/78

Test suite run success

16 tests passing in 5 suites.

Report generated by πŸ§ͺjest coverage report action from a3cb94693f7468623c051eba7d708571e1de668d

lorenyu commented 2 months ago

@sawyerh I think CMD ["HOSTNAME=0.0.0.0", "node", "server.js"] doesn't work because the exec form of CMD (["executable", "arg1", "arg2"]) invokes the executable directly without first invoking a shell, whereas the shell form (executable arg1 arg2) invokes a shell which then invokes the executable. The HOSTNAME=0.0.0.0 isn't an executable so it can't be run, it's something that shells understand.

I'm surprised why the ENV HOSTNAME 0.0.0.0 doesn't work.

As an aside, it's considered best practice to use the ENV NAME=VAR form (with equal sign) than the ENV NAME VAR form without equal sign. See the following snippet from Docker docs:

This syntax does not allow for multiple environment-variables to be set in a single ENV instruction, and can be confusing. For example, the following sets a single environment variable (ONE) with value "TWO= THREE=world": [ENV](https://docs.docker.com/reference/dockerfile/#env) ONE TWO= THREE=world The alternative syntax is supported for backward compatibility, but discouraged for the reasons outlined above, and may be removed in a future release.