Skip to content

Commit

Permalink
chore: add dev debug build using delve
Browse files Browse the repository at this point in the history
Skaffold debug doesn't currently support go 1.21 so this is a workaround
until skaffold is updated.

Signed-off-by: Bradley Jones <[email protected]>
  • Loading branch information
bradleyjones committed Nov 1, 2023
1 parent d2288ec commit a6bb2b5
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "go",
"debugAdapter": "dlv-dap",
"request": "attach",
"mode": "remote",
"port": 2345,
"host": "localhost",
"substitutePath": [
{
"from": "${workspaceFolder}",
"to": "/go/src/github.com/anchore/harbor-scanner-adapter"
}
]
}
]
}
35 changes: 35 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
########## Builder ##########
FROM golang:1.21-alpine AS builder

# Install the latest version of Delve
RUN go install github.com/go-delve/delve/cmd/dlv@latest

# Copy local source
# COPY . /build
# WORKDIR /build

ENV APP_PATH=/go/src/github.com/anchore/harbor-scanner-adapter

RUN mkdir -p $APP_PATH
WORKDIR $APP_PATH
COPY . $APP_PATH

# # Build the binary
# RUN CGO_ENABLED=0 go build -gcflags="all=-N -l" -v ./cmd/anchore-adapter/
#
# ########## Runtime ##########
# FROM alpine:3.17
#
# WORKDIR /
#
# # Copy binaries from builder
# COPY --from=builder /build /
# COPY --from=builder /go/bin/dlv /
#
# RUN apk update && apk add --no-cache curl bash ca-certificates && update-ca-certificates

# Expose debugger
EXPOSE 2345

# Start Delve
CMD /go/bin/dlv --listen=:2345 --headless --accept-multiclient debug $APP_PATH/cmd/anchore-adapter/main.go
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ lint-fix: ## Auto-format all source code + run golangci lint fixers
build:
$(TEMPDIR)/goreleaser build --clean --snapshot

.PHONE: debug
debug: debug-build debug-run

.PHONY: debug-build
debug-build:
docker build -f Dockerfile-dev -t anchore/harbor-scanner-adapter:debug .

.PHONY: debug-stop
debug-stop:
kubectl delete $(shell kubectl get pods -o name | grep harbor-scanner-anchore)

.PHONY: debug-run
debug-run: debug-stop
kubectl apply -f ./k8s/harbor-adapter-anchore-debug.yaml
kubectl port-forward $(shell kubectl get pods -o name | grep harbor-scanner-anchore) 2345:2345 8080:8080

.PHONY: debug-logs
debug-logs:
kubectl logs -f $(shell kubectl get pods -o name | grep harbor-scanner-anchore)

.PHONY: test
test:
CGO_ENABLED=0 go test ./...
Expand Down
81 changes: 81 additions & 0 deletions k8s/harbor-adapter-anchore-debug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: harbor-scanner-anchore
labels:
app: harbor-scanner-anchore
spec:
selector:
matchLabels:
app: harbor-scanner-anchore
replicas: 1
template:
metadata:
labels:
app: harbor-scanner-anchore
spec:
containers:
- name: adapter
image: anchore/harbor-scanner-adapter:debug
imagePullPolicy: Never
env:
- name: SCANNER_ADAPTER_LISTEN_ADDR
value: ":8080"
- name: ANCHORE_ENDPOINT
value: "http://host.docker.internal:8228"
- name: ANCHORE_USERNAME
valueFrom:
secretKeyRef:
name: anchore-creds
key: username
- name: ANCHORE_PASSWORD
valueFrom:
secretKeyRef:
name: anchore-creds
key: password
- name: ANCHORE_CLIENT_TIMEOUT_SECONDS
value: "60"
- name: SCANNER_ADAPTER_FILTER_VENDOR_IGNORED
value: "true"
- name: SCANNER_ADAPTER_LOG_LEVEL
value: "debug"
- name: SCANNER_ADAPTER_REGISTRY_TLS_VERIFY
value: "false"
# To enable api authentication, uncomment this and set it to a good randomized value. Use that same value in the scanner config in Harbor UI with "Bearer" type
# - name: "SCANNER_ADAPTER_APIKEY"
# value: "apikey123"

# Uncomment below to enable https in api
# - name: SCANNER_ADAPTER_TLS_KEY_FILE
# value: "/certs/tls.key"
# - name: SCANNER_ADAPTER_TLS_CERT_FILE
# value: "/certs/tls.crt"

# volumeMounts:
# - name: certs
# mountPath: /certs
# ports:
# - containerPort: 8080
# volumes:
# - name: certs
# secret:
# secretName: adapter-certs
---
apiVersion: v1
kind: Service
metadata:
name: harbor-scanner-anchore-debug
spec:
selector:
app: harbor-scanner-anchore
type: LoadBalancer
ports:
- protocol: TCP
name: app
port: 8080
targetPort: 8080
- protocol: TCP
name: dlv
port: 2345
targetPort: 2345

0 comments on commit a6bb2b5

Please sign in to comment.