-
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.
* cleanup: CI checks, make lint * better makefile * added Dockerfile * cleanup * fix linter
- Loading branch information
Showing
10 changed files
with
142 additions
and
37 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,55 @@ | ||
name: Checks | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ^1.23 | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Run unit tests and generate the coverage report | ||
run: make test-race | ||
|
||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ^1.23 | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install gofumpt | ||
run: go install mvdan.cc/[email protected] | ||
|
||
- name: Install staticcheck | ||
run: go install honnef.co/go/tools/cmd/[email protected] | ||
|
||
- name: Install golangci-lint | ||
run: go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
|
||
- name: Lint | ||
run: make lint | ||
|
||
- name: Ensure go mod tidy runs without changes | ||
run: | | ||
go mod tidy | ||
git update-index -q --really-refresh | ||
git diff-index HEAD |
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,3 +1,4 @@ | ||
/constellation/ | ||
/cvm-reverse-proxy | ||
/measurements.json | ||
/measurements.json | ||
/build/ |
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,65 +1,87 @@ | ||
# Heavily inspired by Lighthouse: https://github.com/sigp/lighthouse/blob/stable/Makefile | ||
# and Reth: https://github.com/paradigmxyz/reth/blob/main/Makefile | ||
.DEFAULT_GOAL := help | ||
|
||
VERSION := $(shell git describe --tags --always --dirty="-dev") | ||
|
||
.PHONY: all | ||
all: clean build-proxy-client build-proxy-server | ||
##@ Help | ||
|
||
.PHONY: help | ||
help: ## Display this help. | ||
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
||
.PHONY: v | ||
v: | ||
v: ## Show the version | ||
@echo "Version: ${VERSION}" | ||
|
||
##@ Build | ||
|
||
.PHONY: clean | ||
clean: | ||
clean: ## Clean the build directory | ||
rm -rf build/ | ||
|
||
.PHONY: build | ||
build: clean build-proxy-client build-proxy-server ## Build the proxy client and server | ||
|
||
.PHONY: build-proxy-client | ||
build-proxy-client: | ||
build-proxy-client: ## Build the proxy client | ||
@mkdir -p ./build | ||
go build -trimpath -ldflags "-X cvm-reverse-proxy/common.Version=${VERSION}" -v -o ./build/proxy-client cmd/proxy-client/main.go | ||
|
||
.PHONY: build-proxy-server | ||
build-proxy-server: | ||
build-proxy-server: ## Build the proxy server | ||
@mkdir -p ./build | ||
go build -trimpath -ldflags "-X cvm-reverse-proxy/common.Version=${VERSION}" -v -o ./build/proxy-server cmd/proxy-server/main.go | ||
|
||
##@ Test & Development | ||
|
||
.PHONY: test | ||
test: | ||
go test ./... | ||
test: ## Run tests | ||
go test ./cmd/... ./common/... ./proxy/... | ||
|
||
.PHONY: test-race | ||
test-race: | ||
go test -race ./... | ||
test-race: ## Run tests with race detector | ||
go test -race ./cmd/... ./common/... ./proxy/... | ||
|
||
.PHONY: lint | ||
lint: | ||
lint: ## Run linters | ||
gofmt -d -s cmd common proxy | ||
gofumpt -d -extra cmd common proxy | ||
go vet ./cmd/... ./common/... ./proxy/... | ||
# staticcheck ./... // complains about 1.22.4 | ||
golangci-lint run --exclude-dirs internal | ||
# nilaway ./cmd/... ./common/... ./proxy/... // incorrect findings | ||
staticcheck ./cmd/... ./common/... ./proxy/... | ||
# golangci-lint run --exclude-dirs internal --exclude-dirs-use-default=false | ||
|
||
.PHONY: fmt | ||
fmt: | ||
fmt: ## Format the code | ||
gofmt -s -w cmd common proxy | ||
gci write cmd common proxy | ||
gofumpt -w -extra cmd common proxy | ||
go mod tidy | ||
|
||
.PHONY: gofumpt | ||
gofumpt: | ||
gofumpt: ## Run gofumpt | ||
gofumpt -l -w -extra cmd common proxy | ||
|
||
.PHONY: lt | ||
.PHONY: lt ## Alias for lint and test | ||
lt: lint test | ||
|
||
.PHONY: cover | ||
cover: | ||
cover: ## Run tests with coverage | ||
go test -coverprofile=/tmp/go-sim-lb.cover.tmp ./... | ||
go tool cover -func /tmp/go-sim-lb.cover.tmp | ||
unlink /tmp/go-sim-lb.cover.tmp | ||
|
||
.PHONY: cover-html | ||
cover-html: | ||
cover-html: ## Run tests with coverage and open the HTML report | ||
go test -coverprofile=/tmp/go-sim-lb.cover.tmp ./... | ||
go tool cover -html=/tmp/go-sim-lb.cover.tmp | ||
unlink /tmp/go-sim-lb.cover.tmp | ||
|
||
.PHONY: docker-images | ||
docker-images: ## Build the Docker images | ||
DOCKER_BUILDKIT=1 docker build \ | ||
--platform linux/amd64 \ | ||
--build-arg VERSION=${VERSION} \ | ||
--file proxy-server.dockerfile \ | ||
--tag cvm-proxy-server \ | ||
. |
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
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,3 +1,4 @@ | ||
// Package common contains shared utilities | ||
package common | ||
|
||
import ( | ||
|
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,23 @@ | ||
# syntax=docker/dockerfile:1 | ||
FROM golang:1.23 AS builder | ||
ARG VERSION | ||
WORKDIR /build | ||
ADD go.mod /build/ | ||
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 GOOS=linux \ | ||
go mod download | ||
ADD . /build/ | ||
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 GOOS=linux \ | ||
go build \ | ||
-trimpath \ | ||
-ldflags "-s -X main.version=${VERSION}" \ | ||
-v \ | ||
-o proxy-server \ | ||
cmd/proxy-server/main.go | ||
|
||
FROM alpine:latest | ||
WORKDIR /app | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=builder /build/proxy-server /app/proxy-server | ||
ENV LISTEN_ADDR=":8080" | ||
EXPOSE 8080 | ||
CMD ["/app/proxy-server"] |
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
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