Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting baseline and initial Circle/CI integration #81

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
db97d99
CircleCI Commit
jadudm Jan 9, 2025
d858c68
Trying to change the container
jadudm Jan 9, 2025
6c0fc8e
Attempting to set up env
jadudm Jan 9, 2025
2663da4
Removing &&
jadudm Jan 9, 2025
69cc862
Using shorthand syntax
jadudm Jan 9, 2025
a28d004
Multiline commands
jadudm Jan 9, 2025
d4e4e72
Trying a convenience image
jadudm Jan 9, 2025
b29c15e
Using sudo
jadudm Jan 9, 2025
5b9d517
jobs vs steps?
jadudm Jan 9, 2025
6e8c1de
Jobs run in parallel
jadudm Jan 9, 2025
f3eebfe
Not installing packages...
jadudm Jan 9, 2025
8c5e584
Building?
jadudm Jan 9, 2025
a168ddf
Can I lint first?
jadudm Jan 9, 2025
33a24a8
Wrong command
jadudm Jan 9, 2025
3142c09
Need libraries in linting
jadudm Jan 9, 2025
3eabddb
Reorg for linting
jadudm Jan 9, 2025
0d274be
YAML anchors...
jadudm Jan 9, 2025
90d7600
Linting?
jadudm Jan 9, 2025
f302b54
Fixed all linting errors
jadudm Jan 9, 2025
5c4b36f
Still trying to lint
jadudm Jan 9, 2025
6d9c514
Path/sudo fix
jadudm Jan 9, 2025
957df69
Timeout/verbose
jadudm Jan 9, 2025
c5882d0
More linting
jadudm Jan 10, 2025
df5c117
Linting
jadudm Jan 10, 2025
39ded64
Linting
jadudm Jan 10, 2025
9f2e999
Linting
jadudm Jan 10, 2025
ff05a53
Linting.
jadudm Jan 11, 2025
fe9f0b1
Linting.
jadudm Jan 11, 2025
70d6b9d
Linting
jadudm Jan 11, 2025
546bdbd
Linting
jadudm Jan 11, 2025
4dd3ce9
Fixing common jobs
jadudm Jan 11, 2025
8954f15
Splitting linter out
jadudm Jan 11, 2025
66e4513
Forgot we need to prep
jadudm Jan 11, 2025
6226645
Indentation
jadudm Jan 11, 2025
b547790
Indenting
jadudm Jan 11, 2025
1eb4f1e
Fixing ATOI conversion
jadudm Jan 11, 2025
baaa02a
Fixes (again) conversion
jadudm Jan 11, 2025
aab7024
Updating deps
jadudm Jan 11, 2025
65893c6
Fixing 1.N.P complaint
jadudm Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.yml
89 changes: 89 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/configuration-reference
version: 2.1

commands:
apt-packages:
description: Performs a common install in each job
steps:
- run:
name: "common apt packages"
command: |
sudo apt-get update
sudo apt-get -y install build-essential \
curl \
libpoppler-dev \
libpoppler-glib-dev \
poppler-utils \
software-properties-common \
tree \
wget
install-linter:
description: Installs the golangci linter
parameters:
linter-version:
default: 1.63.4
type: string
steps:
- run:
name: "install golangci-lint"
command: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v<< parameters.linter-version >>
install-go-utilities:
description: Installs the golang utilities
steps:
- run:
name: "install jsonnet"
command: |
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/tools/cmd/stringer@latest
go install github.com/google/go-jsonnet/cmd/jsonnet@latest
go install github.com/google/go-jsonnet/cmd/jsonnet-lint@latest
go install github.com/google/go-jsonnet/cmd/jsonnetfmt@latest
- run:
name: "install sqlc"
command: |
wget https://downloads.sqlc.dev/sqlc_1.27.0_linux_amd64.tar.gz
tar xvzf sqlc_1.27.0_linux_amd64.tar.gz
chmod 755 sqlc
sudo mv sqlc /bin/sqlc
prep-the-build:
description: Generates files required for the build
steps:
- run:
name: "generate sqlc models"
command: make generate
jobs:
lint:
docker:
- image: cimg/go:1.23.3
steps:
- checkout
- apt-packages
- install-go-utilities
- install-linter
- prep-the-build
- run:
name: "find the lint"
command: golangci-lint run -v
no_output_timeout: 5m

setup-and-build:
docker:
- image: cimg/go:1.23.3
steps:
# Checkout the code as the first step.
- checkout
- apt-packages
- install-go-utilities
- run: make build


# Orchestrate jobs using workflows
# See: https://circleci.com/docs/workflows/ & https://circleci.com/docs/configuration-reference/#workflows
workflows:
build-and-deploy:
jobs:
- lint
- setup-and-build:
requires: [ lint ]
80 changes: 80 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
linters:
enable-all: true
# Some things here we may want to leave disabled.
# Some we may want to enable, and then pay down as debt.
# Anything included here represented a more invasive set of changes to
# satisfy the linter than was desired during initial cleanup.
disable:
- canonicalheader
- contextcheck
- depguard
- err113
- errchkjson
- exhaustruct
- exportloopref
- forbidigo
- gochecknoglobals
- gocritic
- intrange
- ireturn
- musttag
- nilerr
- noctx
- paralleltest
- perfsprint
- tagalign
- tagliatelle
- tenv
- testifylint
- unconvert
- unparam
- varnamelen
- wastedassign
depguard:
# Rules to apply.
#
# Variables:
# - File Variables
# you can still use and exclamation mark ! in front of a variable to say not to use it.
# Example !$test will match any file that is not a go test file.
#
# `$all` - matches all go files
# `$test` - matches all go test files
#
# - Package Variables
#
# `$gostd` - matches all of go's standard library (Pulled from `GOROOT`)
#
# Default: Only allow $gostd in all files.
rules:
main:
list-mode: lax
# List of file globs that will match this list of settings to compare against.
# Default: $all
files:
- $all
# List of allowed packages.
allow:
- $gostd
- github.com/GSA-TTS/jemison/config
# Packages that are not allowed where the value is a suggestion.
deny:
- pkg: "github.com/sirupsen/logrus"
desc: not allowed
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package

run:
timeout: 5m
issues-exit-code: 2
concurrency: 4
allow-parallel-runners: true

output:
formats:
- format: json
path: stderr
- format: checkstyle
path: report.xml
- format: colored-line-number
show-stats: true
3 changes: 2 additions & 1 deletion Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ FROM jemison/dev

WORKDIR /app

ENTRYPOINT ["make", "build"]
ENTRYPOINT ["make"]
CMD ["build"]
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ RUN cp /root/go/bin/stringer /usr/local/go/bin/stringer

WORKDIR /golanglint
# binary will be $(go env GOPATH)/bin/golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/go/bin v1.62.0
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/go/bin v1.63.4


ENTRYPOINT ["tree /"]
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ clean:
rm -f cmd/*/service.exe

.PHONY: generate
generate:
generate: config
cd internal/postgres ; make generate
# cd internal/postgres/search_db ; make generate

.PHONY: config
config:
config: clean
cd config ; make all || exit 1

docker:
docker build -t jemison/dev -f Dockerfile.dev .
docker build -t jemison/build -f Dockerfile.build .

.PHONY: build
# lint
build: clean config generate
build: generate
echo "build migrate"
cd cmd/migrate ; make build
echo "build admin"
Expand All @@ -42,8 +40,14 @@ build: clean config generate
# cd cmd/validate ; make build
echo "build walk"
cd cmd/walk ; make build
echo "copy assets"
cd assets ; rm -rf static/assets ; unzip -qq static.zip

.PHONY: lint
lint: generate
golangci-lint run -v

.PHONY: containerlint
containerlint:
docker run -v ${PWD}:/app -t jemison/build lint

.PHONY: up
up: build
Expand Down Expand Up @@ -111,7 +115,3 @@ terraform: delete_all
docker_full_clean:
-docker stop $(docker ps -a -q)
-docker rm $(docker ps -a -q)

.PHONY: lint
lint:
-golangci-lint run -v
29 changes: 19 additions & 10 deletions cmd/admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
"github.com/GSA-TTS/jemison/internal/env"
"github.com/GSA-TTS/jemison/internal/queueing"
"github.com/gin-gonic/gin"

"go.uber.org/zap"
)

var ThisServiceName = "admin"

var ChQSHP = make(chan queueing.QSHP)

type FetchRequestInput struct {
Scheme string `json:"scheme" maxLength:"10" doc:"Resource scheme"`
Host string `json:"host" maxLength:"500" doc:"Host of resource"`
Path string `json:"path" maxLength:"1500" doc:"Path to resource"`
ApiKey string `json:"api-key"`
APIKey string `json:"api-key"`
}

// https://dev.to/kashifsoofi/rest-api-with-go-chi-and-inmemory-store-43ag
Expand All @@ -29,9 +29,12 @@ func FetchRequestHandler(c *gin.Context) {
if err := c.BindJSON(&fri); err != nil {
return
}
if fri.ApiKey == os.Getenv("API_KEY") || true {
zap.L().Debug("fetch enqueue", zap.String("host", fri.Host), zap.String("path", fri.Path))
//queueing.InsertFetch(fri.Scheme, fri.Host, fri.Path)

if fri.APIKey == os.Getenv("API_KEY") || true {
zap.L().Debug("fetch enqueue",
zap.String("host", fri.Host),
zap.String("path", fri.Path))

ChQSHP <- queueing.QSHP{
Queue: "fetch",
Scheme: fri.Scheme,
Expand All @@ -46,19 +49,22 @@ func FetchRequestHandler(c *gin.Context) {

func EntreeRequestHandler(c *gin.Context) {
var fri FetchRequestInput

full := c.Param("fullorone")
hallPass := c.Param("hallpass")

if err := c.BindJSON(&fri); err != nil {
return
}
if fri.ApiKey == os.Getenv("API_KEY") || true {

if fri.APIKey == os.Getenv("API_KEY") || true {
hallPassB := false
fullB := false

if hallPass == "pass" {
hallPassB = true
}

if full == "full" {
fullB = true
}
Expand Down Expand Up @@ -89,8 +95,8 @@ func PackRequestHandler(c *gin.Context) {
if err := c.BindJSON(&fri); err != nil {
return
}
if fri.ApiKey == os.Getenv("API_KEY") || true {

if fri.APIKey == os.Getenv("API_KEY") || true {
zap.L().Debug("pack enqueue",
zap.String("host", fri.Host))

Expand Down Expand Up @@ -118,10 +124,10 @@ func main() {
v1.PUT("/fetch", FetchRequestHandler)
v1.PUT("/entree/:fullorone/:hallpass", EntreeRequestHandler)
v1.PUT("/pack", PackRequestHandler)
// v1.GET("/jobs", JobCountHandler)
}

log.Println("environment initialized")

go queueing.Enqueue(ChQSHP)

// // Init a cache for the workers
Expand All @@ -130,6 +136,9 @@ func main() {
zap.L().Info("listening to the music of the spheres",
zap.String("port", env.Env.Port))
// Local and Cloud should both get this from the environment.
http.ListenAndServe(":"+env.Env.Port, engine)

//nolint:gosec
err := http.ListenAndServe(":"+env.Env.Port, engine)
if err != nil {
zap.Error(err)
}
}
19 changes: 0 additions & 19 deletions cmd/admin/queues.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
package main

import (
"os"

common "github.com/GSA-TTS/jemison/internal/common"
"github.com/GSA-TTS/jemison/internal/queueing"
"github.com/jackc/pgx/v5"
"github.com/riverqueue/river"
"github.com/riverqueue/river/riverdriver/riverpgxv5"
"go.uber.org/zap"
)

// GLOBAL TO THE APP
var insertClient *river.Client[pgx.Tx]

func InitializeQueues() {
queueing.InitializeRiverQueues()

// Insert-only client
_, pool, _ := common.CommonQueueInit()
ic, err := river.NewClient(riverpgxv5.New(pool), &river.Config{})
if err != nil {
zap.L().Error("could not establish insert-only client")
os.Exit(1)
}
insertClient = ic
}
Loading
Loading