Skip to content

Commit 8fdbfcb

Browse files
authored
Merge pull request #71 from asecurityteam/chore/docker-ci-migration
chore: migrate lint/test to docker-based tooling
2 parents 9fcf022 + cbc52f6 commit 8fdbfcb

11 files changed

Lines changed: 148 additions & 58 deletions

File tree

.github/workflows/golang.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,21 @@ jobs:
99
name: GoLang Basics
1010
steps:
1111
- name: Checkout
12-
uses: actions/checkout@v4
12+
uses: actions/checkout@v6
1313
with:
1414
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of Sonar scan
15-
- name: FS Permissions
16-
# workaround for permissions with contaner attempting to create directories
17-
run: chmod 777 -R "$(pwd)"
1815
- name: Dep
1916
run: make dep
2017
- name: Lint
2118
run: make lint
22-
- name: Coverage Setup
23-
# workaround for permissions with container attempting to create directory
24-
run: mkdir .coverage && chmod 777 .coverage
19+
- name: Coverage Setup
20+
run: mkdir -p .coverage/unit
2521
- name: Unit Tests
2622
run: make test
2723
- name: Integration Tests
2824
run: make integration
2925
- name: SonarQube Scan
30-
uses: SonarSource/sonarqube-scan-action@v5
26+
uses: SonarSource/sonarqube-scan-action@v7
3127
env:
3228
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3329
# run on PRs and once we merge to main, as we need baseline runs for main in Sonar

.golangci.yaml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
version: "2"
2+
run:
3+
build-tags:
4+
- integration
5+
issues-exit-code: 1
6+
tests: true
7+
timeout: 5m
8+
output:
9+
formats:
10+
text:
11+
path: stdout
12+
print-linter-name: true
13+
print-issued-lines: true
14+
linters:
15+
default: none
16+
enable:
17+
- depguard
18+
- errcheck
19+
- gochecknoinits
20+
- goconst
21+
- gocyclo
22+
- gosec
23+
- govet
24+
- ineffassign
25+
- misspell
26+
- nakedret
27+
- prealloc
28+
- revive
29+
- staticcheck
30+
- unconvert
31+
- unparam
32+
- unused
33+
settings:
34+
depguard:
35+
rules:
36+
main:
37+
deny:
38+
- pkg: github.com/davecgh/go-spew/spew
39+
desc: not allowed to use spew
40+
govet:
41+
enable:
42+
- shadow # Check for possible unintended shadowing of variables.
43+
misspell:
44+
locale: US
45+
prealloc:
46+
for-loops: true
47+
revive:
48+
rules:
49+
- name: package-comments
50+
disabled: true
51+
unparam:
52+
check-exported: false
53+
exclusions:
54+
generated: lax
55+
rules:
56+
- path: (.+)\.go$
57+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked
58+
- path: (.+)\.go$
59+
text: (possible misuse of unsafe.Pointer|should have signature)
60+
- path: (.+)\.go$
61+
text: ineffective break statement. Did you mean to break out of the outer loop
62+
- path: (.+)\.go$
63+
text: Use of unsafe calls should be audited
64+
- path: (.+)\.go$
65+
text: Subprocess launch(ed with variable|ing should be audited)
66+
- path: (.+)\.go$
67+
text: G104
68+
- path: (.+)\.go$
69+
text: (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
70+
- path: (.+)\.go$
71+
text: Potential file inclusion via variable
72+
paths:
73+
- third_party$
74+
- builtin$
75+
- examples$
76+
formatters:
77+
enable:
78+
- gofmt
79+
- goimports
80+
settings:
81+
gofmt:
82+
simplify: false
83+
exclusions:
84+
generated: lax
85+
paths:
86+
- third_party$
87+
- builtin$
88+
- examples$
89+

Dockerfile

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
1-
FROM golang:latest AS BUILDER
2-
COPY . .
3-
RUN CGO_ENABLED=0 GOOS=linux go build -a -o /opt/app main.go
1+
# syntax=docker/dockerfile:1
42

5-
##################################
3+
# Build a local Go toolchain image
4+
FROM golang:1.24 AS go
5+
USER root
6+
# Intentionally empty: this stage serves as a runnable Go toolchain container
67

7-
FROM alpine:latest as CERTS
8-
RUN apk --no-cache add tzdata zip ca-certificates
9-
WORKDIR /usr/share/zoneinfo
10-
# -0 means no compression. Needed because go's
11-
# tz loader doesn't handle compressed data.
12-
RUN zip -r -0 /zoneinfo.zip .
13-
14-
###################################
15-
16-
FROM scratch
17-
COPY --from=BUILDER /opt/app .
18-
# the timezone data:
19-
COPY --from=CERTS /zoneinfo.zip /
20-
# the tls certificates:
21-
COPY --from=CERTS /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
22-
23-
ENV ZONEINFO /zoneinfo.zip
24-
ENTRYPOINT ["app"]

Makefile

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
1+
.PHONY: docker-build-go docker-build-lint docker-build dep lint coverage test
2+
13
TAG := $(shell git rev-parse --short HEAD)
24
DIR := $(shell pwd -L)
3-
SDCLI_VERSION :=v1.5
4-
SDCLI=docker run --rm -v "$(DIR):$(DIR)" -w "$(DIR)" asecurityteam/sdcli:$(SDCLI_VERSION)
5-
6-
dep:
7-
$(SDCLI) go dep
8-
9-
lint:
10-
$(SDCLI) go lint
11-
12-
test:
13-
$(SDCLI) go test
14-
15-
integration:
16-
$(SDCLI) go integration
17-
18-
coverage:
19-
$(SDCLI) go coverage
5+
LOCAL_GO_IMAGE ?= serverfull-go
6+
LOCAL_LINT_IMAGE ?= serverfull-golangci-lint
7+
GODOCKER = docker run --rm -v "$(DIR):$(DIR)" -w "$(DIR)" $(LOCAL_GO_IMAGE)
8+
LINTDOCKER = docker run --rm -v "$(DIR):$(DIR)" -w "$(DIR)" $(LOCAL_LINT_IMAGE)
9+
10+
COVERAGE_DIR := .coverage
11+
UNIT_COVERAGE_DIR := $(COVERAGE_DIR)/unit
12+
UNIT_COVERAGE_FILE := $(UNIT_COVERAGE_DIR)/unit.cover.out
13+
14+
docker-build-go:
15+
docker build --target go -t $(LOCAL_GO_IMAGE) .
16+
17+
docker-build-lint:
18+
docker build --target lint -t $(LOCAL_LINT_IMAGE) -f linter.Dockerfile .
19+
20+
docker-build: docker-build-go docker-build-lint
21+
22+
dep: docker-build-go
23+
$(GODOCKER) go mod vendor
24+
25+
lint: docker-build-lint
26+
$(LINTDOCKER) golangci-lint run --config .golangci.yaml ./... -v
27+
28+
coverage-setup:
29+
mkdir -p $(UNIT_COVERAGE_DIR)
30+
touch $(UNIT_COVERAGE_FILE)
31+
32+
test: coverage-setup docker-build-go
33+
$(GODOCKER) go test -coverprofile=$(UNIT_COVERAGE_FILE) -v -race ./...
34+
35+
integration: ;
36+
37+
coverage: docker-build-go
38+
$(GODOCKER) go tool cover -func=$(UNIT_COVERAGE_FILE)
2039

2140
doc: ;
2241

invokeapi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"reflect"
1010
"strings"
@@ -103,7 +103,7 @@ func (h *Invoke) ServeHTTP(w http.ResponseWriter, r *http.Request) {
103103
fnType = invocationTypeRequestResponse // This is the default value in AWS.
104104
}
105105
ctx := r.Context()
106-
b, errRead := ioutil.ReadAll(r.Body)
106+
b, errRead := io.ReadAll(r.Body)
107107
if errRead != nil {
108108
w.WriteHeader(http.StatusBadRequest) // Matches JSON parsing errors for the body
109109
_ = json.NewEncoder(w).Encode(responseFromError(errRead))

linter.Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Build a local golangci-lint image
4+
FROM golangci/golangci-lint:v2.6 AS lint
5+
USER root
6+
# Intentionally empty: this stage serves as a runnable golangci-lint container
7+
8+

tests/doc.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build integration
2-
// +build integration
32

43
// Package tests is where integration tests for a project should be placed.
54
// Integration tests include any of those that require external resources.

tests/embedded_lambda_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build integration
2-
// +build integration
32

43
package tests
54

@@ -156,7 +155,7 @@ func convertStack(s []uintptr) []*messages.InvokeResponse_Error_StackFrame {
156155

157156
func formatFrame(inputFrame runtime.Frame) *messages.InvokeResponse_Error_StackFrame {
158157
path := inputFrame.File
159-
line := int32(inputFrame.Line)
158+
line := int32(inputFrame.Line) // nolint:gosec // G115: Line number is always non-negative
160159
label := inputFrame.Function
161160

162161
// Strip GOPATH from path by counting the number of seperators in label & path

tests/port_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build integration
2-
// +build integration
32

43
package tests
54

tests/router_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build integration
2-
// +build integration
32

43
package tests
54

0 commit comments

Comments
 (0)