-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Docker build and improve checks #220
This commit improves multiple aspects of Docker builds: - Enable artifact output validation for Dockerfile. - Correct the path references in Dockerfile for the distribution directory. - Add Dockerfile specific indentation rules to `.editorconfig`. - Use `npm run install-deps` for dependency installation, enhancing build reliability. - Add automation script `verify-web-server-status.js` to verify running web server on given URL. - Introduce automated build verification for Dockerfile: - On macOS, install Docker with colima as the container runtime because default agents do not include Docker and Docker runtime is not installed due to licensing issues (see actions/runner-images#17). - On Windows, there's no Linux container support (actions/runner#904, actions/runner-images#1143), so keep the checks for macOS and Ubuntu only.
- Loading branch information
1 parent
a6b6407
commit 2469413
Showing
6 changed files
with
113 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
# Build | ||
FROM node:lts-alpine as build-stage | ||
FROM node:lts-alpine AS build-stage | ||
WORKDIR /app | ||
COPY package*.json ./ | ||
RUN npm install | ||
COPY . . | ||
RUN npm run build | ||
RUN npm run install-deps | ||
RUN npm run build \ | ||
&& npm run check:verify-build-artifacts -- --web | ||
RUN mkdir /dist \ | ||
&& dist_directory=$(node 'scripts/print-dist-dir.js' --web) \ | ||
&& cp -a "${dist_directory}/." '/dist' | ||
|
||
# Production stage | ||
FROM nginx:stable-alpine as production-stage | ||
COPY --from=build-stage /app/dist /usr/share/nginx/html | ||
FROM nginx:stable-alpine AS production-stage | ||
COPY --from=build-stage /dist /usr/share/nginx/html | ||
EXPOSE 80 | ||
CMD ["nginx", "-g", "daemon off;"] | ||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Description: | ||
* This script checks if a server, provided as a CLI argument, is up | ||
* and returns an HTTP 200 status code. | ||
* It is designed to provide easy verification of server availability | ||
* and will retry a specified number of times. | ||
* | ||
* Usage: | ||
* node ./scripts/verify-web-server-status.js --url [URL] | ||
* | ||
* Options: | ||
* --url URL of the server to check | ||
*/ | ||
|
||
import { get } from 'http'; | ||
|
||
const MAX_RETRIES = 30; | ||
const RETRY_DELAY_IN_SECONDS = 3; | ||
const URL_PARAMETER_NAME = '--url'; | ||
|
||
function checkServer(currentRetryCount = 1) { | ||
const serverUrl = getServerUrl(); | ||
console.log(`Requesting ${serverUrl}...`); | ||
get(serverUrl, (res) => { | ||
if (res.statusCode === 200) { | ||
console.log('🎊 Success: The server is up and returned HTTP 200.'); | ||
process.exit(0); | ||
} else { | ||
console.log(`Server returned HTTP status code ${res.statusCode}.`); | ||
retry(currentRetryCount); | ||
} | ||
}).on('error', (err) => { | ||
console.error('Error making the request:', err); | ||
retry(currentRetryCount); | ||
}); | ||
} | ||
|
||
function retry(currentRetryCount) { | ||
console.log(`Attempt ${currentRetryCount}/${MAX_RETRIES}:`); | ||
console.log(`Retrying in ${RETRY_DELAY_IN_SECONDS} seconds.`); | ||
|
||
const remainingTime = (MAX_RETRIES - currentRetryCount) * RETRY_DELAY_IN_SECONDS; | ||
console.log(`Time remaining before timeout: ${remainingTime}s`); | ||
|
||
if (currentRetryCount < MAX_RETRIES) { | ||
setTimeout(() => checkServer(currentRetryCount + 1), RETRY_DELAY_IN_SECONDS * 1000); | ||
} else { | ||
console.log('Failure: The server at did not return HTTP 200 within the allocated time. Exiting.'); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function getServerUrl() { | ||
const urlIndex = process.argv.indexOf(URL_PARAMETER_NAME); | ||
if (urlIndex === -1 || urlIndex === process.argv.length - 1) { | ||
console.error(`Parameter "${URL_PARAMETER_NAME}" is not provided.`); | ||
process.exit(1); | ||
} | ||
return process.argv[urlIndex + 1]; | ||
} | ||
|
||
checkServer(); |