Skip to content

Commit

Permalink
Added the Tunnel feature, fixed several UI bugs, and updated the CI (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tarampampam authored Nov 7, 2024
1 parent d83a185 commit dff7073
Show file tree
Hide file tree
Showing 25 changed files with 780 additions and 153 deletions.
86 changes: 52 additions & 34 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,83 @@ on:
workflow_dispatch: {}

jobs:
build-web:
name: Build the frontend
runs-on: ubuntu-latest
env: {FORCE_COLOR: 'true', NPM_PREFIX: './web'}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: {node-version-file: ./web/package.json, cache: 'npm', cache-dependency-path: ./web/package-lock.json}
- run: npm --prefix "$NPM_PREFIX" install -dd --no-audit
- run: npm --prefix "$NPM_PREFIX" run generate
- run: npm --prefix "$NPM_PREFIX" run build
- uses: actions/upload-artifact@v4
with: {name: web-dist, path: ./web/dist/, if-no-files-found: error, retention-days: 1}

build-app:
name: Build for ${{ matrix.os }} (${{ matrix.arch }})
name: Build the app
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [linux, darwin, windows]
arch: [amd64, arm64]
env: {FORCE_COLOR: 'true', NPM_PREFIX: './web'}
needs: [build-web]
steps:
- uses: actions/checkout@v4
- {uses: gacts/github-slug@v1, id: slug}
- id: values
run: |
majorMinorPatch="${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}.${{ steps.slug.outputs.version-patch }}"
echo "version=${majorMinorPatch}" >> $GITHUB_OUTPUT
echo "binary-name=webhook-tester-${{ matrix.os }}-${{ matrix.arch }}`[ ${{ matrix.os }} = 'windows' ] && echo '.exe'`" >> $GITHUB_OUTPUT
echo "deb-name=webhook-tester_${majorMinorPatch}-1_${{ matrix.arch }}" >> $GITHUB_OUTPUT
# build the frontend
- uses: actions/setup-node@v4
with: {node-version-file: ./web/package.json, cache: 'npm', cache-dependency-path: ./web/package-lock.json}
- run: |
npm --prefix "$NPM_PREFIX" install --no-audit
npm --prefix "$NPM_PREFIX" run generate
npm --prefix "$NPM_PREFIX" run build
# build the backend
echo "bin-name=webhook-tester-${{ matrix.os }}-${{ matrix.arch }}`[ ${{ matrix.os }} = 'windows' ] && echo '.exe'`" >> $GITHUB_OUTPUT
- {uses: actions/setup-go@v5, with: {go-version-file: go.mod}}
- run: go install "github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected]"
- run: go generate -skip readme ./...
- {uses: actions/download-artifact@v4, with: {name: web-dist, path: ./web/dist}} # put the built frontend
- env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
LDFLAGS: -s -w -X gh.tarampamp.am/webhook-tester/v2/internal/version.version=${{ steps.slug.outputs.version }}
run: go build -trimpath -ldflags "$LDFLAGS" -o ./${{ steps.values.outputs.binary-name }} ./cmd/webhook-tester/
# upload the binary
LDFLAGS: -s -w -X gh.tarampamp.am/webhook-tester/v2/internal/version.version=${{ steps.slug.outputs.version-semantic }}
run: go build -trimpath -ldflags "$LDFLAGS" -o "./${{ steps.values.outputs.bin-name }}" ./cmd/webhook-tester/
- uses: actions/upload-artifact@v4
with:
name: webhook-tester-${{ matrix.os }}-${{ matrix.arch }}
path: ./${{ steps.values.outputs.bin-name }}
if-no-files-found: error
retention-days: 1
- uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ steps.values.outputs.binary-name }}
asset_name: ${{ steps.values.outputs.binary-name }}
file: ./${{ steps.values.outputs.bin-name }}
asset_name: ${{ steps.values.outputs.bin-name }}
tag: ${{ github.ref }}
# build a Debian package
- if: matrix.os == 'linux' && matrix.arch == 'amd64'
env:
PKG_NAME: ${{ steps.values.outputs.deb-name }}

build-deb-package:
name: Build the Debian package
runs-on: ubuntu-latest
strategy: {matrix: {arch: [amd64, arm64]}}
needs: [build-app]
steps:
- {uses: gacts/github-slug@v1, id: slug}
- {uses: actions/download-artifact@v4, with: {name: "webhook-tester-linux-${{ matrix.arch }}"}}
- id: values
run: |
mkdir -p ${{ env.PKG_NAME }}/usr/local/bin ${{ env.PKG_NAME }}/DEBIAN
cp ${{ steps.values.outputs.binary-name }} ${{ env.PKG_NAME }}/usr/local/bin/webhook-tester
echo -e "Package: webhook-tester\nVersion: ${{ steps.values.outputs.version }}" > ${{ env.PKG_NAME }}/DEBIAN/control
echo -e "Architecture: ${{ matrix.arch }}\nMaintainer: ${{ github.actor }}" >> ${{ env.PKG_NAME }}/DEBIAN/control
echo -e "Description: Powerful tool for testing WebHooks and more" >> ${{ env.PKG_NAME }}/DEBIAN/control
dpkg-deb --build --root-owner-group ${{ env.PKG_NAME }}
- if: matrix.os == 'linux' && matrix.arch == 'amd64'
uses: svenstaro/upload-release-action@v2
majorMinorPatch="${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}.${{ steps.slug.outputs.version-patch }}"
echo "version=${majorMinorPatch}" >> $GITHUB_OUTPUT
echo "pkg-name=webhook-tester_${majorMinorPatch}-1_${{ matrix.arch }}" >> $GITHUB_OUTPUT
- run: |
mkdir -p ./${{ steps.values.outputs.pkg-name }}/usr/local/bin ./${{ steps.values.outputs.pkg-name }}/DEBIAN
mv ./webhook-tester-linux-${{ matrix.arch }} ./${{ steps.values.outputs.pkg-name }}/usr/local/bin/webhook-tester
echo -e "Package: webhook-tester\nVersion: ${{ steps.values.outputs.version }}" > ./${{ steps.values.outputs.pkg-name }}/DEBIAN/control
echo -e "Architecture: ${{ matrix.arch }}\nMaintainer: ${{ github.actor }}" >> ./${{ steps.values.outputs.pkg-name }}/DEBIAN/control
echo -e "Description: Powerful tool for testing WebHooks and more" >> ./${{ steps.values.outputs.pkg-name }}/DEBIAN/control
dpkg-deb --build --root-owner-group ${{ steps.values.outputs.pkg-name }}
- uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ steps.values.outputs.deb-name }}.deb
asset_name: ${{ steps.values.outputs.binary-name }}.deb
file: ./${{ steps.values.outputs.pkg-name }}.deb
asset_name: ${{ steps.values.outputs.pkg-name }}.deb
tag: ${{ github.ref }}

build-docker-image:
Expand All @@ -92,7 +110,7 @@ jobs:
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
build-args: "APP_VERSION=${{ steps.slug.outputs.version }}"
build-args: "APP_VERSION=${{ steps.slug.outputs.version-semantic }}"
tags: | # TODO: add `ghcr.io/${{ github.actor }}/${{ github.event.repository.name }}:latest` and `docker.io/tarampampam/webhook-tester:latest`
ghcr.io/${{ github.actor }}/${{ github.event.repository.name }}:${{ steps.slug.outputs.version }}
ghcr.io/${{ github.actor }}/${{ github.event.repository.name }}:${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}
Expand Down
93 changes: 51 additions & 42 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
- {uses: actions/checkout@v4, with: {fetch-depth: 0}}
- uses: gacts/gitleaks@v1

lint-and-test:
name: Test and lint (backend)
lint-and-test-backend:
name: Test and lint the backend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -35,8 +35,8 @@ jobs:
- uses: golangci/golangci-lint-action@v6
- run: go test -race -covermode=atomic ./...

lint-and-test-web:
name: Test and lint (web)
lint-and-test-frontend:
name: Test and lint the frontend
runs-on: ubuntu-latest
env: {FORCE_COLOR: 'true', NPM_PREFIX: './web'}
steps:
Expand All @@ -47,69 +47,78 @@ jobs:
- run: npm --prefix "$NPM_PREFIX" run generate
- run: npm --prefix "$NPM_PREFIX" run lint
- run: npm --prefix "$NPM_PREFIX" run test

build-web:
name: Build the frontend
runs-on: ubuntu-latest
env: {FORCE_COLOR: 'true', NPM_PREFIX: './web'}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: {node-version-file: ./web/package.json, cache: 'npm', cache-dependency-path: ./web/package-lock.json}
- run: npm --prefix "$NPM_PREFIX" install -dd --no-audit
- run: npm --prefix "$NPM_PREFIX" run generate
- run: npm --prefix "$NPM_PREFIX" run build
- uses: actions/upload-artifact@v4
with: {name: web-dist, path: ./web/dist/, if-no-files-found: error, retention-days: 1}

build-app:
name: Build for ${{ matrix.os }} (${{ matrix.arch }})
name: Build the app
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
matrix: # https://pkg.go.dev/internal/platform
os: [linux, darwin, windows]
arch: [amd64, arm64]
env: {FORCE_COLOR: 'true', NPM_PREFIX: './web'}
needs: [lint-and-test, lint-and-test-web]
needs: [lint-and-test-backend, lint-and-test-frontend, build-web]
steps:
- uses: actions/checkout@v4
- {uses: gacts/github-slug@v1, id: slug}
- id: values
run: |
majorMinorPatch="${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}.${{ steps.slug.outputs.version-patch }}"
echo "version=${majorMinorPatch}" >> $GITHUB_OUTPUT
echo "binary-name=webhook-tester-${{ matrix.os }}-${{ matrix.arch }}`[ ${{ matrix.os }} = 'windows' ] && echo '.exe'`" >> $GITHUB_OUTPUT
echo "deb-name=webhook-tester_${majorMinorPatch}-1_${{ matrix.arch }}" >> $GITHUB_OUTPUT
# build the frontend
- uses: actions/setup-node@v4
with: {node-version-file: ./web/package.json, cache: 'npm', cache-dependency-path: ./web/package-lock.json}
- run: |
npm --prefix "$NPM_PREFIX" install --no-audit
npm --prefix "$NPM_PREFIX" run generate
npm --prefix "$NPM_PREFIX" run build
# build the backend
echo "app-version=${{ steps.slug.outputs.version-semantic }}@${{ steps.slug.outputs.commit-hash-short }}" >> $GITHUB_OUTPUT
echo "bin-name=webhook-tester-${{ matrix.os }}-${{ matrix.arch }}`[ ${{ matrix.os }} = 'windows' ] && echo '.exe'`" >> $GITHUB_OUTPUT
- {uses: actions/setup-go@v5, with: {go-version-file: go.mod}}
- run: go install "github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected]"
- run: go generate -skip readme ./...
- {uses: actions/download-artifact@v4, with: {name: web-dist, path: ./web/dist}} # put the built frontend
- env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
LDFLAGS: -s -w -X gh.tarampamp.am/webhook-tester/v2/internal/version.version=v${{ steps.values.outputs.version }}@${{ steps.slug.outputs.commit-hash-short }}
run: go build -trimpath -ldflags "$LDFLAGS" -o ./${{ steps.values.outputs.binary-name }} ./cmd/webhook-tester/
- if: matrix.os == runner.os && matrix.arch == 'amd64' # try to run the binary
run: ./${{ steps.values.outputs.binary-name }} -h
# upload the binary
LDFLAGS: -s -w -X gh.tarampamp.am/webhook-tester/v2/internal/version.version=${{ steps.values.outputs.app-version }}
run: go build -trimpath -ldflags "$LDFLAGS" -o "./${{ steps.values.outputs.bin-name }}" ./cmd/webhook-tester/
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.values.outputs.binary-name }}
path: ./${{ steps.values.outputs.binary-name }}
name: webhook-tester-${{ matrix.os }}-${{ matrix.arch }}
path: ./${{ steps.values.outputs.bin-name }}
if-no-files-found: error
retention-days: 7
# build a Debian package
- if: matrix.os == 'linux' && matrix.arch == 'amd64'
env:
PKG_NAME: ${{ steps.values.outputs.deb-name }}

build-deb-package:
name: Build the Debian package
runs-on: ubuntu-latest
strategy: {matrix: {arch: [amd64, arm64]}}
needs: [build-app]
steps:
- {uses: gacts/github-slug@v1, id: slug}
- {uses: actions/download-artifact@v4, with: {name: "webhook-tester-linux-${{ matrix.arch }}"}}
- id: values
run: |
mkdir -p ${{ env.PKG_NAME }}/usr/local/bin ${{ env.PKG_NAME }}/DEBIAN
cp ${{ steps.values.outputs.binary-name }} ${{ env.PKG_NAME }}/usr/local/bin/webhook-tester
echo -e "Package: webhook-tester\nVersion: ${{ steps.values.outputs.version }}" > ${{ env.PKG_NAME }}/DEBIAN/control
echo -e "Architecture: ${{ matrix.arch }}\nMaintainer: ${{ github.actor }}" >> ${{ env.PKG_NAME }}/DEBIAN/control
echo -e "Description: Powerful tool for testing WebHooks and more" >> ${{ env.PKG_NAME }}/DEBIAN/control
dpkg-deb --build --root-owner-group ${{ env.PKG_NAME }}
- if: matrix.os == 'linux' && matrix.arch == 'amd64'
uses: actions/upload-artifact@v4
majorMinorPatch="${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}.${{ steps.slug.outputs.version-patch }}"
echo "version=${majorMinorPatch}" >> $GITHUB_OUTPUT
echo "pkg-name=webhook-tester_${majorMinorPatch}-1_${{ matrix.arch }}" >> $GITHUB_OUTPUT
- run: |
mkdir -p ./${{ steps.values.outputs.pkg-name }}/usr/local/bin ./${{ steps.values.outputs.pkg-name }}/DEBIAN
mv ./webhook-tester-linux-${{ matrix.arch }} ./${{ steps.values.outputs.pkg-name }}/usr/local/bin/webhook-tester
echo -e "Package: webhook-tester\nVersion: ${{ steps.values.outputs.version }}" > ./${{ steps.values.outputs.pkg-name }}/DEBIAN/control
echo -e "Architecture: ${{ matrix.arch }}\nMaintainer: ${{ github.actor }}" >> ./${{ steps.values.outputs.pkg-name }}/DEBIAN/control
echo -e "Description: Powerful tool for testing WebHooks and more" >> ./${{ steps.values.outputs.pkg-name }}/DEBIAN/control
dpkg-deb --build --root-owner-group ${{ steps.values.outputs.pkg-name }}
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.values.outputs.binary-name }}.deb
path: ./${{ steps.values.outputs.deb-name }}.deb
name: ${{ steps.values.outputs.pkg-name }}.deb
path: ./${{ steps.values.outputs.pkg-name }}.deb
if-no-files-found: error
retention-days: 7

Expand Down Expand Up @@ -144,7 +153,7 @@ jobs:
build-docker-image:
name: Build the docker image
runs-on: ubuntu-latest
needs: [lint-and-test, lint-and-test-web]
needs: [lint-and-test-backend, lint-and-test-frontend]
steps:
- uses: actions/checkout@v4
- uses: docker/build-push-action@v6
Expand Down
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ the UI—no need for third-party solutions like `pusher.com`!

- Standalone operation with in-memory storage/pubsub - no third-party dependencies needed
- Fully customizable response code, headers, and body for webhooks
- Option to expose your locally running instance to the global internet (via tunneling)
- Fast, built-in UI based on `ReactJS`
- Multi-architecture Docker image based on `scratch`
- Runs as an unprivileged user in Docker
Expand Down Expand Up @@ -54,6 +55,15 @@ with the `--pubsub-driver` flag).

When running multiple instances of the app, the Redis driver is required.

### 🚀 Tunneling

Capture webhook requests from the global internet using the `ngrok` tunnel driver. Enable it by setting the
`--tunnel-driver=ngrok` flag and providing your `ngrok` authentication token with `--ngrok-auth-token`. Once enabled,
the app automatically creates the tunnel for you – no need to install or run `ngrok` manually (even using docker).

With this public URL, you can test your webhooks from external services like GitHub, GitLab, Bitbucket, and more.
You'll never miss a request!

## 🧩 Installation

Download the latest binary for your architecture from the [releases page][link_releases]. For example, to install
Expand All @@ -62,11 +72,16 @@ on an **amd64** system (e.g., Debian, Ubuntu):
[link_releases]:https://github.com/tarampampam/webhook-tester/releases

```shell
$ curl -SsL -o ./webhook-tester https://github.com/tarampampam/webhook-tester/releases/latest/download/webhook-tester-linux-amd64
$ chmod +x ./webhook-tester
$ ./webhook-tester start
curl -SsL -o ./webhook-tester https://github.com/tarampampam/webhook-tester/releases/latest/download/webhook-tester-linux-amd64
chmod +x ./webhook-tester
./webhook-tester start
```

> [!TIP]
> Each release includes binaries for **linux**, **darwin** (macOS) and **windows** (`amd64` and `arm64` architectures).
> You can download the binary for your system from the [releases page][link_releases] (section `Assets`). And - yes,
> all what you need is just download and run single binary file.
Alternatively, you can use the Docker image:

| Registry | Image |
Expand All @@ -80,8 +95,20 @@ Alternatively, you can use the Docker image:
## ⚙ Usage

The easiest way to run the app is by using the Docker image:

```shell
docker run --rm -t -p "8080:8080/tcp" ghcr.io/tarampampam/webhook-tester:2
```

> [!NOTE]
> TODO: Add usage examples
> This command starts the app with the default configuration on port `8080` (the first port in the `-p` argument is
> the host port, and the second is the application port inside the container).
Next, open your browser at [`localhost:8080`](http://localhost:8080) to begin testing your webhooks. To stop the app, press `Ctrl+C` in
the terminal where it's running.

For custom configuration options, refer to the CLI help below or execute the app with the `--help` flag.

[link_ghcr]:https://github.com/users/tarampampam/packages/container/package/webhook-tester
[link_docker_hub]:https://hub.docker.com/r/tarampampam/webhook-tester/
Expand Down Expand Up @@ -130,6 +157,8 @@ The following flags are supported:
| `--max-request-body-size="…"` | maximal webhook request body size (in bytes), zero means unlimited | `0` | `MAX_REQUEST_BODY_SIZE` |
| `--auto-create-sessions` | automatically create sessions for incoming requests | `false` | `AUTO_CREATE_SESSIONS` |
| `--pubsub-driver="…"` | pub/sub driver (memory/redis) | `memory` | `PUBSUB_DRIVER` |
| `--tunnel-driver="…"` | tunnel driver to expose your locally running app to the internet (ngrok, empty to disable) | | `TUNNEL_DRIVER` |
| `--ngrok-auth-token="…"` | ngrok authentication token (required for ngrok tunnel; create a new one at https://dashboard.ngrok.com/authtokens/new) | | `NGROK_AUTHTOKEN` |
| `--redis-dsn="…"` | redis-like (redis, keydb) server DSN (e.g. redis://user:pwd@127.0.0.1:6379/0 or unix://user:pwd@/path/to/redis.sock?db=0) | `redis://127.0.0.1:6379/0` | `REDIS_DSN` |
| `--shutdown-timeout="…"` | maximum duration for graceful shutdown | `15s` | `SHUTDOWN_TIMEOUT` |
| `--use-live-frontend` | use frontend from the local directory instead of the embedded one (useful for development) | `false` | *none* |
Expand Down
Loading

0 comments on commit dff7073

Please sign in to comment.