-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated to go 1.18 and imrovements in CI/CD
- Loading branch information
Showing
31 changed files
with
339 additions
and
2,093 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- "**" | ||
push: | ||
branches: | ||
- "**" | ||
|
||
jobs: | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18 | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: GolangCI Lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.46.2 | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18 | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Build | ||
run: make build | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18 | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Test | ||
run: make cover | ||
|
||
- name: Coverage | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: cover | ||
path: ./cover.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
linters-settings: | ||
dupl: | ||
threshold: 100 | ||
gocyclo: | ||
min-complexity: 15 | ||
lll: | ||
line-length: 140 | ||
misspell: | ||
locale: US | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- deadcode | ||
- dupl | ||
- errcheck | ||
- gocyclo | ||
- gofmt | ||
- goimports | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- lll | ||
- misspell | ||
- nestif | ||
- staticcheck | ||
- typecheck | ||
- unused | ||
- varcheck | ||
# not compatible with go 1.18 yet | ||
# - bodyclose | ||
# - noctx | ||
# - structcheck | ||
|
||
run: | ||
timeout: 5m | ||
go: "1.18" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
project_name: services | ||
builds: | ||
- id: catalog | ||
main: ./cmd/catalog | ||
binary: catalog | ||
goos: | ||
- linux | ||
goarch: | ||
- arm64 | ||
- amd64 | ||
env: | ||
- CGO_ENABLED=0 | ||
- id: stock | ||
main: ./cmd/stock | ||
binary: stock | ||
goos: | ||
- linux | ||
goarch: | ||
- arm64 | ||
- amd64 | ||
env: | ||
- CGO_ENABLED=0 | ||
archives: | ||
- name_template: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
FROM golang:1.15-alpine3.12 AS builder | ||
FROM golang:1.18.3-alpine3.16 AS builder | ||
|
||
ARG SERVICE | ||
|
||
ENV WORKDIR /go/src/gotway | ||
RUN test -n "$SERVICE" || (echo "Build argument \"SERVICE\" not set" && false) | ||
ENV WORKDIR /go/src/services | ||
RUN mkdir -p ${WORKDIR} | ||
WORKDIR ${WORKDIR} | ||
|
||
RUN apk update && \ | ||
apk add --no-cache --update make bash git ca-certificates && \ | ||
update-ca-certificates | ||
|
||
COPY . . | ||
|
||
RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -o bin/app cmd/$SERVICE/*.go | ||
RUN make build-$SERVICE | ||
|
||
FROM alpine:3.12.0 | ||
FROM alpine:3.16.0 | ||
|
||
COPY --from=builder /go/src/gotway/bin/app /app | ||
COPY --from=builder /go/src/services/bin/app /app | ||
|
||
CMD [ "/app" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
ROOT := $(shell git rev-parse --show-toplevel) | ||
OS := $(shell uname -s | awk '{print tolower($$0)}') | ||
ARCH := amd64 | ||
VERSION := $(shell git describe --abbrev=0 --tags) | ||
LD_FLAGS := -X main.version=$(VERSION) -s -w | ||
SOURCE_FILES ?= ./internal/... ./pkg/... ./cmd/... | ||
|
||
export CGO_ENABLED := 0 | ||
export GO111MODULE := on | ||
export GOBIN := $(shell pwd)/bin | ||
|
||
.PHONY: all | ||
all: help | ||
|
||
.PHONY: help | ||
help: ### Show targets documentation | ||
ifeq ($(OS), linux) | ||
@grep -P '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \ | ||
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
else | ||
@awk -F ':.*###' '$$0 ~ FS {printf "%15s%s\n", $$1 ":", $$2}' \ | ||
$(MAKEFILE_LIST) | grep -v '@awk' | sort | ||
endif | ||
|
||
GOLANGCI_LINT := $(GOBIN)/golangci-lint | ||
GOLANGCI_LINT_VERSION := v1.46.2 | ||
golangci-lint: | ||
$(call go-install,github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)) | ||
|
||
GORELEASER := $(GOBIN)/goreleaser | ||
GORELEASER_VERSION := v1.9.2 | ||
goreleaser: | ||
$(call go-install,github.com/goreleaser/goreleaser@$(GORELEASER_VERSION)) | ||
|
||
.PHONY: generate | ||
generate: vendor ### Generate code | ||
@bash ./hack/hack.sh | ||
|
||
.PHONY: docker-redis | ||
docker-redis: ### Spin up docker redis | ||
@docker compose -f docker-compose.redis.yml up -d | ||
|
||
.PHONY: docker | ||
docker: ### Spin up docker services | ||
@docker compose -f docker-compose.redis.yml -f docker-compose.yml up -d | ||
|
||
.PHONY: clean | ||
clean: ### Clean build files | ||
@rm -rf ./bin | ||
@go clean | ||
|
||
.PHONY: build | ||
build: build-catalog build-stock ### Build all binaries | ||
|
||
.PHONY: build-% | ||
build-%: clean ### Build binary | ||
@go build -tags netgo -a -v -ldflags "${LD_FLAGS}" -o ./bin/app ./cmd/$*/*.go | ||
@chmod +x ./bin/* | ||
|
||
.PHONY: run-% | ||
run-%: lint ### Quick run | ||
@CGO_ENABLED=1 go run -race cmd/$*/*.go | ||
|
||
.PHONY: deps | ||
deps: ### Optimize dependencies | ||
@go mod tidy | ||
|
||
.PHONY: vendor | ||
vendor: ### Vendor dependencies | ||
@go mod vendor | ||
|
||
.PHONY: lint | ||
lint: golangci-lint ### Lint | ||
$(GOLANGCI_LINT) run | ||
|
||
.PHONY: release | ||
release: goreleaser ### Dry-run release | ||
$(GORELEASER) release --snapshot --rm-dist | ||
|
||
.PHONY: test-clean | ||
test-clean: ### Clean test cache | ||
@go clean -testcache ./... | ||
|
||
.PHONY: test | ||
test: ### Run tests | ||
@go test -v -coverprofile=cover.out -timeout 10s ./... | ||
|
||
.PHONY: cover | ||
cover: test ### Run tests and generate coverage | ||
@go tool cover -html=cover.out -o=cover.html | ||
|
||
# go-get-tool will 'go get' any package $2 and install it to $1. | ||
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
define go-install | ||
@[ -f $(1) ] || { \ | ||
go install $(1) ; \ | ||
} | ||
endef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.