Skip to content

Commit

Permalink
feature(docker): new multi-staged docker build
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Malusev <[email protected]>
  • Loading branch information
CodeLieutenant committed Sep 9, 2024
1 parent c8a3c98 commit 201baf2
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 118 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
build:
name: Lint Test and Build
runs-on: ubuntu-latest
steps:
- name:
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Pull tags and refs
run: git fetch --prune --unshallow
- name: Check if version is updated
run: |
export ExpectedVersion=$(git describe --tags --abbrev=0)
export DefinedVersion=$(cat cmd/gemini/Version)
if [ "$ExpectedVersion" != "$DefinedVersion" ]; then
if [ "$ExpectedVersion" != "$DefinedVersion" ]; then
echo "Expect to have '$ExpectedVersion', but got '$DefinedVersion'"
exit 1
fi
- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: 1.20.4

go-version: '1.23'
- name: Linting
run: |
make check
run: make check
- name: Set up gotestfmt
uses: GoTestTools/gotestfmt-action@v2
with:
repo: gotestfmt
version: v2.2.0
- name: Unit Tests
run: |
go test -v -race ./...
run: make test
- name: Build
run: |
go build ./cmd/gemini/
run: make build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ cmd/gemini/dist/
.idea
.vscode
bin/
coverage.txt
41 changes: 35 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
run:
concurrency: 8
timeout: 10m
issues-exit-code: 1
tests: true
modules-download-mode: mod
allow-parallel-runners: true
go: '1.23'

output:
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
sort-results: true

issues:
max-same-issues: 1
max-issues-per-linter: 10
new: true
exclude:
- Error return value of `.*.Unlock` is not checked
- Error return value of `.*.Completed` is not checked
linters:
disable-all: true
enable:
- asasalint
- bidichk
- errcheck
- govet
- bodyclose
- ineffassign
- unused
- durationcheck
- goheader
- goimports
- misspell
- gofumpt
- gosimple
- staticcheck
- decorder
- lll
- errorlint
- gocritic
Expand All @@ -25,16 +48,22 @@ linters:
- tparallel
- typecheck
- unused
run:
deadline: 10m
modules-download-mode: readonly
- gomodguard
- gocyclo
- nilerr
- makezero
- wastedassign
- prealloc


linters-settings:
govet:
check-shadowing: true
settings:
shadow:
strict: true
enable-all: true
gocyclo:
min-complexity: 50
lll:
line-length: 180
goheader:
Expand Down Expand Up @@ -64,8 +93,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.'

gofumpt:
lang-version: "1.12"
extra-rules: true
goimports:
local-prefixes: github.com/scylladb/gemini
local-prefixes: github.com/scylladb/gemini
12 changes: 8 additions & 4 deletions cmd/gemini/.goreleaser.yml → .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version: 2

env:
- GO111MODULE=on
before:
Expand All @@ -16,14 +18,16 @@ archives:

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ .Tag }}-next"

blobs:
-
provider: s3
- provider: s3
bucket: downloads.scylladb.com
region: us-east-1
folder: "gemini/{{.Version}}"

changelog:
sort: asc
filters:
Expand All @@ -33,5 +37,5 @@ changelog:

dockers:
- image_templates:
- scylladb/hydra-loaders:gemini-{{ .Tag }}
- scylladb/hydra-loaders:gemini-latest
- scylladb/gemini:{{ .Tag }}
- scylladb/gemini:latest
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.23 AS builder

ENV GO111MODULE=on

WORKDIR /gemini

COPY . .

RUN apt-get update && apt-get install -y libc-dev build-essential \
&& make build

FROM busybox AS production

WORKDIR /gemini

COPY --from=builder /gemini/bin/gemini .

ENV PATH="/gemini:${PATH}"

ENTRYPOINT ["gemini"]
22 changes: 15 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
GOPACKAGES := $(shell go list ./...)
MAKEFILE_PATH := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

GO111MODULE := on
Expand All @@ -20,20 +19,18 @@ define dl_tgz
fi
endef

$(GOBIN)/golangci-lint: GOLANGCI_VERSION = 1.52.2
$(GOBIN)/golangci-lint: GOLANGCI_VERSION = 1.60.3
$(GOBIN)/golangci-lint: Makefile
$(call dl_tgz,golangci-lint,https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_VERSION)/golangci-lint-$(GOLANGCI_VERSION)-$(GOOS)-amd64.tar.gz)

.PHONY: check-golangci
check-golangci: $(GOBIN)/golangci-lint
@echo $(GOPACKAGES) | sed -e 's/github.com\/scylladb\/gemini/./g' | \
xargs $(GOBIN)/golangci-lint run --max-issues-per-linter=0 --max-same-issues=0
$(GOBIN)/golangci-lint run

# fix-golangci Automated fix for golangci-lint errors.
.PHONY: fix-golangci
fix-golangci: $(GOBIN)/golangci-lint
@echo $(GOPACKAGES) | sed -e 's/github.com\/scylladb\/gemini/./g' | \
xargs $(GOBIN)/golangci-lint run --fix
$(GOBIN)/golangci-lint run --fix

# check Run all static code analysis. (use make fix to attempt automatic fix)
.PHONY: check
Expand All @@ -45,4 +42,15 @@ fix: fix-golangci

.PHONY: test
test:
go test -v -race ./...
go test -covermode=atomic -race -coverprofile=coverage.txt -timeout 5m -json -v ./... 2>&1 | gotestfmt -showteststatus

.PHONY: build
build:
CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/gemini ./cmd/gemini

debug-build:
CGO_ENABLED=0 go build -gcflags "all=-N -l" -o bin/gemini ./cmd/gemini

.PHONY: build-docker
build-docker:
docker build --target production -t scylladb/gemini:latest --compress .
3 changes: 0 additions & 3 deletions cmd/gemini/Dockerfile

This file was deleted.

30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
module github.com/scylladb/gemini

go 1.21
go 1.23

require (
github.com/briandowns/spinner v1.23.0
github.com/briandowns/spinner v1.23.1
github.com/gocql/gocql v1.8.0
github.com/google/go-cmp v0.6.0
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed
github.com/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/client_golang v1.20.0
github.com/scylladb/go-set v1.0.2
github.com/scylladb/gocqlx/v2 v2.8.0
github.com/spf13/cobra v1.8.0
github.com/spf13/cobra v1.8.1
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8
golang.org/x/net v0.26.0
golang.org/x/sync v0.7.0
gonum.org/v1/gonum v0.15.0
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
golang.org/x/net v0.28.0
golang.org/x/sync v0.8.0
gonum.org/v1/gonum v0.15.1
gopkg.in/inf.v0 v0.9.1
)

Expand All @@ -28,18 +28,18 @@ require (
github.com/fatih/color v1.17.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.54.0 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/scylladb/go-reflectx v1.0.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)

replace github.com/gocql/gocql => github.com/scylladb/gocql v1.8.0
replace github.com/gocql/gocql => github.com/scylladb/gocql v1.14.3
Loading

0 comments on commit 201baf2

Please sign in to comment.