Skip to content

Commit 364fb8e

Browse files
committed
init
0 parents  commit 364fb8e

21 files changed

Lines changed: 568 additions & 0 deletions

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
**/node_modules
2+
npm-debug.log
3+
**/dist
4+
# Cache used by TypeScript's incremental build
5+
*.tsbuildinfo
6+
**/*.local.*
7+
8+
/.github/
9+
/.vscode/
10+
/helm
11+
*.code-workspace

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
* text eol=lf
2+
*.png binary
3+
*.ttf binary
4+
*.jpg binary
5+
*.eot binary
6+
*.woff binary
7+
*.ttf binary
8+
*.vsdx binary
9+
*.tgz binary
10+
*.gpg binary
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: buildTestPublishContainerDeploy
2+
on:
3+
push:
4+
branches:
5+
- main
6+
release:
7+
types:
8+
- published
9+
pull_request:
10+
workflow_dispatch:
11+
env:
12+
req2stdoutContainerTag: latest
13+
jobs:
14+
publish-container:
15+
if: ${{ github.repository == 'f-w/req2stdout' && github.event_name != 'pull_request' }}
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
steps:
21+
- name: Update req2stdoutContainerTag for tags
22+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
23+
run: echo req2stdoutContainerTag=$(echo $GITHUB_REF | cut -d / -f 3 | cut -d v -f 2- | cut -d . -f 1,2) >> $GITHUB_ENV
24+
- name: Update req2stdoutContainerTag for branches
25+
if: ${{ startsWith(github.ref, 'refs/heads/') && github.ref != 'refs/heads/main' }}
26+
run: echo req2stdoutContainerTag=$(echo $GITHUB_REF | cut -d / -f 3) >> $GITHUB_ENV
27+
- name: Save $req2stdoutContainerTag to file
28+
run: |
29+
echo $req2stdoutContainerTag > req2stdoutContainerTag.txt
30+
- name: Upload req2stdoutContainerTag
31+
if: ${{ startsWith(github.ref, 'refs/heads/') }}
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: req2stdoutContainerTag
35+
path: req2stdoutContainerTag.txt
36+
- name: Checkout 🛎️
37+
uses: actions/checkout@v4
38+
with:
39+
persist-credentials: false
40+
- name: Login to GitHub Container Registry
41+
uses: docker/login-action@v3
42+
with:
43+
registry: ghcr.io
44+
username: ${{ github.repository_owner }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
- name: Publish Container 🚀
47+
uses: docker/build-push-action@v6
48+
with:
49+
push: true
50+
tags: ghcr.io/f-w/req2stdout:${{ env.req2stdoutContainerTag }}
51+
build-args: nodeVersion=${{ vars.NODE_VERSION }}
52+
deploy:
53+
if: ${{ github.repository == 'f-w/req2stdout' && github.event_name == 'push' }}
54+
needs: publish-container
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: Checkout 🛎️
58+
uses: actions/checkout@v4
59+
with:
60+
persist-credentials: false
61+
- name: Install oc
62+
uses: redhat-actions/oc-installer@v1
63+
- name: Authenticate to OCP4 and set context
64+
uses: redhat-actions/oc-login@v1
65+
with:
66+
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
67+
openshift_token: ${{ secrets.OPENSHIFT_API_TOKEN }}
68+
namespace: ${{ secrets.OPENSHIFT_PROJECT }}-prod
69+
- name: Download req2stdoutContainerTag
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: req2stdoutContainerTag
73+
- name: helm upgrade 🚀
74+
run: |
75+
export req2stdoutContainerTag=`cat req2stdoutContainerTag.txt`
76+
helm upgrade --set image.tag="$req2stdoutContainerTag" req2stdout helm
77+
oc rollout restart deployment.apps/req2stdout

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
pnpm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
14+
# OS
15+
.DS_Store
16+
17+
# Tests
18+
/coverage
19+
/.nyc_output
20+
21+
# IDEs and editors
22+
/.idea
23+
.project
24+
.classpath
25+
.c9/
26+
*.launch
27+
.settings/
28+
*.sublime-workspace
29+
30+
# IDE - VSCode
31+
.vscode/*
32+
!.vscode/settings.json
33+
!.vscode/tasks.json
34+
!.vscode/launch.json
35+
!.vscode/extensions.json
36+
37+
**/*.local.*

.vscode/extensions.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
3+
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
4+
5+
// List of extensions which should be recommended for users of this workspace.
6+
"recommendations": ["yzhang.markdown-all-in-one"],
7+
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
8+
"unwantedRecommendations": []
9+
}

.vscode/settings.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"editor.rulers": [80],
3+
"editor.tabCompletion": "on",
4+
"editor.tabSize": 2,
5+
"editor.trimAutoWhitespace": true,
6+
"editor.formatOnSave": true,
7+
"editor.codeActionsOnSave": {
8+
"source.organizeImports": "explicit",
9+
"source.fixAll.eslint": "explicit"
10+
},
11+
12+
"files.exclude": {
13+
"**/.DS_Store": true,
14+
"**/.git": true,
15+
"**/.hg": true,
16+
"**/.svn": true,
17+
"**/CVS": true
18+
},
19+
"files.insertFinalNewline": true,
20+
"files.trimTrailingWhitespace": true,
21+
22+
"eslint.run": "onSave",
23+
"eslint.nodePath": "./node_modules",
24+
"eslint.validate": ["javascript", "typescript"]
25+
}

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# syntax=docker/dockerfile:1
2+
ARG nodeVersion=lts
3+
# Check out https://hub.docker.com/_/node to select a new base image
4+
FROM node:${nodeVersion}
5+
6+
# Set to a non-root built-in user `node`
7+
USER node
8+
9+
# Create app directory (with user `node`)
10+
RUN mkdir -p /home/node/app
11+
12+
WORKDIR /home/node/app
13+
14+
# Bundle app source code
15+
COPY --chown=node . .
16+
17+
ENV PORT=3000 NODE_ENV=production
18+
19+
EXPOSE ${PORT}
20+
CMD [ "node", "." ]

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# req2stdout
2+
3+
## What
4+
5+
Log incoming http request to stdout.
6+
7+
## Why
8+
9+
There are free public SAAS counterparts such as https://requestcatcher.com/. But if there is egress firewall, such as in some corporate environments, reaching the public SAAS can be a challenge. In such case running request logger on an internal localhost maybe inadequate either if the request comes from a remote host.
10+
11+
`req2stdout` not only can be deployed internally but provides a Helm chart to facilitate deploying to internal OpenShift. Hence could be a rescue.
12+
13+
## How
14+
15+
To deploy, run `helm install req2stdout helm` from cwd after logging into OpenShift with `oc login`. The Helm creates an OpenShift route to expose HTTP endpoint referenced as `<req2stdout-host>` below.
16+
17+
To use, send a request, for example `curl -d 'Hello World!' https://<req2stdout-host>`, and observe the container log in OpenShift web console. Requests containing URL path are also logged except for `/probe`, which is reserved for k8s liveness and readiness probe.
18+
19+
Sample stdout when running above cmd
20+
21+
```
22+
=== Incoming Request ===
23+
Time: 2025-08-21T22:38:21.698Z
24+
Method: POST
25+
URL: /
26+
27+
Headers:
28+
{
29+
"user-agent": "curl/8.8.0",
30+
"accept": "*/*",
31+
"content-length": "12",
32+
"content-type": "application/x-www-form-urlencoded",
33+
"host": "<req2stdout-host>",
34+
"x-forwarded-host": "<req2stdout-host>",
35+
"x-forwarded-port": "443",
36+
"x-forwarded-proto": "https",
37+
"forwarded": "for=<real-ip>;host=<req2stdout-host>;proto=https",
38+
"x-forwarded-for": "<real-ip>"
39+
}
40+
41+
Body:
42+
Hello World!
43+
body length: 12
44+
```
45+
46+
Response is `200 OK` with body `Request received and logged`.

helm/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!*.tgz

helm/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

0 commit comments

Comments
 (0)