72 Commits

Author SHA1 Message Date
Łukasz Budnik
48cb758883 Merge pull request #62 from lukaszbudnik/upgrade-docker-dependencies-add-integration-test
upgraded docker containers for golang and alpine
2023-01-08 20:39:59 +01:00
Łukasz Budnik
196306d131 correct bash if-then-else syntax 2023-01-08 20:36:31 +01:00
Łukasz Budnik
c5415206e6 upgraded docker containers for golang and alpine, added simple integration test 2023-01-08 20:33:08 +01:00
Łukasz Budnik
66b4078631 Merge pull request #61 from lukaszbudnik/dependabot/github_actions/actions/checkout-3.3.0
Bump actions/checkout from 3.1.0 to 3.3.0
2023-01-08 17:43:12 +01:00
dependabot[bot]
d14e46e839 Bump actions/checkout from 3.1.0 to 3.3.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.1.0 to 3.3.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3.1.0...v3.3.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-05 17:01:35 +00:00
Łukasz Budnik
21ffd8ef65 Merge pull request #57 from lukaszbudnik/dependabot/go_modules/github.com/stretchr/testify-1.8.1
Bump github.com/stretchr/testify from 1.8.0 to 1.8.1
2022-10-28 17:47:17 +02:00
dependabot[bot]
75cd57556b Bump github.com/stretchr/testify from 1.8.0 to 1.8.1
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.0...v1.8.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-24 17:49:28 +00:00
Łukasz Budnik
27d54a67c5 Merge pull request #46 from lukaszbudnik/dependabot/github_actions/docker/build-push-action-3
Bump docker/build-push-action from 2 to 3
2022-10-07 22:56:46 +02:00
dependabot[bot]
394b6c6b19 Bump docker/build-push-action from 2 to 3
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 2 to 3.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-07 20:52:09 +00:00
Łukasz Budnik
572a661570 Merge pull request #45 from lukaszbudnik/dependabot/github_actions/docker/metadata-action-4
Bump docker/metadata-action from 3 to 4
2022-10-07 22:51:34 +02:00
dependabot[bot]
ae2c5d1f80 Bump docker/metadata-action from 3 to 4
Bumps [docker/metadata-action](https://github.com/docker/metadata-action) from 3 to 4.
- [Release notes](https://github.com/docker/metadata-action/releases)
- [Upgrade guide](https://github.com/docker/metadata-action/blob/master/UPGRADE.md)
- [Commits](https://github.com/docker/metadata-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: docker/metadata-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-07 20:49:08 +00:00
Łukasz Budnik
0b8223504c Merge pull request #48 from lukaszbudnik/dependabot/github_actions/actions/setup-go-3.2.0
Bump actions/setup-go from 2 to 3.2.0
2022-10-07 22:48:34 +02:00
dependabot[bot]
d10a176e53 Bump actions/setup-go from 2 to 3.2.0
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 2 to 3.2.0.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v2...v3.2.0)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-07 20:44:58 +00:00
Łukasz Budnik
e8636e09ac Merge pull request #53 from lukaszbudnik/dependabot/go_modules/github.com/stretchr/testify-1.8.0
Bump github.com/stretchr/testify from 1.7.0 to 1.8.0
2022-10-07 22:44:00 +02:00
dependabot[bot]
109e665451 Bump github.com/stretchr/testify from 1.7.0 to 1.8.0
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.0 to 1.8.0.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.0...v1.8.0)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-07 20:32:54 +00:00
Łukasz Budnik
33c6293042 Merge pull request #55 from lukaszbudnik/dependabot/docker/alpine-3.16.2
Bump alpine from 3.14.2 to 3.16.2
2022-10-07 22:31:53 +02:00
dependabot[bot]
6c93e2987b Bump alpine from 3.14.2 to 3.16.2
Bumps alpine from 3.14.2 to 3.16.2.

---
updated-dependencies:
- dependency-name: alpine
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-07 20:29:23 +00:00
Łukasz Budnik
cfdeef0e2a Merge pull request #44 from lukaszbudnik/dependabot/github_actions/docker/login-action-2
Bump docker/login-action from 1 to 2
2022-10-07 22:28:26 +02:00
dependabot[bot]
1842453288 Bump docker/login-action from 1 to 2
Bumps [docker/login-action](https://github.com/docker/login-action) from 1 to 2.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](https://github.com/docker/login-action/compare/v1...v2)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-07 20:26:52 +00:00
Łukasz Budnik
9fdfd5cb17 Merge pull request #56 from lukaszbudnik/dependabot/github_actions/actions/checkout-3.1.0
Bump actions/checkout from 2.4.0 to 3.1.0
2022-10-07 22:26:15 +02:00
dependabot[bot]
62d92811ce Bump actions/checkout from 2.4.0 to 3.1.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3.1.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.4.0...v3.1.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-04 17:07:54 +00:00
Łukasz Budnik
5e0380377f Merge pull request #31 from lukaszbudnik/dependabot/docker/golang-1.17.3-alpine3.13
Bump golang from 1.17.2-alpine3.13 to 1.17.3-alpine3.13
2021-11-05 18:28:09 +01:00
dependabot[bot]
669c88abce Bump golang from 1.17.2-alpine3.13 to 1.17.3-alpine3.13
Bumps golang from 1.17.2-alpine3.13 to 1.17.3-alpine3.13.

---
updated-dependencies:
- dependency-name: golang
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-05 17:09:55 +00:00
Łukasz Budnik
46ce22d8ec Merge pull request #30 from lukaszbudnik/dependabot/github_actions/actions/checkout-2.4.0
Bump actions/checkout from 2.3.5 to 2.4.0
2021-11-03 18:20:39 +01:00
dependabot[bot]
6e8531123f Bump actions/checkout from 2.3.5 to 2.4.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.5 to 2.4.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.3.5...v2.4.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-03 17:07:22 +00:00
Łukasz Budnik
f651a27580 Merge pull request #29 from lukaszbudnik/dependabot/github_actions/actions/checkout-2.3.5
Bump actions/checkout from 2.3.4 to 2.3.5
2021-10-16 08:35:46 +02:00
dependabot[bot]
900118758f Bump actions/checkout from 2.3.4 to 2.3.5
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.4 to 2.3.5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.3.4...v2.3.5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-15 17:07:06 +00:00
Łukasz Budnik
2da157319c Merge pull request #26 from lukaszbudnik/dependabot/docker/alpine-3.14.2
Bump alpine from 3.14.1 to 3.14.2
2021-10-08 19:51:42 +02:00
dependabot[bot]
1f0946a0b1 Bump alpine from 3.14.1 to 3.14.2
Bumps alpine from 3.14.1 to 3.14.2.

---
updated-dependencies:
- dependency-name: alpine
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-08 17:50:47 +00:00
Łukasz Budnik
1b5234d37c Merge pull request #28 from lukaszbudnik/dependabot/docker/golang-1.17.2-alpine3.13
Bump golang from 1.17.0-alpine3.13 to 1.17.2-alpine3.13
2021-10-08 19:50:11 +02:00
dependabot[bot]
b334dcfcea Bump golang from 1.17.0-alpine3.13 to 1.17.2-alpine3.13
Bumps golang from 1.17.0-alpine3.13 to 1.17.2-alpine3.13.

---
updated-dependencies:
- dependency-name: golang
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-08 17:06:54 +00:00
Łukasz Budnik
f09931b33a Create FUNDING.yml 2021-09-01 12:56:16 +02:00
Łukasz Budnik
afd2708b14 Merge pull request #25 from lukaszbudnik/additional-fields-in-json-response
additional fields in JSON response
2021-08-24 21:27:44 +02:00
Łukasz Budnik
f35f940d90 additional fields in JSON response 2021-08-24 21:25:44 +02:00
Łukasz Budnik
54942ada28 Merge pull request #22 from lukaszbudnik/dependabot/docker/golang-1.17.0-alpine3.13
Bump golang from 1.16.3-alpine3.13 to 1.17.0-alpine3.13
2021-08-20 15:00:37 +02:00
dependabot[bot]
cc1fbdc2b9 Bump golang from 1.16.3-alpine3.13 to 1.17.0-alpine3.13
Bumps golang from 1.16.3-alpine3.13 to 1.17.0-alpine3.13.

---
updated-dependencies:
- dependency-name: golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-20 12:58:27 +00:00
Łukasz Budnik
865440a0b0 Merge pull request #24 from lukaszbudnik/release-pipeline-tweaks
all pushed to main will not create latest tag
2021-08-20 14:57:45 +02:00
Łukasz Budnik
300d243657 all pushed to main will not create latest tag (reserved for versions now); instead edge tag is pushed 2021-08-20 14:54:45 +02:00
Łukasz Budnik
5be69cf38d Merge pull request #21 from lukaszbudnik/dependabot/docker/alpine-3.14.1
Bump alpine from 3.13 to 3.14.1
2021-08-20 14:51:37 +02:00
dependabot[bot]
1701c6cbe5 Bump alpine from 3.13 to 3.14.1
Bumps alpine from 3.13 to 3.14.1.

---
updated-dependencies:
- dependency-name: alpine
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-20 12:16:07 +00:00
Łukasz Budnik
f1ca7d069c Merge pull request #23 from lukaszbudnik/new-docker-publish-pipeline
changes to docker pipelines (autobuilds disabled on Docker Hub)
2021-08-20 14:15:11 +02:00
Łukasz Budnik
0ae522a43e changes to docker pipelines (autobuilds disabled on Docker Hub) 2021-08-20 14:12:34 +02:00
Łukasz Budnik
3af4030d87 Merge pull request #15 from lukaszbudnik/dependabot/github_actions/actions/checkout-2.3.4
Bump actions/checkout from 2 to 2.3.4
2021-08-20 13:51:39 +02:00
dependabot[bot]
cc7ae5835f Bump actions/checkout from 2 to 2.3.4
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 2.3.4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v2.3.4)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-12 05:57:58 +00:00
Łukasz Budnik
1307c185e0 Merge pull request #13 from lukaszbudnik/dependabot/docker/golang-1.16.3-alpine3.13
Bump golang from 1.16.2-alpine3.13 to 1.16.3-alpine3.13
2021-04-04 13:58:42 +02:00
dependabot[bot]
dc016ceccc Bump golang from 1.16.2-alpine3.13 to 1.16.3-alpine3.13
Bumps golang from 1.16.2-alpine3.13 to 1.16.3-alpine3.13.

Signed-off-by: dependabot[bot] <support@github.com>
2021-04-02 07:20:59 +00:00
Łukasz Budnik
2cd59bd065 Merge pull request #12 from lukaszbudnik/dependabot/docker/golang-1.16.2-alpine3.13
Bump golang from 1.16.0-alpine3.13 to 1.16.2-alpine3.13
2021-03-29 09:50:07 +02:00
dependabot[bot]
664b9f425d Bump golang from 1.16.0-alpine3.13 to 1.16.2-alpine3.13
Bumps golang from 1.16.0-alpine3.13 to 1.16.2-alpine3.13.

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-12 07:17:02 +00:00
Łukasz Budnik
7dc37b1b74 typo in dependabot.yml file 2021-03-01 08:17:17 +01:00
Łukasz Budnik
6786f6753c Merge pull request #10 from lukaszbudnik/dependabot/docker/golang-1.16.0-alpine3.13
Bump golang from 1.15.7-alpine3.13 to 1.16.0-alpine3.13
2021-02-28 22:37:35 +00:00
dependabot[bot]
3744500c5e Bump golang from 1.15.7-alpine3.13 to 1.16.0-alpine3.13
Bumps golang from 1.15.7-alpine3.13 to 1.16.0-alpine3.13.

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-28 21:58:15 +00:00
Łukasz Budnik
866b1a165a Create dependabot.yml 2021-02-28 22:58:00 +01:00
Łukasz Budnik
f8fab8d501 Merge pull request #8 from lukaszbudnik/cors-support
added CORS support
2021-02-16 13:02:35 +01:00
Łukasz Budnik
bb07fc7e6e Merge branch 'main' into cors-support 2021-02-16 13:01:24 +01:00
Łukasz Budnik
7073bea751 added CORS support 2021-02-16 12:59:42 +01:00
Łukasz Budnik
b3fa7f0507 Merge pull request #7 from lukaszbudnik/added-github-workflow-badges
added github workflow badges
2021-02-05 08:36:29 +01:00
Łukasz Budnik
50a90591fc added github workflow badges 2021-02-05 08:35:28 +01:00
Łukasz Budnik
204cd377f5 Merge pull request #6 from lukaszbudnik/better-curl-example
added better curl example
2021-02-04 22:42:42 +01:00
Łukasz Budnik
988ee495ba added better curl example 2021-02-04 22:40:52 +01:00
Łukasz Budnik
67a63bc610 Merge pull request #5 from lukaszbudnik/dockerfile-changes
single Dockerfile for testing and official builds
2021-02-04 08:15:49 +01:00
Łukasz Budnik
9c90cf07e9 single Dockerfile for testing and official builds 2021-02-04 08:05:34 +01:00
Łukasz Budnik
1844d70a58 Merge pull request #4 from lukaszbudnik/github-action-docker-image
Create docker-image.yml GitHub Action
2021-02-04 01:08:26 +01:00
Łukasz Budnik
43e698f307 Merge branch 'main' into github-action-docker-image 2021-02-04 01:03:36 +01:00
Łukasz Budnik
eeecbb33bb Merge pull request #2 from lukaszbudnik/go-modules-gorilla-tests-json
go modules, gorilla web toolkit, changed responses to json
2021-02-04 01:02:08 +01:00
Łukasz Budnik
715a703b0a Create docker-image.yml GitHub action 2021-02-04 00:56:27 +01:00
Łukasz Budnik
a2a3c4f948 dropping support for Travis - GitHub Actions are faster 2021-02-04 00:50:07 +01:00
Łukasz Budnik
defd5bdb32 Merge pull request #3 from lukaszbudnik/using-github-workflows
Create GitHub Actions to build and test yosoy
2021-02-04 00:47:56 +01:00
Łukasz Budnik
908f01df4b Create go.yml 2021-02-04 00:43:12 +01:00
Łukasz Budnik
1a1f4cf14d converted to go modules, added gorilla web toolkit, added test, changed yosoy to respond with JSON rather than plain text, added travis support 2021-02-04 00:29:22 +01:00
Łukasz Budnik
cd90e887fe switched to gorilla, added out of the box handlers for logging, proxy headers, and recovery 2021-02-03 09:08:31 +01:00
Łukasz Budnik
b013a03c8f Merge pull request #1 from lukaszbudnik/sorting-headers-ignoring-favicon
implemented sorting headers, added ignoring (404) /favicon.ico requests
2021-02-03 06:36:28 +01:00
Łukasz Budnik
3b5c522e2f implemented sorting headers, added ignoring (404) /favicon.ico requests 2021-02-03 06:34:15 +01:00
13 changed files with 442 additions and 163 deletions

3
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,3 @@
# These are supported funding model platforms
github: [lukaszbudnik]

17
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,17 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
# Maintain dependencies for go lang
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
# Maintain dependencies for docker
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"

26
.github/workflows/docker-image.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: Docker Image CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.3.0
- name: Build the Docker image
run: docker build . --file Dockerfile --tag yosoy-local:latest
- name: Run simple integration test
run: |
docker run -p 3333:80 yosoy-local:latest > yosoy.log &
sleep 5
RESULT=$(curl -s -X DELETE -H 'x-api-key: abc123' 'http://0.0.0.0:3333/sample/path?with=params')
echo "$RESULT"
if [[ $RESULT =~ '"method":"DELETE"' ]]
then
echo 'Test successful'
exit 0
else
echo 'Test failure'
exit 1
fi

52
.github/workflows/docker-publish.yml vendored Normal file
View File

@@ -0,0 +1,52 @@
name: Publish Docker image
on:
push:
branches: [main]
release:
types: [published]
jobs:
push_to_registries:
name: Push Docker image to Docker Hub and ghcr.io registries
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v3.3.0
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
lukasz/yosoy
ghcr.io/${{ github.repository }}
tags: |
type=edge
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push Docker images
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

20
.github/workflows/go.yml vendored Normal file
View File

@@ -0,0 +1,20 @@
name: Go
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.3.0
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
debug.test
yosoy

View File

@@ -1,13 +1,12 @@
FROM golang:1.13.5-alpine3.10 as builder
FROM golang:1.19-alpine as builder
MAINTAINER Łukasz Budnik lukasz.budnik@gmail.com
LABEL maintainer="Łukasz Budnik lukasz.budnik@gmail.com"
# build yosoy
RUN apk add git
RUN git clone https://github.com/lukaszbudnik/yosoy.git
ADD . /go/yosoy
RUN cd /go/yosoy && go build
FROM alpine:3.10
FROM alpine:3.17
COPY --from=builder /go/yosoy/yosoy /bin
# register entrypoint

228
README.md
View File

@@ -1,151 +1,133 @@
# yosoy
# yosoy ![Go](https://github.com/lukaszbudnik/yosoy/workflows/Go/badge.svg) ![Docker](https://github.com/lukaszbudnik/yosoy/workflows/Docker%20Image%20CI/badge.svg)
yosoy is a HTTP service for stubbing and prototyping distributed applications. It is a service which will introduce itself to the caller and print some useful information about its environment. "Yo soy" in español means "I am".
yosoy is extremely useful when creating a distributed application stub and you need to see a more meaningful responses than a default nginx welcome page.
yosoy is extremely useful when creating a distributed application stub and you need to see more meaningful responses than a default nginx welcome page.
Typical use cases include:
* testing HTTP routing & ingress
* testing HTTP load balancing
* testing HTTP caching
* stubbing and prototyping the infrastructure
- testing HTTP routing & ingress
- testing HTTP load balancing
- testing HTTP caching
- stubbing and prototyping distributed applications
yosoy will provide information like:
## API
* Request URI
* Hostname
* Remote IP
* How many times it was called
* HTTP headers
* Env variables if `YOSOY_SHOW_ENVS` is set to `true`, `yes`, `on`, or `1`
* Files' contents if `YOSOY_SHOW_FILES` is set to a comma-separated list of (valid) files
yosoy responds to all requests with a JSON containing the information about:
See [Kubernetes example](#kubernetes-example) below.
- HTTP request:
- Host
- Request URI
- Method
- Scheme
- Proto
- URL
- Remote IP
- HTTP headers
- HTTP proxy headers
- host:
- Hostname
- How many times it was called
- Env variables if `YOSOY_SHOW_ENVS` is set to `true`, `yes`, `on`, or `1`
- Files' contents if `YOSOY_SHOW_FILES` is set to a comma-separated list of (valid) files
Checkout out [Sample JSON response](#sample-json-response) below to see how useful yosoy is when troubleshooting/stubbing/prototyping distributed applications.
## Docker image
The docker image is available on docker hub:
```sh
docker pull lukasz/yosoy
```
lukasz/yosoy
and ghcr.io:
```sh
docker pull ghcr.io/lukaszbudnik/yosoy
```
It exposes HTTP service on port 80.
## Kubernetes example
Let's take a look at a sample Kubernetes deployment file. It uses both `YOSOY_SHOW_ENVS` and `YOSOY_SHOW_FILES`.
There is a sample Kubernetes deployment file in the `test` folder. It uses both `YOSOY_SHOW_ENVS` and `YOSOY_SHOW_FILES`. The deployment uses Kubernetes Downward API to expose labels and annotations as volume files which are then returned by yosoy.
> To illustrate `YOSOY_SHOW_FILES` functionality it uses Kubernetes Downward API to expose labels and annotations as volume files which are then read by yosoy.
Deploy it to minikube and execute curl to the service a couple of times:
```
apiVersion: apps/v1
kind: Deployment
metadata:
name: camarero
labels:
app.kubernetes.io/name: camarero
spec:
replicas: 2
selector:
matchLabels:
app.kubernetes.io/name: camarero
template:
metadata:
labels:
app.kubernetes.io/name: camarero
spec:
containers:
- name: yosoy
image: lukasz/yosoy
env:
- name: YOSOY_SHOW_ENVS
value: "true"
- name: YOSOY_SHOW_FILES
value: "/etc/podinfo/labels,/etc/podinfo/annotations"
ports:
- containerPort: 80
volumeMounts:
- name: podinfo
mountPath: /etc/podinfo
volumes:
- name: podinfo
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- path: "annotations"
fieldRef:
fieldPath: metadata.annotations
---
apiVersion: v1
kind: Service
metadata:
name: camarero
labels:
app.kubernetes.io/name: camarero
spec:
type: NodePort
selector:
app.kubernetes.io/name: camarero
ports:
- protocol: TCP
port: 80
```bash
# start minikube
minikube start
# deploy test service
kubectl apply -f test/deployment.yaml
# tunnel to it and copy the URL as $URL variable
minikube service --url camarero
# simulate some HTTP requests
curl -H "Host: gateway.myapp.com" $URL/camarero/abc
curl -H "Host: gateway.myapp.com" $URL/camarero/abc
curl -H "Host: gateway.myapp.com" $URL/camarero/abc
curl -H "Host: gateway.myapp.com" $URL/camarero/abc
```
Deploy above service (with 2 replicas) and execute curl to the service a couple of times:
## Sample JSON response
```
kubectl apply -f test-deployment.yaml
export NODE_PORT=$(kubectl get services/camarero -o go-template='{{(index .spec.ports 0).nodePort}}')
curl $(minikube ip):$NODE_PORT
curl $(minikube ip):$NODE_PORT
curl $(minikube ip):$NODE_PORT
curl $(minikube ip):$NODE_PORT
```
A sample response looks like this:
```
Request URI: /
Hostname: camarero-859d7c6d6b-kb5s5
Remote IP: 172.18.0.1
Called: 2
HTTP headers:
User-Agent: curl/7.58.0
Accept: */*
Env variables:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=camarero-859d7c6d6b-kb5s5
YOSOY_SHOW_ENVS=true
YOSOY_SHOW_FILES=/etc/podinfo/labels,/etc/podinfo/annotations
CAMARERO_PORT_80_TCP_PORT=80
CAMARERO_PORT_80_TCP_ADDR=10.105.203.131
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_PORT=443
CAMARERO_SERVICE_HOST=10.105.203.131
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
CAMARERO_PORT=tcp://10.105.203.131:80
CAMARERO_SERVICE_PORT=80
CAMARERO_PORT_80_TCP=tcp://10.105.203.131:80
CAMARERO_PORT_80_TCP_PROTO=tcp
HOME=/root
File /etc/podinfo/labels:
app.kubernetes.io/name="camarero"
pod-template-hash="859d7c6d6b"
File /etc/podinfo/annotations:
kubernetes.io/config.seen="2020-11-17T07:38:15.374049163Z"
kubernetes.io/config.source="api"
A sample yosoy JSON response to a request made from a single page application (SPA) to a backend API deployed in Kubernetes behind nginx ingress and [haproxy-auth-gateway](https://github.com/lukaszbudnik/haproxy-auth-gateway) looks like this:
```json
{
"host": "api.localtest.me",
"proto": "HTTP/1.1",
"method": "GET",
"scheme": "https",
"requestUri": "/camarero",
"url": "https:///camarero",
"remoteAddr": "192.168.65.3",
"counter": 1,
"headers": {
"Accept": ["*/*"],
"Accept-Encoding": ["gzip, deflate, br"],
"Accept-Language": ["en-US,en;q=0.9,pl-PL;q=0.8,pl;q=0.7,es;q=0.6"],
"Authorization": [
"Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJXejFuaDNCWDI4UHMxVEMzSDRoOW52Q1VWRXpjVVBzQms4Z1NmeEp4ZS1JIn0.eyJleHAiOjE2Mjk4MjM3OTMsImlhdCI6MTYyOTgyMjg5MywiYXV0aF90aW1lIjoxNjI5ODIyODkyLCJqdGkiOiI3ZmQzMjkwZi05NjMyLTQ0NzEtYjRjOS1lNTFjZDYwMjllYjgiLCJpc3MiOiJodHRwczovL2F1dGgubG9jYWx0ZXN0Lm1lL2F1dGgvcmVhbG1zL2hvdGVsIiwic3ViIjoiMDdmYzM3YmYtMmJjNy00ZTRmLWE3MDUtYzRjNjgzNTIwYmU1IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoicmVhY3QiLCJub25jZSI6IjQzNDhmMjU5LTliYTYtNDk2ZC04N2I5LWZmZGYzNDMwN2UzOSIsInNlc3Npb25fc3RhdGUiOiJmNTM5OGI3Ny01OTNhLTQ3OWYtOTc5NS00NGIyNGJjMjhkYjQiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHBzOi8vbHVrYXN6YnVkbmlrLmdpdGh1Yi5pbyJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsiY2FtYXJlcm8iXX0sInNjb3BlIjoib3BlbmlkIGVtYWlsIHByb2ZpbGUiLCJzaWQiOiJmNTM5OGI3Ny01OTNhLTQ3OWYtOTc5NS00NGIyNGJjMjhkYjQiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsIm5hbWUiOiJKdWxpbyIsInByZWZlcnJlZF91c2VybmFtZSI6Imp1bGlvIiwiZ2l2ZW5fbmFtZSI6Ikp1bGlvIn0.t5y3L4FzGxM0zwI3fskDI8Kemxz_izcvPPKciSEvNHnZWGQK-9AclGNFz_A9cLFSkpc6l6lBmt7WaC0i04c4h1a9G9AOFImmVXPMPDdTXOQ4aah4CvlN6Fy8ShvSHrQA-wMHEELBpIFsKFx2WP3QHiy27ycr3kqQzW4QymyU7J8tM4-qKR_H1_8aiNOrm5fIED-nEP096V2zvWXiGZX7ts6XE2-annhKphCABLdmIiwgDUnhlAz0hdiDrDbIjzr0ldW4AnUkSQxIZY0PnoEnGVuUvkOYvJpFx10gjORMnRgHSEj9Mk5dtyVGHcihZ5TntCL40WoymNxae6K4-FH3Lw"
],
"Origin": ["https://lukaszbudnik.github.io"],
"Referer": ["https://lukaszbudnik.github.io/"],
"Sec-Ch-Ua": [
"\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\""
],
"Sec-Ch-Ua-Mobile": ["?0"],
"Sec-Fetch-Dest": ["empty"],
"Sec-Fetch-Mode": ["cors"],
"Sec-Fetch-Site": ["cross-site"],
"User-Agent": [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
],
"X-Forwarded-For": ["192.168.65.3", "10.1.3.9"],
"X-Forwarded-Host": ["api.localtest.me"],
"X-Forwarded-Port": ["443"],
"X-Forwarded-Proto": ["https"],
"X-Real-Ip": ["192.168.65.3"],
"X-Request-Id": ["48a77564d88ca8a893610b9458bfd885"],
"X-Scheme": ["https"]
},
"hostname": "camarero-cf7c95ccd-cz5lh",
"envVariables": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"HOSTNAME=camarero-cf7c95ccd-cz5lh",
"YOSOY_SHOW_FILES=/etc/podinfo/labels,/etc/podinfo/annotations",
"YOSOY_SHOW_ENVS=true",
"KUBERNETES_SERVICE_PORT=443",
"KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443",
"KUBERNETES_PORT=tcp://10.96.0.1:443",
"KUBERNETES_PORT_443_TCP_PORT=443",
"KUBERNETES_SERVICE_HOST=10.96.0.1",
"KUBERNETES_PORT_443_TCP_PROTO=tcp",
"KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1",
"HOME=/root"
],
"files": {
"/etc/podinfo/annotations": "kubernetes.io/config.seen=\"2021-08-24T15:12:19.555374430Z\"\nkubernetes.io/config.source=\"api\"",
"/etc/podinfo/labels": "app.kubernetes.io/component=\"api\"\napp.kubernetes.io/name=\"camarero\"\napp.kubernetes.io/part-of=\"hotel\"\napp.kubernetes.io/version=\"0.0.1\"\npod-template-hash=\"cf7c95ccd\""
}
}
```

9
go.mod Normal file
View File

@@ -0,0 +1,9 @@
module github.com/lukaszbudnik/yosoy
go 1.16
require (
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/stretchr/testify v1.8.1
)

23
go.sum Normal file
View File

@@ -0,0 +1,23 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

116
server.go
View File

@@ -1,65 +1,111 @@
package main
import (
"fmt"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"time"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
type response struct {
Host string `json:"host"`
Proto string `json:"proto"`
Method string `json:"method"`
Scheme string `json:"scheme"`
RequestURI string `json:"requestUri"`
URL string `json:"url"`
RemoteAddr string `json:"remoteAddr"`
Counter int `json:"counter"`
Headers map[string][]string `json:"headers"`
Hostname string `json:"hostname"`
EnvVariables []string `json:"envVariables,omitempty"`
Files map[string]string `json:"files,omitempty"`
}
var counter = 0
var hostname = os.Getenv("HOSTNAME")
var showEnvs = os.Getenv("YOSOY_SHOW_ENVS")
var showFiles = os.Getenv("YOSOY_SHOW_FILES")
func preflight(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "*")
w.Header().Set("Access-Control-Allow-Headers", "*")
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Expose-Headers", "*")
w.Header().Set("Access-Control-Max-Age", "600")
w.WriteHeader(http.StatusOK)
}
func handler(w http.ResponseWriter, req *http.Request) {
remoteAddr := req.RemoteAddr
// LastIndex works better with IPv6
if index := strings.LastIndex(remoteAddr, ":"); index > 0 {
remoteAddr = remoteAddr[0:index]
}
fmt.Printf("[%v] - %v - %v - \"%v %v\"\n", hostname, time.Now().Format(time.RFC3339), remoteAddr, req.Method, req.RequestURI)
w.WriteHeader(200)
w.Header().Add("Content-Type", "text/plain")
fmt.Fprintf(w, "Request URI: %v\n", req.RequestURI)
fmt.Fprintf(w, "Hostname: %v\n", hostname)
fmt.Fprintf(w, "Remote IP: %v\n", remoteAddr)
w.Header().Set("Access-Control-Allow-Origin", "*")
showEnvs := os.Getenv("YOSOY_SHOW_ENVS")
showFiles := os.Getenv("YOSOY_SHOW_FILES")
response := &response{}
counter++
fmt.Fprintf(w, "Called: %v\n", counter)
fmt.Fprintln(w)
fmt.Fprintf(w, "HTTP headers:\n")
for name, headers := range req.Header {
for _, h := range headers {
fmt.Fprintf(w, "%v: %v\n", name, h)
}
}
response.Counter = counter
remoteAddr := remoteAddrWithoutPort(req)
response.RemoteAddr = remoteAddr
response.RequestURI = req.RequestURI
response.Host = req.Host
response.Proto = req.Proto
response.Method = req.Method
response.Scheme = req.URL.Scheme
response.Headers = req.Header
response.URL = req.URL.String()
response.Hostname = hostname
if strings.ToLower(showEnvs) == "true" || strings.ToLower(showEnvs) == "yes" || strings.ToLower(showEnvs) == "on" || showEnvs == "1" {
fmt.Fprintln(w)
fmt.Fprintf(w, "Env variables:\n")
for _, e := range os.Environ() {
fmt.Fprintln(w, e)
}
response.EnvVariables = os.Environ()
}
if len(showFiles) > 0 {
response.Files = make(map[string]string)
files := strings.Split(showFiles, ",")
for _, file := range files {
bytes, err := ioutil.ReadFile(file)
if err != nil {
fmt.Printf("[%v] - %v - could not read file %v: %v\n", hostname, time.Now().Format(time.RFC3339), file, err)
log.Printf("Could not read file %v: %v\n", file, err)
continue
}
fmt.Fprintln(w)
fmt.Fprintf(w, "File %v:\n", file)
contents := string(bytes)
fmt.Fprintln(w, contents)
response.Files[file] = contents
}
}
w.Header().Add("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}
func remoteAddrWithoutPort(req *http.Request) string {
remoteAddr := req.RemoteAddr
if index := strings.LastIndex(remoteAddr, ":"); index > 0 {
remoteAddr = remoteAddr[0:index]
}
return remoteAddr
}
func main() {
fmt.Printf("[%v] - %v - yosoy is up!\n", hostname, time.Now().Format(time.RFC3339))
http.HandleFunc("/", handler)
http.ListenAndServe(":80", nil)
log.Printf("yosoy is up %v\n", hostname)
r := mux.NewRouter()
r.Handle("/favicon.ico", r.NotFoundHandler)
r.PathPrefix("/").HandlerFunc(preflight).Methods(http.MethodOptions)
r.PathPrefix("/").HandlerFunc(handler).Methods(http.MethodGet, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete, http.MethodConnect, http.MethodHead, http.MethodTrace)
loggingRouter := handlers.CombinedLoggingHandler(os.Stdout, r)
proxyRouter := handlers.ProxyHeaders(loggingRouter)
recoveryRouter := handlers.RecoveryHandler()(proxyRouter)
http.ListenAndServe(":80", recoveryRouter)
}

47
server_test.go Normal file
View File

@@ -0,0 +1,47 @@
package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHandler(t *testing.T) {
os.Setenv("YOSOY_SHOW_ENVS", "true")
os.Setenv("YOSOY_SHOW_FILES", ".gitignore")
req, err := http.NewRequest("GET", "https://example.org/sample/path?one=jeden&two=dwa", nil)
if err != nil {
t.Fatal(err)
}
req.Header.Set("Accept", "*/*")
rr := httptest.NewRecorder()
handler := http.HandlerFunc(handler)
handler.ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusOK)
}
var response response
json.Unmarshal(rr.Body.Bytes(), &response)
// test response
assert.Equal(t, 1, response.Counter)
assert.Equal(t, "example.org", response.Host)
assert.Equal(t, "GET", response.Method)
assert.Equal(t, "https", response.Scheme)
assert.Equal(t, "HTTP/1.1", response.Proto)
assert.Equal(t, "https://example.org/sample/path?one=jeden&two=dwa", response.URL)
assert.NotEmpty(t, response.EnvVariables)
assert.NotEmpty(t, response.Files[".gitignore"])
// test cors
assert.Contains(t, rr.HeaderMap["Access-Control-Allow-Origin"], "*")
}

53
test/deployment.yaml Normal file
View File

@@ -0,0 +1,53 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: camarero
labels:
app.kubernetes.io/name: camarero
spec:
replicas: 2
selector:
matchLabels:
app.kubernetes.io/name: camarero
template:
metadata:
labels:
app.kubernetes.io/name: camarero
spec:
containers:
- name: yosoy
image: lukasz/yosoy:2.0.3
env:
- name: YOSOY_SHOW_ENVS
value: "true"
- name: YOSOY_SHOW_FILES
value: "/etc/podinfo/labels,/etc/podinfo/annotations"
ports:
- containerPort: 80
volumeMounts:
- name: podinfo
mountPath: /etc/podinfo
volumes:
- name: podinfo
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- path: "annotations"
fieldRef:
fieldPath: metadata.annotations
---
apiVersion: v1
kind: Service
metadata:
name: camarero
labels:
app.kubernetes.io/name: camarero
spec:
type: NodePort
selector:
app.kubernetes.io/name: camarero
ports:
- protocol: TCP
port: 80