Skip to content

Commit

Permalink
support proxy protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskim06 committed Aug 10, 2023
1 parent 92face7 commit 9e62c47
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
65 changes: 27 additions & 38 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,31 @@ jobs:
with:
ref: ${{ github.event.inputs.git-ref }}

- name: Testing
- name: Get versions
id: versions
run:
sed 's/ /=/' .tool-versions | tee -a "$GITHUB_OUTPUT"

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ steps.versions.outputs.golang }}

- name: Test
run: make test

- name: Build
run: make docker

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push Docker images to GHCR and DockerHub
run: |
tag="${{ github.event.inputs.git-ref }}"
echo "$tag"
echo "${{ github.sha }}"
# - name: Get versions
# id: versions
# run:
# sed 's/ /=/' .tool-versions | tee -a "$GITHUB_OUTPUT"
#
# - name: Set up Go
# uses: actions/setup-go@v4
# with:
# go-version: ${{ steps.versions.outputs.golang }}
#
# - name: Test
# run: make test
#
# - name: Build
# run: make docker
#
# - name: Log in to the Container registry
# uses: docker/login-action@v2
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Push Docker images to GHCR and DockerHub
# run: |
# tag="${{ github.event.inputs.git-ref }}"
# echo "$tag"
# if [[ $tag == master ]]; then
# tag=latest
# docker tag httpbun "${{ secrets.DOCKER_HUB_USERNAME }}/httpbun:${{ github.sha }}"
# fi
# docker tag httpbun "ghcr.io/${{ github.actor }}/httpbun:$tag"
# docker push --all-tags "ghcr.io/${{ github.actor }}/httpbun"
docker tag httpbun "ghcr.io/${{ github.actor }}/httpbun:${{ github.event.inputs.git-ref }}"
docker tag httpbun "ghcr.io/${{ github.actor }}/httpbun:latest"
docker push --all-tags "ghcr.io/${{ github.actor }}/httpbun"
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require github.com/stretchr/testify v1.7.0

require (
github.com/armon/go-proxyproto v0.0.0-20210323213023-7e956b284f0a // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/armon/go-proxyproto v0.0.0-20210323213023-7e956b284f0a h1:AP/vsCIvJZ129pdm9Ek7bH7yutN3hByqsMoNrWAxRQc=
github.com/armon/go-proxyproto v0.0.0-20210323213023-7e956b284f0a/go.mod h1:QmP9hvJ91BbJmGVGSbutW19IC0Q9phDCLGaomwTJbgU=
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=
Expand Down
14 changes: 11 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package server

import (
"context"
"github.com/sharat87/httpbun/bun"
"github.com/sharat87/httpbun/info"
"log"
"net"
"net/http"
"os"
"time"

proxyproto "github.com/armon/go-proxyproto"
"github.com/sharat87/httpbun/bun"
"github.com/sharat87/httpbun/info"
)

type Config struct {
Expand Down Expand Up @@ -67,10 +69,16 @@ func StartNew(config Config) Server {
Handler: m,
}

listener, err := net.Listen("tcp", config.BindTarget)
var listener net.Listener
l, err := net.Listen("tcp", config.BindTarget)
if err != nil {
log.Fatalf("Error listening on %q: %v", config.BindTarget, err)
}
if os.Getenv("HTTPBUN_USE_PROXY_PROTOCOL") == "true" {
listener = &proxyproto.Listener{Listener: l}
} else {
listener = l
}

closeCh := make(chan error, 1)

Expand Down

0 comments on commit 9e62c47

Please sign in to comment.