-
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.
lint and check, cleanup idiomatic go issues
- Loading branch information
1 parent
a4017b5
commit 879c9e2
Showing
33 changed files
with
386 additions
and
151 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,33 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile | ||
{ | ||
"name": "Existing Dockerfile", | ||
"build": { | ||
// Sets the run context to one level up instead of the .devcontainer folder. | ||
"context": "..", | ||
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. | ||
"dockerfile": "../Dockerfile" | ||
}, | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"golang.go" | ||
] | ||
} | ||
} | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Uncomment the next line to run commands after the container is created. | ||
// "postCreateCommand": "cat /etc/os-release", | ||
|
||
// Configure tool-specific properties. | ||
// "customizations": {}, | ||
|
||
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. | ||
// "remoteUser": "devcontainer" | ||
} |
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,11 @@ | ||
.idea | ||
*.sw* | ||
*.terraform | ||
*.terraform* | ||
/bin | ||
/scripts/runLocal | ||
sidecar.db* | ||
*.db* | ||
/sqlite | ||
/sqlite* | ||
go-sidecar |
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,20 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for more information: | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
# https://containers.dev/guide/dependabot | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "devcontainers" | ||
directory: "/" | ||
schedule: | ||
interval: weekly | ||
- package-ecosystem: "docker" | ||
directory: "/" | ||
schedule: | ||
interval: weekly | ||
- package-ecosystem: "go" | ||
directory: "/" | ||
schedule: | ||
interval: weekly |
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,7 +1,5 @@ | ||
name: build-container | ||
|
||
on: push | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-24.04 | ||
|
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ sidecar.db* | |
*.db* | ||
/sqlite | ||
/sqlite* | ||
go-sidecar |
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,6 @@ | ||
linters: | ||
enable: | ||
- govet | ||
- staticcheck | ||
- unused | ||
- errcheck |
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,106 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "install", | ||
"type": "shell", | ||
"command": "make deps/go", | ||
"options": { | ||
"cwd": "${workspaceFolder}", | ||
}, | ||
"group": { | ||
"kind": "build" | ||
} | ||
}, | ||
{ | ||
"label": "fmt", | ||
"type": "shell", | ||
"command": "gofmt -l .", | ||
"options": { | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
"dependsOn": "install", | ||
"group": { | ||
"kind": "build" | ||
} | ||
}, | ||
{ | ||
"label": "vet", | ||
"type": "shell", | ||
"command": "go vet ./...", | ||
"options": { | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
"dependsOn": "fmtcheck", | ||
"group": { | ||
"kind": "build" | ||
} | ||
}, | ||
{ | ||
"label": "lint", | ||
"type": "shell", | ||
"command": "golangci-lint run -c .golangci.yml", | ||
"options": { | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
"dependsOn": "vet", | ||
"group": { | ||
"kind": "build" | ||
} | ||
}, | ||
{ | ||
"label": "build", | ||
"type": "shell", | ||
"command": "go build ./...", | ||
"options": { | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
"dependsOn": "lint", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
}, | ||
{ | ||
"label": "clean", | ||
"type": "shell", | ||
"command": "go clean ./...", | ||
"options": { | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
"dependsOn": "build", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": false | ||
} | ||
}, | ||
{ | ||
"label": "test", | ||
"type": "shell", | ||
"command": "go test ./...", | ||
"options": { | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
"dependsOn": "lint", | ||
"group": { | ||
"kind": "test", | ||
"isDefault": true | ||
} | ||
}, | ||
{ | ||
"label": "staticcheck", | ||
"type": "shell", | ||
"command": "staticcheck ./...", | ||
"options": { | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
"dependsOn": "test", | ||
"group": { | ||
"kind": "test", | ||
"isDefault": false | ||
} | ||
}, | ||
] | ||
} |
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,21 +1,31 @@ | ||
FROM golang:1.22-bullseye as build | ||
FROM golang:1.22-bullseye AS build | ||
|
||
RUN apt-get update | ||
RUN apt-get install -y make postgresql-client | ||
|
||
RUN mkdir /build | ||
RUN useradd --create-home -s /bin/bash gobuild | ||
RUN usermod -a -G sudo gobuild | ||
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers | ||
|
||
COPY . /build | ||
|
||
WORKDIR /build | ||
ARG PROJECT=go-sidecar | ||
RUN mkdir -p /workspaces/${PROJECT} | ||
WORKDIR /workspaces/${PROJECT} | ||
COPY --chown=gobuild:gobuild . . | ||
|
||
# system and linux dependencies | ||
RUN make deps-linux | ||
RUN chown -R gobuild:gobuild /go | ||
|
||
# local dependencies | ||
ENV USER=gobuild | ||
ENV GOBIN=/go/bin | ||
ENV PATH=$PATH:${GOBIN} | ||
USER gobuild | ||
|
||
RUN make build | ||
RUN git config --global --add safe.directory /workspaces/${PROJECT} | ||
|
||
# FROM golang:1.22-bullseye as run | ||
# | ||
# RUN apt-get update | ||
# RUN apt-get install -y vim postgresql-client | ||
# | ||
# COPY --from=build /build/bin/cmd /bin | ||
RUN make yamlfmt | ||
RUN make fmtcheck | ||
RUN make vet | ||
RUN make lint | ||
RUN make test |
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,6 +1,11 @@ | ||
|
||
.PHONY: deps proto | ||
|
||
deps/dev: | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
go install honnef.co/go/tools/cmd/staticcheck@latest | ||
go install github.com/google/yamlfmt/cmd/yamlfmt@latest | ||
|
||
deps/go: | ||
go install google.golang.org/protobuf/cmd/[email protected] | ||
go install google.golang.org/grpc/cmd/[email protected] | ||
|
@@ -16,7 +21,7 @@ deps/go: | |
google.golang.org/grpc/cmd/protoc-gen-go-grpc | ||
go mod tidy | ||
|
||
deps-linux: deps/go | ||
deps-linux: deps/go deps/dev | ||
BIN="/usr/local/bin" VERSION="1.32.2" && \ | ||
curl -sSL "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" -o "${BIN}/buf" && \ | ||
chmod +x "${BIN}/buf" | ||
|
@@ -35,7 +40,7 @@ clean: | |
|
||
.PHONY: build/cmd/sidecar | ||
build/cmd/sidecar: | ||
go build -o bin/cmd/sidecar cmd/sidecar/main.go | ||
go build -ldflags="-s -w" -o bin/cmd/sidecar cmd/sidecar/main.go | ||
|
||
.PHONY: build | ||
build: build/cmd/sidecar | ||
|
@@ -46,9 +51,39 @@ docker-buildx-self: | |
docker-buildx: | ||
docker-buildx build --platform linux/amd64 --push -t 767397703211.dkr.ecr.us-east-1.amazonaws.com/go-sidecar:$(shell date +%s) -t 767397703211.dkr.ecr.us-east-1.amazonaws.com/go-sidecar:latest . | ||
|
||
.PHONY: yamlfmt | ||
yamlfmt: | ||
yamlfmt -lint .github/workflows/*.yml .github/*.yml | ||
|
||
.PHONY: fmt | ||
fmt: | ||
gofmt -l . | ||
|
||
|
||
.PHONY: fmtcheck | ||
fmtcheck: | ||
@unformatted_files=$$(gofmt -l .); \ | ||
if [ -n "$$unformatted_files" ]; then \ | ||
echo "The following files are not properly formatted:"; \ | ||
echo "$$unformatted_files"; \ | ||
echo "Please run 'gofmt -w .' to format them."; \ | ||
exit 1; \ | ||
fi | ||
.PHONY: vet | ||
vet: | ||
go vet ./... | ||
|
||
.PHONY: lint | ||
lint: | ||
golangci-lint run | ||
|
||
.PHONY: test | ||
test: | ||
TESTING=true go test -v -p 1 -parallel 1 ./... | ||
|
||
.PHONY: staticcheck | ||
staticcheck: | ||
staticcheck ./... | ||
|
||
.PHONY: ci-test | ||
ci-test: test | ||
ci-test: test lint vet fmtcheck yamlfmt |
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
Oops, something went wrong.