Skip to content

Commit a6bf5d5

Browse files
authored
Add crash handler on debug images (#265)
* [FIX] adding step to build symbol * [FIX] crashpad final path
1 parent 74f7fcf commit a6bf5d5

File tree

12 files changed

+265
-17
lines changed

12 files changed

+265
-17
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM debian:bullseye-slim
2+
3+
LABEL author="Everton Haise Taques <everton.taques@encora.com>"
4+
LABEL maintainer="NS1 Labs"
5+
LABEL version="1.0.0"
6+
7+
ENV BUILD_DEPS "g++ cmake make git pkgconf jq python3-pip python3-setuptools ca-certificates libasan6 zip curl"
8+
9+
COPY ./entrypoint.sh /entrypoint.sh
10+
11+
RUN mkdir -p /pktvisor-src
12+
13+
WORKDIR /pktvisor-src
14+
15+
RUN apt-get update && \
16+
apt-get upgrade --yes --force-yes && \
17+
apt-get install --yes --force-yes --no-install-recommends ${BUILD_DEPS} && \
18+
pip3 install conan
19+
20+
RUN chmod +x /entrypoint.sh
21+
22+
ENTRYPOINT [ "/entrypoint.sh" ]
23+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Docker test action
2+
3+
Github Action to build, compact and publish pktvisor symbol to backtrace.io
4+
5+
6+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'docker'
2+
author: 'Everton Haise Taques <everton.taques@encora.com>'
3+
description: 'NS1 Labs'
4+
5+
inputs:
6+
context:
7+
description: "Docker build context"
8+
required: true
9+
default: "./"
10+
11+
symbol_url:
12+
description: "symbol url"
13+
required: true
14+
default: ""
15+
16+
file:
17+
description: "Dockerfile used to build the image"
18+
required: true
19+
default: "./Dockerfile"
20+
21+
runs:
22+
using: 'docker'
23+
image: 'Dockerfile'
24+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
#
3+
function validateParams() {
4+
echo "========================= Checking parameters ========================="
5+
[[ -z $INPUT_SYMBOL_URL ]] && echo "Backtrace symbol url is required" && exit 1 || echo "Backtrace symbol url present"
6+
}
7+
8+
function build() {
9+
echo "========================= Building pktvisor ========================="
10+
cp -rf /github/workspace/.git/ /pktvisor-src/.git/
11+
cp -rf /github/workspace/src/ /pktvisor-src/src/
12+
cp -rf /github/workspace/cmd/ /pktvisor-src/cmd/
13+
cp -rf /github/workspace/3rd/ /pktvisor-src/3rd/
14+
cp -rf /github/workspace/docker/ /pktvisor-src/docker/
15+
cp -rf /github/workspace/golang/ /pktvisor-src/golang/
16+
cp -rf /github/workspace/integration_tests/ /pktvisor-src/integration_tests/
17+
cp -rf /github/workspace/cmake/ /pktvisor-src/cmake/
18+
cp -rf /github/workspace/CMakeLists.txt /pktvisor-src/
19+
cp -rf /github/workspace/conanfile.txt /pktvisor-src/
20+
mkdir /tmp/build
21+
cd /tmp/build
22+
conan profile new --detect default && \
23+
conan profile update settings.compiler.libcxx=libstdc++11 default && \
24+
conan config set general.revisions_enabled=1
25+
PKG_CONFIG_PATH=/local/lib/pkgconfig cmake -DCMAKE_BUILD_TYPE=Debug -DASAN=ON /pktvisor-src && \
26+
make all -j 4
27+
}
28+
29+
function compact() {
30+
echo "========================= Compacting binary and copying ========================="
31+
cd /tmp/build
32+
zip pktvisord.zip /tmp/build/bin/pktvisord
33+
cp -rf /tmp/build/bin/pktvisord /github/workspace/
34+
cp -rf /tmp/build/bin/crashpad_handler /github/workspace/
35+
cp -rf /tmp/build/bin/pktvisor-reader /github/workspace/
36+
#version for pktvisor-cli
37+
cp -rf /pktvisor-src/golang/pkg/client/version.go /github/workspace/version.go
38+
}
39+
40+
function publish() {
41+
echo "========================= Publishing symbol to backtrace ========================="
42+
cd /tmp/build
43+
curl --data-binary @pktvisord.zip -H "Expect: gzip" "${INPUT_SYMBOL_URL}"
44+
}
45+
46+
validateParams
47+
build
48+
compact
49+
publish
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM golang:latest
2+
3+
LABEL author="Everton Haise Taques <everton.taques@encora.com>"
4+
LABEL maintainer="NS1 Labs"
5+
LABEL version="1.0.0"
6+
7+
COPY ./entrypoint.sh /entrypoint.sh
8+
9+
RUN chmod +x /entrypoint.sh
10+
11+
ENTRYPOINT [ "/entrypoint.sh" ]
12+

.github/actions/build-go/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Docker test action
2+
3+
Github Action to build pktvisor-cli
4+
5+
6+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'docker'
2+
author: 'Everton Haise Taques <everton.taques@encora.com>'
3+
description: 'NS1 Labs'
4+
5+
inputs:
6+
context:
7+
description: "Docker build context"
8+
required: true
9+
default: "./"
10+
11+
file:
12+
description: "Dockerfile used to build the image"
13+
required: true
14+
default: "./Dockerfile"
15+
16+
runs:
17+
using: 'docker'
18+
image: 'Dockerfile'
19+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
#
3+
function build() {
4+
echo "========================= Building pktvisor-cli ========================="
5+
cp -rf golang/ /src/
6+
# Copying this from previous build (cpp)
7+
cp -rf ./version.go /src/pkg/client/version.go
8+
cd /src
9+
go build -o pktvisor-cli cmd/pktvisor-cli/main.go
10+
}
11+
12+
function copy() {
13+
echo "========================= Copying binary ========================="
14+
cp -rf /src/pktvisor-cli /github/workspace/
15+
}
16+
17+
build
18+
copy

.github/workflows/debug_build.yml

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,46 @@
11
name: Debug Builds
22

33
on:
4-
workflow_dispatch:
54
push:
6-
branches:
7-
- develop
8-
- release
5+
branches: [ develop, master, release/**, crash_handler ]
96

107
jobs:
11-
package:
8+
build:
129
runs-on: ubuntu-latest
13-
1410
steps:
1511
- uses: actions/checkout@v2
1612

17-
- name: Create Build Environment
18-
run: cmake -E make_directory ${{github.workspace}}/build
13+
- name: Build pktvisord + push symbol to backtrace.io
14+
uses: ./.github/actions/build-cpp
15+
with:
16+
context: "."
17+
symbol_url: ${{secrets.SYMBOL_URL}}
18+
file: "./Dockerfile"
19+
20+
- name: Build pktvisor-cli
21+
uses: ./.github/actions/build-go
22+
with:
23+
context: "."
24+
file: "./Dockerfile"
1925

20-
- name: Get Conan
21-
uses: turtlebrowser/get-conan@v1.0
26+
- name: Debug artifacts
27+
run: ls -lha .
2228

23-
- name: Configure CMake to generate VERSION
24-
shell: bash
25-
working-directory: ${{github.workspace}}/build
26-
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=Debug
29+
- name: Upload artifacts
30+
uses: actions/upload-artifact@v3
31+
with:
32+
name: pktvisor-artifacts
33+
path: ./
34+
retention-days: 1
35+
36+
package:
37+
needs: build
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Download to workspace
41+
uses: actions/download-artifact@v2
42+
with:
43+
name: pktvisor-artifacts
2744

2845
- name: Get branch name
2946
shell: bash
@@ -45,7 +62,7 @@ jobs:
4562
echo "REF_TAG=latest-debug" >> $GITHUB_ENV
4663
4764
- name: Generate ref tag (develop)
48-
if: ${{ env.BRANCH_NAME == 'develop' }}
65+
if: ${{ env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'crash_handler' }}
4966
run: |
5067
echo "REF_TAG=latest-develop-debug" >> $GITHUB_ENV
5168
@@ -57,15 +74,25 @@ jobs:
5774
- name: Debug ref tag
5875
run: echo ${{ env.REF_TAG }}
5976

77+
- name: Replace secrets token
78+
run: |
79+
sed -i -e "s/CP_TOKEN/${{ secrets.CRASHPAD_TOKEN }}/g" docker/entry-cp.sh
80+
81+
- name: escape url
82+
run: |
83+
REPLACE=${{ secrets.CRASHPAD_URL }}
84+
ESCAPED_REPLACE=$(printf '%s\n' "$REPLACE" | sed -e 's/[\/&]/\\&/g')
85+
sed -i -e "s/CP_URL/$ESCAPED_REPLACE/g" docker/entry-cp.sh
86+
6087
- name: Login to Docker Hub
6188
uses: docker/login-action@v1
6289
with:
6390
username: ${{ secrets.DOCKERHUB_USERNAME }}
6491
password: ${{ secrets.DOCKERHUB_TOKEN }}
6592

66-
- name: Build + push - pktvisor debug
93+
- name: Build, push debug image + crashhandler
6794
env:
6895
IMAGE_NAME: ns1labs/pktvisor
6996
run: |
70-
docker build . --file docker/Dockerfile.debug --tag ${{ env.IMAGE_NAME }}:${{ env.REF_TAG }}
97+
docker build . --file docker/Dockerfile.crashhandler --tag ${{ env.IMAGE_NAME }}:${{ env.REF_TAG }}
7198
docker push -a ${{ env.IMAGE_NAME }}

docker/Dockerfile.crashhandler

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM debian:bullseye-slim
2+
3+
ENV RUNTIME_DEPS "curl ca-certificates libasan6 gdb"
4+
5+
RUN \
6+
apt-get update && \
7+
apt-get upgrade --yes --force-yes && \
8+
apt-get install --yes --force-yes --no-install-recommends ${RUNTIME_DEPS} && \
9+
rm -rf /var/lib/apt
10+
11+
# copy files
12+
COPY ./pktvisord /usr/local/sbin/pktvisord
13+
COPY ./crashpad_handler /usr/local/sbin/crashpad_handler
14+
COPY ./pktvisor-reader /usr/local/sbin/pktvisor-reader
15+
COPY ./pktvisor-cli /usr/local/bin/pktvisor-cli
16+
COPY ./docker/entry-cp.sh /entry-cp.sh
17+
18+
# permissions
19+
RUN chmod a+x /usr/local/sbin/pktvisord
20+
RUN chmod a+x /usr/local/sbin/crashpad_handler
21+
RUN chmod a+x /usr/local/sbin/pktvisor-reader
22+
RUN chmod a+x /usr/local/bin/pktvisor-cli
23+
RUN chmod a+x /entry-cp.sh
24+
25+
ENTRYPOINT [ "/entry-cp.sh" ]
26+

0 commit comments

Comments
 (0)