-
Notifications
You must be signed in to change notification settings - Fork 0
Add error fallback webserver with custom error pages and deployment configuration #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
db8d82b
feat: add error fallback webserver with custom error pages and deploy…
The0mikkel a6c81e4
Add empty depoyment file for automation
The0mikkel 7f997f7
chore(release): 1.0.0-r.1 [skip ci]
semantic-release-bot 9736bd5
Rename service from instancing-fallback to error-fallback in docker-c…
The0mikkel 63a8409
Merge branch 'develop' of https://github.com/ctfpilot/error-fallback …
The0mikkel 93439b1
Correct minor errors in language and validation
The0mikkel 5d496d6
Change placeholder naming
The0mikkel e929ee3
Add README.md for page generation and templating instructions
The0mikkel a6d4b24
Update README.md to clarify additional placeholder for error codes
The0mikkel 741e4f2
Fix placeholder replacement logic to handle missing placeholders grac…
The0mikkel fd79f29
Increase poll interval and enhance error handling with reload attempt…
The0mikkel 6c2deb8
Add readiness probe to deployment configuration for improved service …
The0mikkel 5ce3801
Fix README.md for consistency in folder naming conventions
The0mikkel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| public/ |
This file contains hidden or 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,47 @@ | ||
| { | ||
| "branches": [ | ||
| "main", | ||
| { | ||
| "name": "develop", | ||
| "prerelease": "r" | ||
| } | ||
| ], | ||
| "plugins": [ | ||
| [ | ||
| "@semantic-release/commit-analyzer", | ||
| { | ||
| "preset": "conventionalcommits" | ||
| } | ||
| ], | ||
| [ | ||
| "@semantic-release/release-notes-generator", | ||
| { | ||
| "preset": "conventionalcommits" | ||
| } | ||
| ], | ||
| [ | ||
| "@semantic-release/github", | ||
| { | ||
| "successComment": false, | ||
| "assets": [ | ||
| ] | ||
| } | ||
| ], | ||
| [ | ||
| "@semantic-release/exec", | ||
| { | ||
| "prepareCmd": "echo ${nextRelease.version} > version.txt && cp template/k8s.yml k8s/k8s.yml && sed -i 's/{ .Version }/${nextRelease.version}/g' k8s/k8s.yml", | ||
| "publishCmd": "echo 'Published version ${nextRelease.version}'" | ||
| } | ||
| ], | ||
| [ | ||
| "@semantic-release/git", | ||
| { | ||
| "assets": [ | ||
| "k8s/k8s.yml" | ||
| ], | ||
| "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" | ||
| } | ||
| ] | ||
| ] | ||
| } |
This file contains hidden or 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,13 @@ | ||
| FROM python:3.14-slim AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY src/ /app/src | ||
|
|
||
| RUN python3 src/generator.py | ||
|
|
||
| FROM joseluisq/static-web-server | ||
|
|
||
| COPY --from=builder /app/public/ /public | ||
|
|
||
| ENV SERVER_CACHE_CONTROL_HEADERS=false |
This file contains hidden or 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 hidden or 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,6 @@ | ||
| services: | ||
| error-fallback: | ||
| build: . | ||
| ports: | ||
| - "8080:80" | ||
| restart: always |
This file contains hidden or 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,63 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: error-fallback | ||
| labels: | ||
| app.kubernetes.io/part-of: ctfpilot | ||
| app.kubernetes.io/name: error-fallback | ||
| app.kubernetes.io/version: 1.0.0-r.1 | ||
| app.kubernetes.io/component: challenges | ||
| ctfpilot.com/component: error-fallback | ||
|
|
||
| spec: | ||
| # HA setup | ||
| replicas: 3 | ||
| selector: | ||
| matchLabels: | ||
| ctfpilot.com/component: error-fallback | ||
|
|
||
| template: | ||
| metadata: | ||
| labels: | ||
| ctfpilot.com/component: error-fallback | ||
| spec: | ||
| enableServiceLinks: false | ||
| automountServiceAccountToken: false | ||
| containers: | ||
| - name: instancing-fallback | ||
The0mikkel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| image: ctfpilot/error-fallback:1.0.0-r.1 | ||
| imagePullPolicy: Always | ||
| ports: | ||
| - name: http | ||
| containerPort: 80 | ||
| resources: | ||
| requests: | ||
| memory: "128Mi" | ||
| cpu: "10m" | ||
| limits: | ||
| memory: "256Mi" | ||
| cpu: "100m" | ||
| livenessProbe: | ||
| httpGet: | ||
| path: / | ||
| port: 80 | ||
| initialDelaySeconds: 5 | ||
| periodSeconds: 10 | ||
The0mikkel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: error-fallback | ||
| labels: | ||
| app.kubernetes.io/part-of: ctfpilot | ||
| app.kubernetes.io/name: error-fallback | ||
| app.kubernetes.io/version: 1.0.0-r.1 | ||
| app.kubernetes.io/component: challenges | ||
| ctfpilot.com/component: error-fallback | ||
| spec: | ||
| selector: | ||
| ctfpilot.com/component: error-fallback | ||
| ports: | ||
| - name: http | ||
| port: 80 | ||
| targetPort: http | ||
This file contains hidden or 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,29 @@ | ||
| # Error page generation | ||
|
|
||
| In order to generate the error pages, run the `generator.py` script in `src`: | ||
|
|
||
| ```sh | ||
| python3 src/generator.py | ||
| ``` | ||
|
|
||
| This will generate the error pages based on the layouts and content defined in the `layouts` and `content` folders respectively. | ||
|
|
||
| ## Templating | ||
|
|
||
| A custom templating system is used to insert content into the layouts. | ||
| Placeholders in the layout files are defined using the format `/**PLACEHOLDER_NAME**/`. | ||
| The generator script replaces these placeholders with the corresponding content. | ||
|
|
||
| The placeholders used are: | ||
|
|
||
| - `/**ERROR_HTML**/`: The main HTML content for the error page. Inserted from `content`. | ||
| - `/**ERROR_JS**/`: Any JavaScript code to be included in the error page. Inserted from `js`. | ||
| - `/**ERROR_CSS**/`: Any CSS styles to be included in the error page . Inserted from `css`. | ||
|
|
||
| For `error` layout pages, an additional placeholder is used: | ||
|
|
||
| - `/**ERROR_CODE**/`: The error code for the error page (e.g., 404, 500). Replaced with the filename part of the content file. | ||
|
|
||
| The templating use multiple layouts, which are defined in the `layouts` folder. | ||
| Each content file in the `content` folder should be prefixed with the layout name, followed by an underscore. | ||
| For example, a content file named `error_404.html` will use the `error` layout, and produce a page named `404.html`. |
This file contains hidden or 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,4 @@ | ||
| <h1>Not found</h1> | ||
| <p> | ||
| The page you are looking for could not be found. | ||
| </p> |
This file contains hidden or 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,7 @@ | ||
| <h1>Error</h1> | ||
| <p> | ||
| An unexpected error has occurred. | ||
| </p> | ||
| <p> | ||
| Go back to the <a href="/">home page</a>.<br /> | ||
| </p> |
This file contains hidden or 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,4 @@ | ||
| <h1>Bad gateway</h1> | ||
| <p> | ||
| The service did not answer correctly. | ||
| </p> |
This file contains hidden or 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,5 @@ | ||
| <h1>No service available</h1> | ||
| <p> | ||
| The service is currently unavailable. Please try again later. <br /> | ||
| The service may be restarting or undergoing maintenance. | ||
| </p> |
This file contains hidden or 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,5 @@ | ||
| <h1>Gateway timeout</h1> | ||
| <p> | ||
| The service was unable to respond in a timely manner. <br /> | ||
| The service may be restarting or undergoing maintenance. | ||
| </p> |
This file contains hidden or 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,4 @@ | ||
| <h1>Error</h1> | ||
| <p> | ||
| An unexpected error has occurred. | ||
| </p> |
This file contains hidden or 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,64 @@ | ||
| :root { | ||
| --header-font: "Hack", monospace, sans-serif; | ||
| --body-font: "Hack", monospace, sans-serif; | ||
|
|
||
| --light-theme-color: #eebc1d; | ||
| --dark-theme-color: #eebc1d; | ||
| --text-light: #232323; | ||
| --text-dark: #f9f9f9; | ||
| --bg-light: #f9f9f9; | ||
| --bg-dark: #232323; | ||
|
|
||
| --theme-color: var(--light-theme-color); | ||
| --bg-color: var(--bg-light); | ||
| --text-color: var(--text-light); | ||
| } | ||
|
|
||
| @media (prefers-color-scheme: dark) { | ||
| :root { | ||
| --theme-color: var(--dark-theme-color); | ||
| --bg-color: var(--bg-dark); | ||
| --text-color: var(--text-dark); | ||
| } | ||
| } | ||
|
|
||
| html, | ||
| body { | ||
| background-color: var(--bg-color); | ||
| color: var(--text-color) !important; | ||
| font-family: var(--body-font) !important; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| main { | ||
| padding: 2rem; | ||
| } | ||
|
|
||
| h1, | ||
| h2, | ||
| h3, | ||
| h4, | ||
| h5 { | ||
| font-family: var(--header-font) !important; | ||
| } | ||
|
|
||
| a { | ||
| color: var(--theme-color); | ||
| filter: brightness(100%); | ||
| transition: filter 0.2s; | ||
| } | ||
|
|
||
| a:hover { | ||
| filter: brightness(95%); | ||
| transition: filter 0.2s; | ||
| } | ||
|
|
||
| .container { | ||
| display: flex; | ||
| justify-content: center; | ||
| text-align: center; | ||
| height: 100vh; | ||
| overflow-y: hidden; | ||
| align-items: center; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.