From b3166984097821ae686b0b3d50b763e6f3c24e58 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 26 Jun 2022 12:27:43 -0700 Subject: [PATCH] Release with GoReleaser. Allow start without key configuration (#788) --- .github/workflows/buildtest.yaml | 4 +- .github/workflows/docker.yaml | 96 +++++++++++------------ .github/workflows/release.yaml | 40 ++++++++++ .gitignore | 2 + .goreleaser.yaml | 72 +++++++++++++++++ cmd/server/main.go | 32 ++++++-- pkg/sfu/streamtracker.go | 4 +- pkg/telemetry/prometheus/node_nonlinux.go | 1 - 8 files changed, 192 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/buildtest.yaml b/.github/workflows/buildtest.yaml index e3cfb326..28fef6e4 100644 --- a/.github/workflows/buildtest.yaml +++ b/.github/workflows/buildtest.yaml @@ -50,9 +50,9 @@ jobs: args: build - name: Static Check - uses: dominikh/staticcheck-action@v1.1.0 + uses: dominikh/staticcheck-action@v1.2.0 with: - version: "2021.1.1" + version: "2022.1" - name: Test run: | diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 93a47e44..d602cd5d 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -11,57 +11,57 @@ jobs: docker: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: | - ~/go/pkg/mod - ~/go/bin - ~/.cache - key: ${{ runner.os }}-livekit-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-livekit- - - name: Docker meta - id: meta - uses: docker/metadata-action@v3 - with: - # list of Docker images to use as base name for tags - images: | - livekit/livekit-server - # generate Docker tags based on the following events/attributes - tags: | - type=semver,pattern=v{{version}} - type=semver,pattern=v{{major}}.{{minor}} + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/go/pkg/mod + ~/go/bin + ~/.cache + key: ${{ runner.os }}-livekit-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-livekit- + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + # list of Docker images to use as base name for tags + images: | + livekit/livekit-server + # generate Docker tags based on the following events/attributes + tags: | + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.17 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.18 - - name: Download Go modules - run: go mod download + - name: Download Go modules + run: go mod download - - name: Generate code - uses: magefile/mage-action@v1 - with: - version: latest - args: generate + - name: Generate code + uses: magefile/mage-action@v1 + with: + version: latest + args: generate - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push - id: docker_build - uses: docker/build-push-action@v2 - with: - context: . - push: true - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..820cf39f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,40 @@ +name: Release + +on: + workflow_dispatch: + push: + # only publish on version tags + tags: + - 'v*.*.*' + +permissions: + contents: write + +jobs: + release: + runs-on: macos-12 + steps: + - uses: actions/checkout@v2 + - name: Fetch all tags + run: git fetch --force --tags + - uses: actions/cache@v2 + with: + path: | + ~/go/pkg/mod + ~/go/bin + ~/.cache + key: livekit-server + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.18 + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index e14ce8fc..b44d8bda 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ proto/ # IDE .idea + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..2610124c --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,72 @@ +before: + hooks: + - go mod tidy + - go generate ./... +builds: + # darwin build requires CGO, declaring it separately + - id: darwin + env: + - CGO_ENABLED=1 + main: ./cmd/server + binary: livekit-server + goarch: + - amd64 + - arm64 + goos: + - darwin + - id: livekit + env: + - CGO_ENABLED=0 + main: ./cmd/server + binary: livekit-server + goarm: + - "7" + goarch: + - amd64 + - arm64 + - arm + goos: + - linux + - windows +archives: + - format_overrides: + - goos: windows + format: zip + replacements: + darwin: mac + files: + - LICENSE +nfpms: + - package_name: livekit + vendor: LiveKit + homepage: https://livekit.io + description: |- + LiveKit is a high-performance WebRTC server. It provides software components for building multi-user, real-time, media applications. + license: Apache 2.0 + + formats: + - deb + - rpm + + recommends: + - redis-server +release: + github: + owner: livekit + name: livekit + draft: true + prerelease: auto +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +gomod: + proxy: true + mod: mod +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" + diff --git a/cmd/server/main.go b/cmd/server/main.go index a7a00c39..3cbd1f3d 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -13,10 +13,10 @@ import ( "github.com/urfave/cli/v2" + serverlogger "github.com/livekit/livekit-server/pkg/logger" "github.com/livekit/protocol/logger" "github.com/livekit/livekit-server/pkg/config" - serverlogger "github.com/livekit/livekit-server/pkg/logger" "github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/pkg/service" "github.com/livekit/livekit-server/version" @@ -92,7 +92,7 @@ func main() { }, &cli.BoolFlag{ Name: "dev", - Usage: "sets log-level to debug, console formatter, and /debug/pprof", + Usage: "sets log-level to debug, console formatter, and /debug/pprof. insecure for production.", }, }, Action: startServer, @@ -149,7 +149,31 @@ func getConfig(c *cli.Context) (*config.Config, error) { return nil, err } - return config.NewConfig(confString, c) + conf, err := config.NewConfig(confString, c) + if err != nil { + return nil, err + } + serverlogger.InitFromConfig(conf.Logging) + + if c.String("config") == "" && c.String("config-body") == "" { + // without config, use single port UDP + conf.Development = true + conf.RTC.UDPPort = 7882 + conf.RTC.ICEPortRangeStart = 0 + conf.RTC.ICEPortRangeEnd = 0 + logger.Infow("starting in development mode") + + if len(conf.Keys) == 0 { + logger.Infow("no keys provided, using placeholder keys", + "API Key", "devkey", + "API Secret", "secret", + ) + conf.Keys = map[string]string{ + "devkey": "secret", + } + } + } + return conf, nil } func startServer(c *cli.Context) error { @@ -162,8 +186,6 @@ func startServer(c *cli.Context) error { return err } - serverlogger.InitFromConfig(conf.Logging) - if memProfile != "" { if f, err := os.Create(memProfile); err != nil { return err diff --git a/pkg/sfu/streamtracker.go b/pkg/sfu/streamtracker.go index 356743d4..02668b7a 100644 --- a/pkg/sfu/streamtracker.go +++ b/pkg/sfu/streamtracker.go @@ -214,9 +214,7 @@ func (s *StreamTracker) BitrateTemporalCumulative() []int64 { // copy and process brs := make([]int64, len(s.bitrate)) - for i := 0; i < len(s.bitrate); i++ { - brs[i] = s.bitrate[i] - } + copy(brs, s.bitrate[:]) for i := len(brs) - 1; i >= 1; i-- { if brs[i] != 0 { diff --git a/pkg/telemetry/prometheus/node_nonlinux.go b/pkg/telemetry/prometheus/node_nonlinux.go index e9c6f318..61977539 100644 --- a/pkg/telemetry/prometheus/node_nonlinux.go +++ b/pkg/telemetry/prometheus/node_nonlinux.go @@ -1,5 +1,4 @@ //go:build !linux -// +build !linux package prometheus