Skip to content
Snippets Groups Projects
Commit fb85324b authored by Malte Bauch's avatar Malte Bauch
Browse files

Merge branch '19-add-a-debug-dockerfile' into 'develop'

Resolve "Add a debug dockerfile"

See merge request !21
parents 59678ee0 f0a0ca63
Branches
Tags
2 merge requests!30Move from develop to master as default branch,!21Resolve "Add a debug dockerfile"
Pipeline #145596 passed
.idea .git
ygot .gitlab
.cobra.yaml
.dockerignore
.gitlab-ci.yaml
CONTRIBUTING.md
README.md
ci
doc
artifacts
build-tools
models
...@@ -3,7 +3,7 @@ stages: ...@@ -3,7 +3,7 @@ stages:
variables: variables:
IMAGE_PATH: "${CI_REGISTRY_IMAGE}" IMAGE_PATH: "${CI_REGISTRY_IMAGE}"
.build: &build .build: &build
stage: build stage: build
...@@ -18,7 +18,7 @@ build-gnmi-target-ubuntu: ...@@ -18,7 +18,7 @@ build-gnmi-target-ubuntu:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- TAG=${CI_COMMIT_BRANCH//\//-} - TAG=${CI_COMMIT_BRANCH//\//-}
- IMAGE_NAME="$IMAGE_PATH/ubuntu" - IMAGE_NAME="$IMAGE_PATH/ubuntu"
- docker buildx build -t "$IMAGE_NAME:$TAG" -f Dockerfile --target "ubuntu" . - docker buildx build -t "$IMAGE_NAME:$TAG" -f target.Dockerfile --target "ubuntu" .
- docker push "$IMAGE_NAME:$TAG" - docker push "$IMAGE_NAME:$TAG"
<<: *build <<: *build
...@@ -27,6 +27,6 @@ build-gnmi-target-debian: ...@@ -27,6 +27,6 @@ build-gnmi-target-debian:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- TAG=${CI_COMMIT_BRANCH//\//-} - TAG=${CI_COMMIT_BRANCH//\//-}
- IMAGE_NAME="$IMAGE_PATH/debian" - IMAGE_NAME="$IMAGE_PATH/debian"
- docker buildx build -t "$IMAGE_NAME:$TAG" -f Dockerfile --target "debian" . - docker buildx build -t "$IMAGE_NAME:$TAG" -f target.Dockerfile --target "debian" .
- docker push "$IMAGE_NAME:$TAG" - docker push "$IMAGE_NAME:$TAG"
<<: *build <<: *build
ARG GOLANG_VERSION=1.18 ARG GOLANG_VERSION=1.20.3
ARG BUILDARGS
FROM ubuntu:22.04 FROM golang:$GOLANG_VERSION-buster as builder
RUN apt-get update && apt-get -y install golang-go WORKDIR /gnmi-target/
EXPOSE 7030
COPY . . COPY . .
ENTRYPOINT ["go", "run", "main.go"] RUN --mount=type=cache,target=/root/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build
RUN go install github.com/go-delve/delve/cmd/dlv@v1.20.2
RUN make build-debug
FROM ubuntu:22.04 as ubuntu
EXPOSE 7030
WORKDIR /debug/
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y iproute2
RUN apt-get install -y iputils-ping
COPY --from=builder /go/bin/dlv /debug/
COPY --from=builder /gnmi-target/artifacts/gnmi-target /debug/
CMD [ "/debug/dlv", "--listen=:4000", "--headless=true", "--log=true", "--accept-multiclient", "--api-version=2", "exec", "/debug/gnmi-target", "start" ]
...@@ -21,20 +21,23 @@ pre: ...@@ -21,20 +21,23 @@ pre:
install-tools: install-tools:
@echo Install development tooling @echo Install development tooling
mkdir -p $(GOSDN_PRG) mkdir -p $(GOSDN_PRG)
export GOBIN=$(GOSDN_PRG) && go install github.com/openconfig/ygot/generator@v0.18.1 &&\ export GOBIN=$(GOSDN_PRG) && go install github.com/openconfig/ygot/generator@v0.27.0 &&\
go install github.com/andresterba/go-ygot-generator-generator@v0.0.4 go install github.com/andresterba/go-ygot-generator-generator@v0.0.4
@echo Finished installing development tooling @echo Finished installing development tooling
build: pre build: pre
$(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/gnmi-target ./main.go $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/gnmi-target ./main.go
build-debug: pre
$(GOBUILD) -gcflags="all=-N -l" -o $(BUILD_ARTIFACTS_PATH)/gnmi-target ./main.go
generate-yang-models: install-tools generate-yang-models: install-tools
cd modeldata/gnmitargetygot &&\ cd modeldata/gnmitargetygot &&\
../../$(TOOLS_DIR)/go-ygot-generator-generator config.yaml gostructs.go &&\ ../../$(TOOLS_DIR)/go-ygot-generator-generator config.yaml gostructs.go &&\
go generate go generate
container: build container: build
docker buildx build --rm -t gnmi-target --load -f ./Dockerfile . docker buildx build --rm -t gnmi-target --load -f ./target.Dockerfile .
container-debug: container-debug:
docker buildx build --rm -t gnmi-target-debug --load -f ./Dockerfile.debug . docker buildx build --rm -t gnmi-target-debug --load -f ./Dockerfile.debug .
......
...@@ -41,7 +41,7 @@ build:image: ...@@ -41,7 +41,7 @@ build:image:
extends: .build_template extends: .build_template
stage: build stage: build
script: script:
- docker buildx build --platform linux/amd64,linux/arm64 -t $TAG -f Dockerfile --push . - docker buildx build --platform linux/amd64,linux/arm64 -t $TAG -f target.Dockerfile --push .
rules: rules:
- !reference [.default_rules_dev, rules] - !reference [.default_rules_dev, rules]
- !reference [.default_rules_prod, rules] - !reference [.default_rules_prod, rules]
......
# Debug
Running the target in an encapsulated environment is recommended.
## Debugging using Dockerfile.debug
A Dockerfile for debugging (`Dockerfile.debug`) is provided within the
repositories root.
### Usage:
The following assumes that VSCode is used.
1. Extend `launch.json`:
```
{
"version": "0.2.0",
"configurations": [
...
{
"name": "Go Containerized Debug",
"type": "go",
"request": "attach",
"mode": "remote",
"port": 4000,
"host": "127.0.0.1"
}
]
}
```
2. Build the debug container: `make container-debug`
3. Run the container: `docker run --rm --privileged -d -p 7030:7030 -p 4000:4000 gnmi-target-debug:latest`
4. Set breakpoints and attach to the running container by using the configuration added in step 1
ARG GOLANG_VERSION=1.18 ARG GOLANG_VERSION=1.20.3
ARG BUILDARGS
FROM golang:$GOLANG_VERSION-buster AS installer FROM golang:$GOLANG_VERSION-buster as builder
WORKDIR /gnmi-target/ WORKDIR /gnmi-target/
COPY go.* ./
RUN go mod download
FROM installer as builder
COPY . . COPY . .
RUN make build RUN --mount=type=cache,target=/root/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
make build
FROM ubuntu:22.04 as ubuntu FROM ubuntu:22.04 as ubuntu
RUN apt-get update && apt-get upgrade -y RUN apt-get update && apt-get upgrade -y
......
.git
.gitlab
.cobra.yaml
.dockerignore
.gitlab-ci.yaml
CONTRIBUTING.md
README.md
ci
doc
artifacts
build-tools
models
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment