Skip to content

Commit 96ce66b

Browse files
committed
TUN-9016: update go to 1.24
## Summary Update several moving parts of cloudflared build system: * use goboring 1.24.2 in cfsetup * update linter and fix lint issues * update packages namely **quic-go and net** * install script for macos * update docker files to use go 1.24.1 * remove usage of cloudflare-go * pin golang linter Closes TUN-9016
1 parent e144eac commit 96ce66b

File tree

585 files changed

+23517
-21301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

585 files changed

+23517
-21301
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ build_cloudflared_macos: &build
5757
- '[ "${RUNNER_ARCH}" = "intel" ] && export TARGET_ARCH=amd64'
5858
- ARCH=$(uname -m)
5959
- echo ARCH=$ARCH - TARGET_ARCH=$TARGET_ARCH
60-
- ./.teamcity/mac/install-cloudflare-go.sh
61-
- export PATH="/tmp/go/bin:$PATH"
60+
- ./.teamcity/mac/install-go.sh
6261
- BUILD_SCRIPT=.teamcity/mac/build.sh
6362
- if [[ ! -x ${BUILD_SCRIPT} ]] ; then exit ; fi
6463
- set -euo pipefail

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ linters:
2727
- sloglint # Ensure consistent code style when using log/slog.
2828
- sqlclosecheck # Checks that sql.Rows, sql.Stmt, sqlx.NamedStmt, pgx.Query are closed.
2929
- staticcheck # It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary.
30-
- tenv # Tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17.
30+
- usetesting # Reports uses of functions with replacement inside the testing package.
3131
- testableexamples # Linter checks if examples are testable (have an expected output).
3232
- testifylint # Checks usage of github.com/stretchr/testify.
3333
- tparallel # Tparallel detects inappropriate usage of t.Parallel() method in your Go test codes.

.teamcity/mac/install-cloudflare-go.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ rm -rf $GOCACHE
77
export PATH="/tmp/go/bin:$PATH"
88
go version
99
which go
10-
go env
10+
go env

.teamcity/mac/install-go.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
rm -rf /tmp/go
2+
export GOCACHE=/tmp/gocache
3+
rm -rf $GOCACHE
4+
5+
brew install [email protected]
6+
7+
go version
8+
which go
9+
go env
10+

.teamcity/windows/component-test.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Write-Output "Running unit tests"
3232

3333
# Not testing with race detector because of https://github.com/golang/go/issues/61058
3434
# We already test it on other platforms
35-
& go test -failfast -mod=vendor ./...
35+
go test -failfast -v -mod=vendor ./...
3636
if ($LASTEXITCODE -ne 0) { throw "Failed unit tests" }
3737

3838
Write-Output "Running component tests"
@@ -44,4 +44,4 @@ if ($LASTEXITCODE -ne 0) {
4444
python component-tests/setup.py --type cleanup
4545
throw "Failed component tests"
4646
}
47-
python component-tests/setup.py --type cleanup
47+
python component-tests/setup.py --type cleanup

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# use a builder image for building cloudflare
22
ARG TARGET_GOOS
33
ARG TARGET_GOARCH
4-
FROM golang:1.22.10 as builder
4+
FROM golang:1.24.2 AS builder
55
ENV GO111MODULE=on \
66
CGO_ENABLED=0 \
77
TARGET_GOOS=${TARGET_GOOS} \
@@ -16,10 +16,8 @@ WORKDIR /go/src/github.com/cloudflare/cloudflared/
1616
# copy our sources into the builder image
1717
COPY . .
1818

19-
RUN .teamcity/install-cloudflare-go.sh
20-
2119
# compile cloudflared
22-
RUN PATH="/tmp/go/bin:$PATH" make cloudflared
20+
RUN make cloudflared
2321

2422
# use a distroless base image with glibc
2523
FROM gcr.io/distroless/base-debian12:nonroot

Dockerfile.amd64

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# use a builder image for building cloudflare
2-
FROM golang:1.22.10 as builder
2+
FROM golang:1.24.2 AS builder
33
ENV GO111MODULE=on \
44
CGO_ENABLED=0 \
55
# the CONTAINER_BUILD envvar is used set github.com/cloudflare/cloudflared/metrics.Runtime=virtual
@@ -11,10 +11,8 @@ WORKDIR /go/src/github.com/cloudflare/cloudflared/
1111
# copy our sources into the builder image
1212
COPY . .
1313

14-
RUN .teamcity/install-cloudflare-go.sh
15-
1614
# compile cloudflared
17-
RUN GOOS=linux GOARCH=amd64 PATH="/tmp/go/bin:$PATH" make cloudflared
15+
RUN GOOS=linux GOARCH=amd64 make cloudflared
1816

1917
# use a distroless base image with glibc
2018
FROM gcr.io/distroless/base-debian12:nonroot

Dockerfile.arm64

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# use a builder image for building cloudflare
2-
FROM golang:1.22.10 as builder
2+
FROM golang:1.24.2 AS builder
33
ENV GO111MODULE=on \
44
CGO_ENABLED=0 \
55
# the CONTAINER_BUILD envvar is used set github.com/cloudflare/cloudflared/metrics.Runtime=virtual
@@ -11,10 +11,8 @@ WORKDIR /go/src/github.com/cloudflare/cloudflared/
1111
# copy our sources into the builder image
1212
COPY . .
1313

14-
RUN .teamcity/install-cloudflare-go.sh
15-
1614
# compile cloudflared
17-
RUN GOOS=linux GOARCH=arm64 PATH="/tmp/go/bin:$PATH" make cloudflared
15+
RUN GOOS=linux GOARCH=arm64 make cloudflared
1816

1917
# use a distroless base image with glibc
2018
FROM gcr.io/distroless/base-debian12:nonroot-arm64

cfsetup.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pinned_go: &pinned_go go-boring=1.22.10-1
1+
pinned_go: &pinned_go go-boring=1.24.2-1
22

33
build_dir: &build_dir /cfsetup_build
44
default-flavor: bookworm
@@ -13,7 +13,7 @@ bullseye: &bullseye
1313
- rubygem-fpm
1414
- rpm
1515
- libffi-dev
16-
- golangci-lint
16+
- golangci-lint=1.64.8-2
1717
pre-cache: &build_pre_cache
1818
- export GOCACHE=/cfsetup_build/.cache/go-build
1919
- go install golang.org/x/tools/cmd/[email protected]

cmd/cloudflared/linux_service.go

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package main
44

55
import (
66
"fmt"
7+
"io"
78
"os"
89

910
"github.com/rs/zerolog"
@@ -15,7 +16,7 @@ import (
1516
"github.com/cloudflare/cloudflared/logger"
1617
)
1718

18-
func runApp(app *cli.App, graceShutdownC chan struct{}) {
19+
func runApp(app *cli.App, _ chan struct{}) {
1920
app.Commands = append(app.Commands, &cli.Command{
2021
Name: "service",
2122
Usage: "Manages the cloudflared system service",
@@ -35,7 +36,7 @@ func runApp(app *cli.App, graceShutdownC chan struct{}) {
3536
},
3637
},
3738
})
38-
app.Run(os.Args)
39+
_ = app.Run(os.Args)
3940
}
4041

4142
// The directory and files that are used by the service.
@@ -97,6 +98,7 @@ WantedBy=timers.target
9798
var sysvTemplate = ServiceTemplate{
9899
Path: "/etc/init.d/cloudflared",
99100
FileMode: 0755,
101+
// nolint: dupword
100102
Content: `#!/bin/sh
101103
# For RedHat and cousins:
102104
# chkconfig: 2345 99 01
@@ -184,13 +186,11 @@ exit 0
184186
`,
185187
}
186188

187-
var (
188-
noUpdateServiceFlag = &cli.BoolFlag{
189-
Name: "no-update-service",
190-
Usage: "Disable auto-update of the cloudflared linux service, which restarts the server to upgrade for new versions.",
191-
Value: false,
192-
}
193-
)
189+
var noUpdateServiceFlag = &cli.BoolFlag{
190+
Name: "no-update-service",
191+
Usage: "Disable auto-update of the cloudflared linux service, which restarts the server to upgrade for new versions.",
192+
Value: false,
193+
}
194194

195195
func isSystemd() bool {
196196
if _, err := os.Stat("/run/systemd/system"); err == nil {
@@ -430,3 +430,38 @@ func uninstallSysv(log *zerolog.Logger) error {
430430
}
431431
return nil
432432
}
433+
434+
func ensureConfigDirExists(configDir string) error {
435+
ok, err := config.FileExists(configDir)
436+
if !ok && err == nil {
437+
err = os.Mkdir(configDir, 0755)
438+
}
439+
return err
440+
}
441+
442+
func copyFile(src, dest string) error {
443+
srcFile, err := os.Open(src)
444+
if err != nil {
445+
return err
446+
}
447+
defer srcFile.Close()
448+
449+
destFile, err := os.Create(dest)
450+
if err != nil {
451+
return err
452+
}
453+
ok := false
454+
defer func() {
455+
destFile.Close()
456+
if !ok {
457+
_ = os.Remove(dest)
458+
}
459+
}()
460+
461+
if _, err := io.Copy(destFile, srcFile); err != nil {
462+
return err
463+
}
464+
465+
ok = true
466+
return nil
467+
}

0 commit comments

Comments
 (0)