From 49b855c49653bbdae9306f1dc62ac999658792f7 Mon Sep 17 00:00:00 2001 From: Lucas van Beek Date: Wed, 2 Feb 2022 16:43:48 +0100 Subject: [PATCH 1/2] Implement debian package --- .goreleaser.yml | 138 +++++--------------------- go.sum | 4 + scripts/defaults | 5 + scripts/postinstall.sh | 5 + scripts/systemd/librespeed-go.service | 13 +++ 5 files changed, 51 insertions(+), 114 deletions(-) create mode 100644 scripts/defaults create mode 100644 scripts/postinstall.sh create mode 100644 scripts/systemd/librespeed-go.service diff --git a/.goreleaser.yml b/.goreleaser.yml index e68cfa4..9a45eb4 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,120 +1,30 @@ -project_name: 'speedtest-go' -#dist: ./out -before: - hooks: - - go mod download +project_name: 'librespeed-go' + builds: - - main: ./main.go - id: speedtest-backend - binary: speedtest-backend - env: + - env: - CGO_ENABLED=0 - flags: - - -trimpath - ldflags: - - -w -s - goos: - - windows - - linux - - darwin - goarch: - - 386 - - amd64 - - arm - - arm64 - - mips - - mipsle - goarm: - - 5 - - 6 - - 7 - gomips: - - hardfloat - - softfloat - ignore: - - goos: darwin - goarch: 386 - - goos: windows - goarch: arm - - goos: windows - goarch: arm64 - hooks: - post: upx -9 "{{ .Path }}" - - main: ./main.go - id: speedtest-backend-freebsd - binary: speedtest-backend - env: - - CGO_ENABLED=0 - flags: - - -trimpath - ldflags: - - -w -s - goos: - - freebsd - goarch: - - 386 - - amd64 - - arm - - arm64 - - mips - - mipsle - goarm: - - 5 - - 6 - - 7 - gomips: - - hardfloat - - softfloat - - main: ./main.go - id: speedtest-backend-noupx-linux - binary: speedtest-backend - env: - - CGO_ENABLED=0 - flags: - - -trimpath - ldflags: - - -w -s - goos: - - linux - goarch: - - mips64 - - mips64le - gomips: - - hardfloat - - softfloat - - main: ./main.go - id: speedtest-backend-noupx-windows-arm64 - binary: speedtest-backend - env: - - CGO_ENABLED=0 - flags: - - -trimpath - ldflags: - - -w -s - goos: - - windows - goarch: - - arm - - arm64 - goarm: - - 5 - - 6 - - 7 + +nfpms: + - homepage: https://freedom.nl + description: LibreSpeed-Go backend + maintainer: Freedom Internet DevOps + license: LGPL 3.0 + vendor: Freedom Internet + contents: + - src: scripts/defaults + dst: /etc/default/librespeed-go + - src: scripts/systemd/librespeed-go.service + dst: /usr/lib/systemd/system/librespeed-go.service + formats: + - deb + - rpm + dependencies: + - systemd + scripts: + postinstall: scripts/postinstall.sh + archives: - - format_overrides: - - goos: windows - format: zip - files: + - files: - README.md - LICENSE - settings.toml -checksum: - name_template: 'checksums.txt' -changelog: - skip: false - sort: asc -release: - github: - owner: librespeed - name: speedtest-go - disable: false diff --git a/go.sum b/go.sum index e9d2f88..21d26d3 100644 --- a/go.sum +++ b/go.sum @@ -68,6 +68,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/breml/rootcerts v0.2.1 h1:GZMVDXOs945764NFck0vtHSjktKYubOFM0kjf5HAuwc= github.com/breml/rootcerts v0.2.1/go.mod h1:24FDtzYMpqIeYC7QzaE8VPRQaFZU5TIUDlyk8qwjD88= +github.com/breml/rootcerts v0.2.2 h1:hkHEpbTdYaNvDoYeq+mwRvCeg/YTTl23DjQ1Tnj71Zs= +github.com/breml/rootcerts v0.2.2/go.mod h1:24FDtzYMpqIeYC7QzaE8VPRQaFZU5TIUDlyk8qwjD88= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= @@ -567,6 +569,8 @@ golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo= +golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/scripts/defaults b/scripts/defaults new file mode 100644 index 0000000..7780fac --- /dev/null +++ b/scripts/defaults @@ -0,0 +1,5 @@ +# Set the command-line arguments to pass to the server. +# Due to shell scaping, to pass backslashes for regexes, you need to double +# them (\\d for \d). If running under systemd, you need to double them again +# (\\\\d to mean \d), and escape newlines too. +ARGS="" \ No newline at end of file diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh new file mode 100644 index 0000000..5bc5a67 --- /dev/null +++ b/scripts/postinstall.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +systemctl daemon-reload +systemctl enable librespeed-go +systemctl start librespeed-go \ No newline at end of file diff --git a/scripts/systemd/librespeed-go.service b/scripts/systemd/librespeed-go.service new file mode 100644 index 0000000..5edb7d8 --- /dev/null +++ b/scripts/systemd/librespeed-go.service @@ -0,0 +1,13 @@ +[Unit] +Description=LibreSpeed-Go backend +Documentation=https://github.com/FreedomNetNL/speedtest-go + +[Service] +Restart=on-failure +DynamicUser=yes +User=librespeed +EnvironmentFile=/etc/default/librespeed-go +ExecStart=/usr/local/bin/librespeed-go $ARGS + +[Install] +WantedBy=multi-user.target \ No newline at end of file From c2c92dba1dc2ac6bb75fe87c44ffd6670e7ba3c4 Mon Sep 17 00:00:00 2001 From: Lucas van Beek Date: Wed, 2 Feb 2022 16:46:43 +0100 Subject: [PATCH 2/2] Implement CI --- .github/workflows/build.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a1c0c33 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,30 @@ +--- +name: build + +on: [push] + +jobs: + builds: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release --rm-dist ${{ !startsWith(github.ref, 'refs/tags/v') && '--snapshot' || '' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Store build + uses: actions/upload-artifact@v2 + with: + name: build + path: dist/* \ No newline at end of file