Skip to content

Commit

Permalink
Create release automatically (#2)
Browse files Browse the repository at this point in the history
The releases include binaries for:
* linux/amd64
* linux/arm
* linux/arm64
  • Loading branch information
rthellend committed Jul 4, 2023
1 parent 46f42a4 commit d98de27
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}


- name: Get release version
run: echo "VERSION=${GITHUB_REF}" > version.sh
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175
Expand Down
29 changes: 27 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,44 @@ on:
jobs:
build-and-run-tests:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Build
run: go build -v ./...
run: go build ./...
- name: Run go vet
run: go vet ./...
- name: Run go tests
run: go test -v ./...
- name: Run go tests (-race)
run: go test -race -v ./...
- name: Build docker image
run: docker build -t c2fmzq/tlsproxy .
run: |
touch version.sh
docker build -t c2fmzq/tlsproxy:test .
docker run --rm --interactive c2fmzq/tlsproxy:test -v
- name: Build release binaries
if: startsWith(github.ref, 'refs/tags/v')
run: |
export CGO_ENABLED=0
flag="-ldflags=-s -w -X main.Version=${GITHUB_REF_NAME}"
for arch in amd64 arm arm64; do
GOARCH="${arch}" go build -trimpath "${flag}" -o "tlsproxy-linux-${arch}" ./proxy
sha256sum "tlsproxy-linux-${arch}" | cut -d " " -f1 > "tlsproxy-linux-${arch}.sha256"
done
- name: Create release
# https://github.com/softprops/action-gh-release/tree/v0.1.15
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
if: startsWith(github.ref, 'refs/tags/v')
with:
draft: false
generate_release_notes: true
fail_on_unmatched_files: true
files: |
tlsproxy-linux-*
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ RUN go mod download

ADD proxy /app/go/src/tlsproxy/proxy
ADD internal /app/go/src/tlsproxy/internal
ADD version.sh /app/go/src/tlsproxy
WORKDIR /app/go/src/tlsproxy
RUN go install ./proxy
RUN source version.sh && go install -ldflags="-s -w -X main.Version=${VERSION:-dev}" ./proxy

FROM scratch
WORKDIR /
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2023 TTBT Enterprises LLC
Copyright (c) 2023 Robin Thellend <rthellend@rthellend.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 5 additions & 9 deletions internal/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// MIT License
//
// Copyright (c) 2023 TTBT Enterprises LLC
// Copyright (c) 2023 Robin Thellend <rthellend@rthellend.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -33,7 +34,6 @@ import (
"sync"
"time"

"golang.org/x/sys/unix"
"golang.org/x/time/rate"
yaml "gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -131,15 +131,11 @@ func (cfg *Config) Check() error {
cfg.TLSAddr = ":10443"
}
if cfg.MaxOpen == 0 {
var rl unix.Rlimit
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rl); err != nil {
return err
}
rl.Cur = rl.Max
if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &rl); err != nil {
return err
n, err := openFileLimit()
if err != nil {
return errors.New("MaxOpen: value must be set")
}
cfg.MaxOpen = int(rl.Cur/2 - 100)
cfg.MaxOpen = n/2 - 100
}

serverNames := make(map[string]bool)
Expand Down
1 change: 1 addition & 0 deletions internal/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// MIT License
//
// Copyright (c) 2023 TTBT Enterprises LLC
// Copyright (c) 2023 Robin Thellend <rthellend@rthellend.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions internal/listener.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// MIT License
//
// Copyright (c) 2023 TTBT Enterprises LLC
// Copyright (c) 2023 Robin Thellend <rthellend@rthellend.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
34 changes: 34 additions & 0 deletions internal/otheros.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// MIT License
//
// Copyright (c) 2023 TTBT Enterprises LLC
// Copyright (c) 2023 Robin Thellend <rthellend@rthellend.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

//go:build !unix

package internal

import (
"errors"
)

func openFileLimit() (int, error) {
return 0, errors.New("unable to get the limit of open files")
}
1 change: 1 addition & 0 deletions internal/proxy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// MIT License
//
// Copyright (c) 2023 TTBT Enterprises LLC
// Copyright (c) 2023 Robin Thellend <rthellend@rthellend.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions internal/proxy_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// MIT License
//
// Copyright (c) 2023 TTBT Enterprises LLC
// Copyright (c) 2023 Robin Thellend <rthellend@rthellend.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
42 changes: 42 additions & 0 deletions internal/unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// MIT License
//
// Copyright (c) 2023 TTBT Enterprises LLC
// Copyright (c) 2023 Robin Thellend <rthellend@rthellend.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

//go:build unix

package internal

import (
"golang.org/x/sys/unix"
)

func openFileLimit() (int, error) {
var rl unix.Rlimit
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rl); err != nil {
return 0, err
}
rl.Cur = rl.Max
if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &rl); err != nil {
return 0, err
}
return int(rl.Cur), nil
}
11 changes: 11 additions & 0 deletions proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// MIT License
//
// Copyright (c) 2023 TTBT Enterprises LLC
// Copyright (c) 2023 Robin Thellend <rthellend@thellend.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -30,22 +31,32 @@ import (
"log"
"os"
"os/signal"
"runtime"
"syscall"
"time"

"github.com/c2FmZQ/tlsproxy/internal"
)

// Version is set with -ldflags="-X main.Version=${VERSION}"
var Version = "dev"

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

configFile := flag.String("config", "", "The config file name")
versionFlag := flag.Bool("v", false, "Show the version")
flag.Parse()

if *versionFlag {
os.Stdout.WriteString(Version + " " + runtime.Version() + "\n")
return
}
if *configFile == "" {
log.Fatal("--config must be set")
}
log.Printf("INFO tlsproxy %s %s", Version, runtime.Version())
cfg, err := internal.ReadConfig(*configFile)
if err != nil {
log.Fatalf("ERR %v", err)
Expand Down

0 comments on commit d98de27

Please sign in to comment.