From e5d2712b283c79632eb992afdb2f22d65002ce22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Franke?= Date: Wed, 20 Nov 2024 13:45:05 +0100 Subject: [PATCH] Add debug containers and related launch.json conf --- ...e.yaml => build-and-push-debug-image.yaml} | 22 ++++++++++++-- .github/workflows/build-and-push-image.yaml | 7 +++-- .vscode/launch.json | 30 +++++++++++++++++++ Dockerfile.debug | 21 +++++++++++++ Makefile | 6 ++++ .../dev-dataspace/docker-compose.yml | 10 ++++++- 6 files changed, 89 insertions(+), 7 deletions(-) rename .github/workflows/{build-and-push-snapshot-image.yaml => build-and-push-debug-image.yaml} (77%) create mode 100644 Dockerfile.debug diff --git a/.github/workflows/build-and-push-snapshot-image.yaml b/.github/workflows/build-and-push-debug-image.yaml similarity index 77% rename from .github/workflows/build-and-push-snapshot-image.yaml rename to .github/workflows/build-and-push-debug-image.yaml index 11a2968..e7d59c7 100644 --- a/.github/workflows/build-and-push-snapshot-image.yaml +++ b/.github/workflows/build-and-push-debug-image.yaml @@ -18,7 +18,10 @@ name: Create and publish a Docker image # Configures this workflow to run every time a change is pushed to the branch called `release`. on: push: + branches: + - main tags: + - v* - snapshot-* # Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. @@ -42,7 +45,7 @@ jobs: uses: actions/checkout@v4 # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -50,17 +53,30 @@ jobs: # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=false + prefix= + suffix=debug # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. - name: Build and push Docker image id: push - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + uses: docker/build-push-action@v6 with: context: . + file: Dockerfile.debug push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)." + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true diff --git a/.github/workflows/build-and-push-image.yaml b/.github/workflows/build-and-push-image.yaml index c7e9d81..55173af 100644 --- a/.github/workflows/build-and-push-image.yaml +++ b/.github/workflows/build-and-push-image.yaml @@ -22,6 +22,7 @@ on: - main tags: - v* + - snapshot-* # Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. env: @@ -44,7 +45,7 @@ jobs: uses: actions/checkout@v4 # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -52,7 +53,7 @@ jobs: # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. @@ -60,7 +61,7 @@ jobs: # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. - name: Build and push Docker image id: push - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + uses: docker/build-push-action@v6 with: context: . push: true diff --git a/.vscode/launch.json b/.vscode/launch.json index e7a1abf..837dd89 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -31,5 +31,35 @@ "server", ] } + { + "name": "Dev Dataspace: Attach to consumer", + "type": "go", + "debugAdapter": "dlv-dap", + "request": "attach", + "mode": "remote", + "port": 14000, + "host": "127.0.0.1", + "substitutePath": [ + { + "from": "${workspaceFolder}", + "to": "/app" + }, + ] + }, + { + "name": "Dev Dataspace: Attach to provider", + "type": "go", + "debugAdapter": "dlv-dap", + "request": "attach", + "mode": "remote", + "port": 24000, + "host": "127.0.0.1", + "substitutePath": [ + { + "from": "${workspaceFolder}", + "to": "/app" + }, + ] + } ] } diff --git a/Dockerfile.debug b/Dockerfile.debug new file mode 100644 index 0000000..7b65714 --- /dev/null +++ b/Dockerfile.debug @@ -0,0 +1,21 @@ +# Copyright 2024 go-dataspace +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This creates an image that +FROM docker.io/library/golang:1.22.9 AS builder +WORKDIR /app +COPY . ./ +RUN make debug +RUN go install github.com/go-delve/delve/cmd/dlv@latest +ENTRYPOINT [ "/go/bin/dlv", "exec", "--listen=:4000", "--headless", "--log", "--accept-multiclient", "--continue", "./_build/run-dsp.debug" ] diff --git a/Makefile b/Makefile index b8d1f7d..fc87438 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,12 @@ build: go mod download CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-extldflags=-static" -o _build/$(BINARY_NAME) ./cmd/ +debug: + -mkdir _build + go mod download + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -gcflags=all="-N -l" -ldflags="-extldflags=-static" -o _build/$(BINARY_NAME).debug ./cmd/ + + test: go test -v ./... diff --git a/docs/development/dev-dataspace/docker-compose.yml b/docs/development/dev-dataspace/docker-compose.yml index bcb556b..b79aa1d 100644 --- a/docs/development/dev-dataspace/docker-compose.yml +++ b/docs/development/dev-dataspace/docker-compose.yml @@ -16,11 +16,13 @@ # insecure = true # authMD = "User1" # -version: '3.9' +name: run-dsp development dataspace + services: run-dsp-client: build: context: ../../../ + dockerfile: Dockerfile.debug command: server environment: - LOGLEVEL=debug @@ -31,17 +33,22 @@ services: - SERVER.CONTROL.INSECURE=true ports: - '18081:8081' + - '14000:4000' depends_on: - reference-provider run-dsp-provider: build: context: ../../../ + dockerfile: Dockerfile.debug command: server environment: - LOGLEVEL=debug - SERVER.PROVIDER.ADDRESS=reference-provider:9090 - SERVER.PROVIDER.INSECURE=true - SERVER.DSP.EXTERNALURL=http://run-dsp-provider:8080/ + ports: + - '28081:8081' + - '24000:4000' depends_on: - reference-provider reference-provider: @@ -52,4 +59,5 @@ services: - PROVIDER_INSECURE=true - EXTERNAL_URL=http://127.0.0.1:19091/ ports: + - '19090:9090' - '19091:9091'