Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
-
name: Run GoReleaser
go-version-file: 'go.mod'

- name: Login to Docker Hub
uses: docker/login-action@v3

Check warning on line 23 in .github/workflows/release.yml

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.github/workflows/release.yml#L23

An action sourced from a third-party repository on GitHub is not pinned to a full length commit SHA. Pinning an action to a full length commit SHA is currently the only way to use an action as an immutable release.
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: 1.24
go-version-file: 'go.mod'

- name: Build
run: go build ./...
Expand All @@ -33,4 +33,4 @@ jobs:
chmod +x codacy-coverage-reporter.sh
./codacy-coverage-reporter.sh report --force-coverage-parser go -r coverage.out
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ dumps
.idea/
clickhouse-bulk
debug
check.py
check.py
/dist
54 changes: 50 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
version: 2

project_name: clickhouse-bulk

release:
Expand All @@ -8,12 +9,13 @@ release:

builds:
- binary: clickhouse-bulk
goos: &goos
goos:
- darwin
- windows
- linux
goarch: &goarch
goarch:
- amd64
- arm64
- 386
env:
- CGO_ENABLED=0
Expand All @@ -27,8 +29,52 @@ archives:
- name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format_overrides:
- goos: windows
format: zip
formats: ['zip']
files:
- config.sample.json
- README.md
- LICENSE

dockers:
- image_templates:
- "nikepan/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "nikepan/{{ .ProjectName }}:{{ .Version }}-amd64"
dockerfile: Dockerfile.goreleaser
use: buildx
goos: linux
goarch: amd64
extra_files:
- config.sample.json
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"

- image_templates:
- "nikepan/{{ .ProjectName }}:{{ .Tag }}-arm64"
- "nikepan/{{ .ProjectName }}:{{ .Version }}-arm64"
dockerfile: Dockerfile.goreleaser
use: buildx
goos: linux
goarch: arm64
extra_files:
- config.sample.json
build_flag_templates:
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"

docker_manifests:
- name_template: "nikepan/{{ .ProjectName }}:{{ .Tag }}"
image_templates:
- "nikepan/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "nikepan/{{ .ProjectName }}:{{ .Tag }}-arm64"

- name_template: "nikepan/{{ .ProjectName }}:latest"
image_templates:
- "nikepan/{{ .ProjectName }}:{{ .Version }}-amd64"
- "nikepan/{{ .ProjectName }}:{{ .Version }}-arm64"
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM golang:1.24 as builder
FROM golang:1.24 AS builder

ARG TARGETOS
ARG TARGETARCH
ARG GOPROXY
ENV GOOS=linux \
GOARCH=amd64 \
ENV GOOS=$TARGETOS \
GOARCH=$TARGETARCH \
CGO_ENABLED=0 \
GO111MODULE=on

Expand All @@ -22,4 +24,4 @@ RUN mkdir /app/dumps
COPY --from=builder /go/src/github.com/nikepan/clickhouse-bulk/config.sample.json .
COPY --from=builder /go/src/github.com/nikepan/clickhouse-bulk/clickhouse-bulk .
EXPOSE 8123
ENTRYPOINT ["./clickhouse-bulk", "-config=config.sample.json"]
ENTRYPOINT ["./clickhouse-bulk", "-config=config.sample.json"]
8 changes: 8 additions & 0 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM alpine:3
RUN apk add ca-certificates
WORKDIR /app
RUN mkdir /app/dumps
COPY config.sample.json .
COPY clickhouse-bulk .
EXPOSE 8123
ENTRYPOINT ["./clickhouse-bulk", "-config=config.sample.json"]
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

var version = "unknown"
var commit = "unknown"
var date = "unknown"

func main() {
Expand All @@ -19,10 +20,12 @@ func main() {
flag.Parse()

if flag.Arg(0) == "version" {
log.Printf("clickhouse-bulk ver. %+v (%+v)\n", version, date)
log.Printf("clickhouse-bulk v%s (commit: %s, built: %s)\n", version, commit, date)
return
}

log.Printf("Starting clickhouse-bulk v%s (commit: %s, built: %s)\n", version, commit, date)

cnf, err := ReadConfig(*configFile)
if err != nil {
log.Fatalf("ERROR: %+v\n", err)
Expand Down
6 changes: 5 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ type Status struct {

// NewServer - create server
func NewServer(listen string, collector *Collector, debug bool, logQueries bool) *Server {
return &Server{listen, collector, debug, logQueries, echo.New()}
e := echo.New()
e.HideBanner = true
e.HidePort = true
return &Server{listen, collector, debug, logQueries, e}
}

func (server *Server) writeHandler(c echo.Context) error {
Expand Down Expand Up @@ -176,6 +179,7 @@ func RunServer(cnf Config) {
dumper.Listen(sender, cnf.DumpCheckInterval)
}

log.Printf("Server starting on %s\n", cnf.Listen)
err := srv.Start(cnf)
if err != nil {
log.Printf("ListenAndServe: %+v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ func ReadConfig(configFile string) (Config, error) {
cnf.Clickhouse.Servers = strings.Split(serversList, ",")
}

log.Printf("use servers: %+v", strings.Join(cnf.Clickhouse.Servers, ", "))
log.Printf("Using servers: %+v", strings.Join(cnf.Clickhouse.Servers, ", "))
return cnf, nil
}
Loading