Skip to content

Commit

Permalink
Go 1.21, default.pgo, alpine + ubuntu-22.04/20.04 images (#469)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vadimalekseev authored Aug 14, 2023
1 parent a86de35 commit c5f2968
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 62 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
./file.d
.git
.idea
.vscode
30 changes: 22 additions & 8 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@ jobs:
permissions:
packages: write
contents: read

strategy:
fail-fast: false
matrix:
image:
- name: 'ubuntu:latest'
suffix: ''
- name: 'ubuntu:22.04'
suffix: '-ubuntu22.04'
- name: 'ubuntu:20.04'
suffix: '-ubuntu20.04'
- name: 'ubuntu:18.04'
suffix: '-ubuntu18.04'
- name: 'alpine'
suffix: '-alpine'
- name: 'scratch'
suffix: '-scratch'
steps:
- uses: actions/checkout@v3

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

- name: Set version
id: set-version
run: |
VERSION=${GITHUB_REF/refs\/tags\//}
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
- name: Build and push
id: docker-build
uses: docker/build-push-action@v4
with:
push: true
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.set-version.outputs.VERSION }}
file: ./build/package/Dockerfile
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ github.ref_name }}
APP_IMAGE=${{ matrix.image.name }}
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.ref_name }}${{ matrix.image.suffix }}
48 changes: 16 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,26 @@ concurrency:

jobs:
test:
runs-on: ${{ matrix.runner }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
flags: [ '' ]
go: [ '1.20' ]
arch: [ amd64 ]
runner: [ ubuntu-latest ]
include:
- arch: amd64
runner: ubuntu-latest
flags: -race
flags: [ '', '-race' ]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
go-version: '1.21'
cache: true

- name: Build
env:
GOARCH: ${{ matrix.arch }}
GOFLAGS: ${{ matrix.flags }}
run: go build ./...

- name: Test
env:
GOARCH: ${{ matrix.arch }}
GOFLAGS: ${{ matrix.flags }}
LOG_LEVEL: error
run: go test -coverprofile=profile.out -covermode=atomic -v -coverpkg=./... ./...
Expand All @@ -51,38 +40,32 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: coverage
path: profile.out
path: |
profile.out
profile_race.out
if-no-files-found: error
retention-days: 1

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

e2e_test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
flags: [ '' ]
go: [ '1.20' ]
arch: [ amd64 ]
runner: [ ubuntu-latest ]
include:
- arch: amd64
runner: ubuntu-latest
flags: -race
flags: [ '', '-race' ]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.21'
cache: true

- name: Run Kafka
Expand All @@ -93,7 +76,6 @@ jobs:

- name: E2E
env:
GOARCH: ${{ matrix.arch }}
GOFLAGS: ${{ matrix.flags }}
LOG_LEVEL: error
run: go test ./e2e -coverprofile=profile_e2e.out -covermode=atomic -tags=e2e_new -timeout=3m -coverpkg=./...
Expand All @@ -102,7 +84,9 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: coverage
path: profile_e2e.out
path: |
profile_e2e.out
profile_e2e_race.out
if-no-files-found: error
retention-days: 1

Expand All @@ -123,7 +107,7 @@ jobs:
- name: Send coverage
uses: codecov/codecov-action@v3
with:
files: profile.out, profile_e2e.out
files: profile.out, profile_race.out, profile_e2e.out, profile_e2e_race.out,

lint:
runs-on: ubuntu-latest
Expand All @@ -134,7 +118,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.21'
cache: true

- name: Lint
Expand All @@ -159,7 +143,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.21'
cache: true

- name: Generate doc
Expand All @@ -183,7 +167,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.21'
cache: true

- name: Download dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.21'
cache: true

- name: Run GoReleaser
Expand Down
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ UPSTREAM_BRANCH ?= origin/master
.PHONY: build
build:
echo "Building for amd64..."
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

.PHONY: build-for-current-system
build-for-current-system:
echo "Building for current architecture..."
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
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-X github.com/ozontech/file.d/buildinfo.Version=${VERSION}" -o file.d ./cmd/file.d

.PHONY: cover
cover:
Expand Down Expand Up @@ -43,14 +38,9 @@ bench-file:
gen-doc:
go run github.com/vitkovskii/insane-doc@v0.0.3

.PHONY: profile-file
profile-file:
go test -bench LightJsonReadPar ./plugin/input/file -v -count 1 -run -benchmem -benchtime 1x -cpuprofile cpu.pprof -memprofile mem.pprof -mutexprofile mutex.pprof

.PHONY: lint
lint:
# installation: https://golangci-lint.run/usage/install/#local-installation
golangci-lint run
go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run

.PHONY: mock
mock:
Expand Down
33 changes: 33 additions & 0 deletions build/package/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ARG APP_IMAGE=ubuntu:latest

# Build
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS build

ARG VERSION
ARG BUILD_TIME

WORKDIR /file.d

COPY go.mod go.sum ./

RUN go mod download

COPY . .

ENV CGO_ENABLED 0
ENV GOOS linux
ENV GOARCH amd64

RUN go build -trimpath \
-pgo default.pgo \
-ldflags "-X github.com/ozontech/file.d/buildinfo.Version=${VERSION}" \
-o file.d ./cmd/file.d

# Deploy
FROM $APP_IMAGE

WORKDIR /file.d

COPY --from=build /file.d/file.d /file.d/file.d

CMD [ "./file.d" ]
10 changes: 5 additions & 5 deletions Dockerfile → build/package/Dockerfile_dev
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Build
FROM --platform=$BUILDPLATFORM golang:1.20-alpine AS build
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS build

RUN apk update
RUN apk add git
ARG VERSION
ARG BUILD_TIME

WORKDIR /file.d

Expand All @@ -17,8 +17,8 @@ ENV GOOS linux
ENV GOARCH amd64

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

# Deploy
Expand Down
3 changes: 1 addition & 2 deletions buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package buildinfo

var (
Version string
BuildTime string
Version string
)
2 changes: 1 addition & 1 deletion cmd/file.d/file.d.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() {
kingpin.Version(buildinfo.Version)
kingpin.Parse()

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

setRuntimeSettings()
insaneJSON.DisableBeautifulErrors = true
Expand Down
Binary file added default.pgo
Binary file not shown.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/ozontech/file.d

go 1.20
go 1.21

toolchain go1.21.0

require (
github.com/ClickHouse/ch-go v0.58.0
Expand Down
Loading

0 comments on commit c5f2968

Please sign in to comment.