diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f87a6fc..b1c5c1a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,22 +9,27 @@ jobs: 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 + 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 }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 434491c..2e924e7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 ./... @@ -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 }} \ No newline at end of file + CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} diff --git a/.gitignore b/.gitignore index 626bca1..7397bb5 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,5 @@ dumps .idea/ clickhouse-bulk debug -check.py \ No newline at end of file +check.py +/dist diff --git a/.goreleaser.yml b/.goreleaser.yml index d7f761c..3c3e8cb 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,4 +1,5 @@ ---- +version: 2 + project_name: clickhouse-bulk release: @@ -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 @@ -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" diff --git a/Dockerfile b/Dockerfile index 09c85d2..f6ae1b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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"] \ No newline at end of file +ENTRYPOINT ["./clickhouse-bulk", "-config=config.sample.json"] diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser new file mode 100644 index 0000000..8131340 --- /dev/null +++ b/Dockerfile.goreleaser @@ -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"] diff --git a/main.go b/main.go index 62f5e88..df5b02e 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( ) var version = "unknown" +var commit = "unknown" var date = "unknown" func main() { @@ -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) diff --git a/server.go b/server.go index 64fcb0f..e2e71ce 100644 --- a/server.go +++ b/server.go @@ -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 { @@ -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) diff --git a/utils.go b/utils.go index 16fe828..e70d60b 100644 --- a/utils.go +++ b/utils.go @@ -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 }