25 Commits

Author SHA1 Message Date
Ł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
9 changed files with 112 additions and 37 deletions

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"

View File

@@ -1,18 +1,12 @@
name: Docker Image CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile --tag yosoy-local:$(date +%s)
- uses: actions/checkout@v2.3.4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag yosoy-local:$(date +%s)

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@v2
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
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@v2
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

View File

@@ -1,25 +1,20 @@
name: Go
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2.3.4
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Build
run: go build -v ./...
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
- name: Test
run: go test -v ./...

View File

@@ -1,4 +1,4 @@
FROM golang:1.15.7-alpine3.13 as builder
FROM golang:1.17.0-alpine3.13 as builder
LABEL maintainer="Łukasz Budnik lukasz.budnik@gmail.com"
@@ -6,7 +6,7 @@ LABEL maintainer="Łukasz Budnik lukasz.budnik@gmail.com"
ADD . /go/yosoy
RUN cd /go/yosoy && go build
FROM alpine:3.13
FROM alpine:3.14.1
COPY --from=builder /go/yosoy/yosoy /bin
# register entrypoint

View File

@@ -1,4 +1,4 @@
# 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".
@@ -52,19 +52,19 @@ minikube start
kubectl apply -f test/deployment.yaml
# tunnel to it and copy the URL as $URL variable
minikube service --url camarero
# call it a few times
curl $URL
curl $URL
curl $URL
curl $URL
# 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
```
A sample response looks like this:
```json
{
"host": "127.0.0.1:53366",
"requestUri": "/",
"host": "gateway.myapp.com",
"requestUri": "/camarero/abc",
"remoteAddr": "172.17.0.1",
"counter": 4,
"headers": {

2
go.mod
View File

@@ -1,6 +1,6 @@
module github.com/lukaszbudnik/yosoy
go 1.15
go 1.16
require (
github.com/gorilla/handlers v1.5.1

View File

@@ -26,7 +26,19 @@ type response struct {
var counter = 0
var hostname = os.Getenv("HOSTNAME")
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) {
w.Header().Set("Access-Control-Allow-Origin", "*")
showEnvs := os.Getenv("YOSOY_SHOW_ENVS")
showFiles := os.Getenv("YOSOY_SHOW_FILES")
@@ -80,7 +92,8 @@ func main() {
r := mux.NewRouter()
r.Handle("/favicon.ico", r.NotFoundHandler)
r.PathPrefix("/").HandlerFunc(handler)
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)

View File

@@ -32,8 +32,12 @@ func TestHandler(t *testing.T) {
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.NotEmpty(t, response.EnvVariables)
assert.NotEmpty(t, response.Files[".gitignore"])
// test cors
assert.Contains(t, rr.HeaderMap["Access-Control-Allow-Origin"], "*")
}