diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 63ee50f..2773eb1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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" diff --git a/go.mod b/go.mod index cd22ddc..618021e 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index dc03bd5..65342f7 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/server/server.go b/server/server.go index d8ad7e7..57bd005 100644 --- a/server/server.go +++ b/server/server.go @@ -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 { @@ -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)