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

chore: add dev debug build using delve #64

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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"
}
]
}
]
}
17 changes: 17 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
########## 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
bradleyjones marked this conversation as resolved.
Show resolved Hide resolved

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

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

# 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

.PHONY: 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 -l app=harbor-scanner-anchore

.PHONY: debug-run
debug-run:
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
bradleyjones marked this conversation as resolved.
Show resolved Hide resolved

.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
Loading