Skip to content

Commit c5f2968

Browse files
Go 1.21, default.pgo, alpine + ubuntu-22.04/20.04 images (#469)
* Bump Go version * Add .dockerignore * Update CI * Update CI * Build images with matrix * Remove Set version step * Refactor Makefile * Remove BuildTime * Separate dev/github Dockerfiles * Build for many targets * Paste default.pgo
1 parent a86de35 commit c5f2968

File tree

12 files changed

+101
-62
lines changed

12 files changed

+101
-62
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
./file.d
2+
.git
3+
.idea
4+
.vscode

.github/workflows/cd.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@ jobs:
1010
permissions:
1111
packages: write
1212
contents: read
13-
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
image:
17+
- name: 'ubuntu:latest'
18+
suffix: ''
19+
- name: 'ubuntu:22.04'
20+
suffix: '-ubuntu22.04'
21+
- name: 'ubuntu:20.04'
22+
suffix: '-ubuntu20.04'
23+
- name: 'ubuntu:18.04'
24+
suffix: '-ubuntu18.04'
25+
- name: 'alpine'
26+
suffix: '-alpine'
27+
- name: 'scratch'
28+
suffix: '-scratch'
1429
steps:
1530
- uses: actions/checkout@v3
1631

@@ -24,15 +39,14 @@ jobs:
2439
username: ${{ github.actor }}
2540
password: ${{ secrets.GITHUB_TOKEN }}
2641

27-
- name: Set version
28-
id: set-version
29-
run: |
30-
VERSION=${GITHUB_REF/refs\/tags\//}
31-
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
32-
3342
- name: Build and push
3443
id: docker-build
3544
uses: docker/build-push-action@v4
3645
with:
3746
push: true
38-
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.set-version.outputs.VERSION }}
47+
file: ./build/package/Dockerfile
48+
platforms: linux/amd64,linux/arm64
49+
build-args: |
50+
VERSION=${{ github.ref_name }}
51+
APP_IMAGE=${{ matrix.image.name }}
52+
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.ref_name }}${{ matrix.image.suffix }}

.github/workflows/ci.yml

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,26 @@ concurrency:
1212

1313
jobs:
1414
test:
15-
runs-on: ${{ matrix.runner }}
15+
runs-on: ubuntu-latest
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
flags: [ '' ]
20-
go: [ '1.20' ]
21-
arch: [ amd64 ]
22-
runner: [ ubuntu-latest ]
23-
include:
24-
- arch: amd64
25-
runner: ubuntu-latest
26-
flags: -race
19+
flags: [ '', '-race' ]
2720
steps:
2821
- name: Checkout code
2922
uses: actions/checkout@v3
3023

3124
- name: Install Go
3225
uses: actions/setup-go@v4
3326
with:
34-
go-version: ${{ matrix.go }}
27+
go-version: '1.21'
3528
cache: true
3629

3730
- name: Build
38-
env:
39-
GOARCH: ${{ matrix.arch }}
40-
GOFLAGS: ${{ matrix.flags }}
4131
run: go build ./...
4232

4333
- name: Test
4434
env:
45-
GOARCH: ${{ matrix.arch }}
4635
GOFLAGS: ${{ matrix.flags }}
4736
LOG_LEVEL: error
4837
run: go test -coverprofile=profile.out -covermode=atomic -v -coverpkg=./... ./...
@@ -51,38 +40,32 @@ jobs:
5140
uses: actions/upload-artifact@v3
5241
with:
5342
name: coverage
54-
path: profile.out
43+
path: |
44+
profile.out
45+
profile_race.out
5546
if-no-files-found: error
5647
retention-days: 1
5748

5849
- name: Run benchmarks
5950
if: ${{ !contains(matrix.flags, '-race') }}
6051
env:
61-
GOARCH: ${{ matrix.arch }}
62-
GOFLAGS: ${{ matrix.flags }}
52+
LOG_LEVEL: error
6353
run: go test --timeout=15m --benchtime=3x --benchmem --bench="BenchmarkLightJsonReadPar" --run=$^ ./plugin/input/file/...
6454

6555
e2e_test:
6656
runs-on: ubuntu-latest
6757
strategy:
6858
fail-fast: false
6959
matrix:
70-
flags: [ '' ]
71-
go: [ '1.20' ]
72-
arch: [ amd64 ]
73-
runner: [ ubuntu-latest ]
74-
include:
75-
- arch: amd64
76-
runner: ubuntu-latest
77-
flags: -race
60+
flags: [ '', '-race' ]
7861
steps:
7962
- name: Checkout code
8063
uses: actions/checkout@v3
8164

8265
- name: Install Go
8366
uses: actions/setup-go@v4
8467
with:
85-
go-version: '1.20'
68+
go-version: '1.21'
8669
cache: true
8770

8871
- name: Run Kafka
@@ -93,7 +76,6 @@ jobs:
9376

9477
- name: E2E
9578
env:
96-
GOARCH: ${{ matrix.arch }}
9779
GOFLAGS: ${{ matrix.flags }}
9880
LOG_LEVEL: error
9981
run: go test ./e2e -coverprofile=profile_e2e.out -covermode=atomic -tags=e2e_new -timeout=3m -coverpkg=./...
@@ -102,7 +84,9 @@ jobs:
10284
uses: actions/upload-artifact@v3
10385
with:
10486
name: coverage
105-
path: profile_e2e.out
87+
path: |
88+
profile_e2e.out
89+
profile_e2e_race.out
10690
if-no-files-found: error
10791
retention-days: 1
10892

@@ -123,7 +107,7 @@ jobs:
123107
- name: Send coverage
124108
uses: codecov/codecov-action@v3
125109
with:
126-
files: profile.out, profile_e2e.out
110+
files: profile.out, profile_race.out, profile_e2e.out, profile_e2e_race.out,
127111

128112
lint:
129113
runs-on: ubuntu-latest
@@ -134,7 +118,7 @@ jobs:
134118
- name: Install Go
135119
uses: actions/setup-go@v4
136120
with:
137-
go-version: '1.20'
121+
go-version: '1.21'
138122
cache: true
139123

140124
- name: Lint
@@ -159,7 +143,7 @@ jobs:
159143
- name: Install Go
160144
uses: actions/setup-go@v4
161145
with:
162-
go-version: '1.20'
146+
go-version: '1.21'
163147
cache: true
164148

165149
- name: Generate doc
@@ -183,7 +167,7 @@ jobs:
183167
- name: Install Go
184168
uses: actions/setup-go@v4
185169
with:
186-
go-version: '1.20'
170+
go-version: '1.21'
187171
cache: true
188172

189173
- name: Download dependencies

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install Go
2121
uses: actions/setup-go@v4
2222
with:
23-
go-version: '1.20'
23+
go-version: '1.21'
2424
cache: true
2525

2626
- name: Run GoReleaser

Makefile

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ UPSTREAM_BRANCH ?= origin/master
55
.PHONY: build
66
build:
77
echo "Building for amd64..."
8-
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-X github.com/ozontech/file.d/buildinfo.Version=${VERSION} -X github.com/ozontech/file.d/buildinfo.BuildTime=${TIME}" -o file.d ./cmd/file.d
9-
10-
.PHONY: build-for-current-system
11-
build-for-current-system:
12-
echo "Building for current architecture..."
13-
go build -ldflags "-X github.com/ozontech/file.d/buildinfo.Version=${VERSION} -X github.com/ozontech/file.d/buildinfo.BuildTime=${TIME}" -v -o file.d ./cmd/file.d
8+
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-X github.com/ozontech/file.d/buildinfo.Version=${VERSION}" -o file.d ./cmd/file.d
149

1510
.PHONY: cover
1611
cover:
@@ -43,14 +38,9 @@ bench-file:
4338
gen-doc:
4439
go run github.com/vitkovskii/[email protected]
4540

46-
.PHONY: profile-file
47-
profile-file:
48-
go test -bench LightJsonReadPar ./plugin/input/file -v -count 1 -run -benchmem -benchtime 1x -cpuprofile cpu.pprof -memprofile mem.pprof -mutexprofile mutex.pprof
49-
5041
.PHONY: lint
5142
lint:
52-
# installation: https://golangci-lint.run/usage/install/#local-installation
53-
golangci-lint run
43+
go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run
5444

5545
.PHONY: mock
5646
mock:

build/package/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
ARG APP_IMAGE=ubuntu:latest
2+
3+
# Build
4+
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS build
5+
6+
ARG VERSION
7+
ARG BUILD_TIME
8+
9+
WORKDIR /file.d
10+
11+
COPY go.mod go.sum ./
12+
13+
RUN go mod download
14+
15+
COPY . .
16+
17+
ENV CGO_ENABLED 0
18+
ENV GOOS linux
19+
ENV GOARCH amd64
20+
21+
RUN go build -trimpath \
22+
-pgo default.pgo \
23+
-ldflags "-X github.com/ozontech/file.d/buildinfo.Version=${VERSION}" \
24+
-o file.d ./cmd/file.d
25+
26+
# Deploy
27+
FROM $APP_IMAGE
28+
29+
WORKDIR /file.d
30+
31+
COPY --from=build /file.d/file.d /file.d/file.d
32+
33+
CMD [ "./file.d" ]

Dockerfile renamed to build/package/Dockerfile_dev

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Build
2-
FROM --platform=$BUILDPLATFORM golang:1.20-alpine AS build
2+
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS build
33

4-
RUN apk update
5-
RUN apk add git
4+
ARG VERSION
5+
ARG BUILD_TIME
66

77
WORKDIR /file.d
88

@@ -17,8 +17,8 @@ ENV GOOS linux
1717
ENV GOARCH amd64
1818

1919
RUN go build -trimpath \
20-
-ldflags "-X github.com/ozontech/file.d/buildinfo.Version=$(git describe --abbrev=4 --dirty --always --tags) \
21-
-X github.com/ozontech/file.d/buildinfo.BuildTime=$(date '+%Y-%m-%d_%H:%M:%S')" \
20+
-pgo default.pgo \
21+
-ldflags "-X github.com/ozontech/file.d/buildinfo.Version=${VERSION}" \
2222
-o file.d ./cmd/file.d
2323

2424
# Deploy

buildinfo/buildinfo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package buildinfo
22

33
var (
4-
Version string
5-
BuildTime string
4+
Version string
65
)

cmd/file.d/file.d.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func main() {
7272
kingpin.Version(buildinfo.Version)
7373
kingpin.Parse()
7474

75-
logger.Infof("Hi! I'm file.d version=%s %s", buildinfo.Version, buildinfo.BuildTime)
75+
logger.Infof("Hi! I'm file.d version=%s %s", buildinfo.Version)
7676

7777
setRuntimeSettings()
7878
insaneJSON.DisableBeautifulErrors = true

default.pgo

32 KB
Binary file not shown.

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/ozontech/file.d
22

3-
go 1.20
3+
go 1.21
4+
5+
toolchain go1.21.0
46

57
require (
68
github.com/ClickHouse/ch-go v0.58.0

0 commit comments

Comments
 (0)