Skip to content

Commit 8602f1d

Browse files
authored
feature/packaging (#72)
* update prometheus dashboard * add packaging workflow
1 parent cc4a50d commit 8602f1d

File tree

7 files changed

+3199
-183
lines changed

7 files changed

+3199
-183
lines changed

.github/workflows/build.yml

+216
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
name: Build
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- master
8+
- develop
9+
- release
10+
push:
11+
branches:
12+
- master
13+
- develop
14+
- release
15+
16+
env:
17+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
18+
BUILD_TYPE: Release
19+
20+
jobs:
21+
build:
22+
# The CMake configure and build commands are platform agnostic and should work equally
23+
# well on Windows or Mac. You can convert this to a matrix build if you need
24+
# cross-platform coverage.
25+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
26+
strategy:
27+
matrix:
28+
os: [ ubuntu-latest, macos-latest ]
29+
runs-on: ${{ matrix.os }}
30+
31+
steps:
32+
- uses: actions/checkout@v2
33+
34+
- name: Create Build Environment
35+
# Some projects don't allow in-source building, so create a separate build directory
36+
# We'll use this as our working directory for all subsequent commands
37+
run: cmake -E make_directory ${{github.workspace}}/build
38+
39+
- name: Get Conan
40+
# You may pin to the exact commit or the version.
41+
# uses: turtlebrowser/get-conan@4dc7e6dd45c8b1e02e909979d7cfc5ebba6ddbe2
42+
uses: turtlebrowser/[email protected]
43+
44+
- name: Conan profile and settings
45+
run: |
46+
conan profile new --detect default
47+
conan config set general.revisions_enabled=1
48+
49+
- name: Conan profile (linux-workaround)
50+
if: matrix.os == 'ubuntu-latest'
51+
run:
52+
conan profile update settings.compiler.libcxx=libstdc++11 default
53+
54+
- name: Conan install (osx-workaround)
55+
if: matrix.os == 'macos-latest'
56+
working-directory: ${{github.workspace}}/build
57+
run: |
58+
conan remote add ns1labs-conan https://ns1labs.jfrog.io/artifactory/api/conan/ns1labs-conan
59+
conan install --build=missing ..
60+
61+
- name: linux package install
62+
if: matrix.os == 'ubuntu-latest'
63+
run: |
64+
sudo apt-get update
65+
sudo apt-get install --yes --no-install-recommends golang ca-certificates jq
66+
67+
- name: Configure CMake
68+
# Use a bash shell so we can use the same syntax for environment variable
69+
# access regardless of the host operating system
70+
shell: bash
71+
working-directory: ${{github.workspace}}/build
72+
# Note the current convention is to use the -S and -B options here to specify source
73+
# and build directories, but this is only available with CMake 3.13 and higher.
74+
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
75+
run: PKG_CONFIG_PATH=${{github.workspace}}/local/lib/pkgconfig cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
76+
77+
- name: Build
78+
working-directory: ${{github.workspace}}/build
79+
shell: bash
80+
# Execute the build. You can specify a specific target with "--target <NAME>"
81+
run: cmake --build . --config $BUILD_TYPE -- -j 2
82+
83+
- name: Test
84+
working-directory: ${{github.workspace}}/build
85+
shell: bash
86+
# Execute tests defined by the CMake configuration.
87+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
88+
run: ctest -C $BUILD_TYPE
89+
90+
package:
91+
needs: build
92+
runs-on: ubuntu-latest
93+
# if this is a push into one of our main branches (rather than just a pull request), we will also package
94+
if: github.event_name != 'pull_request'
95+
96+
steps:
97+
- uses: actions/checkout@v2
98+
99+
- name: Create Build Environment
100+
run: cmake -E make_directory ${{github.workspace}}/build
101+
102+
- name: Configure CMake to generate VERSION
103+
shell: bash
104+
working-directory: ${{github.workspace}}/build
105+
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
106+
107+
- name: Get branch name
108+
shell: bash
109+
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
110+
111+
- name: Debug branch name
112+
run: echo ${{ env.BRANCH_NAME }}
113+
114+
- name: Get VERSION
115+
run: |
116+
echo "VERSION=`cat ${{github.workspace}}/build/VERSION`" >> $GITHUB_ENV
117+
118+
- name: Debug version
119+
run: echo ${{ env.VERSION }}
120+
121+
- name: Generate ref tag (master)
122+
if: ${{ env.BRANCH_NAME == 'master' }}
123+
run: |
124+
echo "REF_TAG=latest" >> $GITHUB_ENV
125+
echo "PRERELEASE=false" >> $GITHUB_ENV
126+
echo "DRAFT=true" >> $GITHUB_ENV
127+
128+
- name: Generate ref tag (develop)
129+
if: ${{ env.BRANCH_NAME == 'develop' }}
130+
run: |
131+
echo "REF_TAG=latest-develop" >> $GITHUB_ENV
132+
echo "PRERELEASE=true" >> $GITHUB_ENV
133+
echo "DRAFT=false" >> $GITHUB_ENV
134+
135+
- name: Generate ref tag (release candidate)
136+
if: ${{ env.BRANCH_NAME == 'release' }}
137+
run: |
138+
echo "REF_TAG=latest-rc" >> $GITHUB_ENV
139+
echo "PRERELEASE=true" >> $GITHUB_ENV
140+
echo "DRAFT=false" >> $GITHUB_ENV
141+
142+
- name: Debug ref tag
143+
run: echo ${{ env.REF_TAG }}
144+
145+
- name: Manage Github ref tags
146+
uses: actions/github-script@v3
147+
with:
148+
github-token: ${{ github.token }}
149+
# note deleteRef can't start with refs/, but create createRef does.
150+
script: |
151+
try {
152+
await github.git.deleteRef({
153+
owner: context.repo.owner,
154+
repo: context.repo.repo,
155+
ref: "tags/${{ env.REF_TAG }}",
156+
})
157+
} catch (e) {
158+
console.log("The tag doesn't exist yet: " + e)
159+
}
160+
await github.git.createRef({
161+
owner: context.repo.owner,
162+
repo: context.repo.repo,
163+
ref: "refs/tags/${{ env.REF_TAG }}",
164+
sha: context.sha
165+
})
166+
167+
- name: Login to Docker Hub
168+
uses: docker/login-action@v1
169+
with:
170+
username: ${{ secrets.DOCKERHUB_USERNAME }}
171+
password: ${{ secrets.DOCKERHUB_TOKEN }}
172+
173+
- name: Build + push VERSION - pktvisor
174+
env:
175+
IMAGE_NAME: ns1labs/pktvisor
176+
run: |
177+
docker build . --file docker/Dockerfile --tag ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
178+
docker push ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
179+
180+
- name: Tag + push docker image with ref tag (cached build) - pktvisor
181+
env:
182+
IMAGE_NAME: ns1labs/pktvisor
183+
run: |
184+
docker build . --file docker/Dockerfile --tag ${{ env.IMAGE_NAME }}:${{ env.REF_TAG }}
185+
docker push ${{ env.IMAGE_NAME }}:${{ env.REF_TAG }}
186+
187+
- name: Build + push VERSION - pktvisor-prom-write
188+
env:
189+
IMAGE_NAME: ns1labs/pktvisor-prom-write
190+
working-directory: ${{github.workspace}}/centralized_collection/prometheus/docker-grafana-agent
191+
run: |
192+
docker build . --file docker/Dockerfile --tag ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
193+
docker push ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
194+
195+
- name: Tag + push docker image with ref tag (cached build) - pktvisor-prom-write
196+
env:
197+
IMAGE_NAME: ns1labs/pktvisor-prom-write
198+
working-directory: ${{github.workspace}}/centralized_collection/prometheus/docker-grafana-agent
199+
run: |
200+
docker build . --file docker/Dockerfile --tag ${{ env.IMAGE_NAME }}:${{ env.REF_TAG }}
201+
docker push ${{ env.IMAGE_NAME }}:${{ env.REF_TAG }}
202+
203+
- name: Generate AppImage
204+
env:
205+
IMAGE_NAME: ns1labs/pktvisor
206+
working-directory: ${{github.workspace}}/appimage
207+
run: |
208+
DEV_IMAGE="${{ env.IMAGE_NAME }}:${{ env.VERSION }}" DEV_MODE=t make pktvisor-x86_64.AppImage
209+
mv pktvisor-x86_64.AppImage pktvisor-x86_64-${{ env.VERSION }}.AppImage
210+
211+
- name: Upload AppImage artifact
212+
uses: actions/upload-artifact@v2
213+
with:
214+
name: pktvisor-AppImage
215+
path: ${{github.workspace}}/appimage/pktvisor-x86_64-${{ env.VERSION }}.AppImage
216+

.github/workflows/cmake.yml

-86
This file was deleted.

CMakeLists.txt

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@ cmake_minimum_required(VERSION 3.13)
22

33
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
44

5-
# this is the source of truth for version, which will be written to config.h include file.
5+
# VERSION
6+
# this is the source of truth for semver version
67
project(visor VERSION 3.2.0)
8+
9+
# for main line release, this is empty
10+
# for development release, this is "-develop"
11+
# for release candidate, this is "-rc"
712
set(VISOR_PRERELEASE "-develop")
13+
14+
# these are computed
815
set(VISOR_VERSION_NUM "${PROJECT_VERSION}${VISOR_PRERELEASE}")
9-
set(VISOR_VERSION " pktvisor ${PROJECT_VERSION}${VISOR_PRERELEASE}")
16+
set(VISOR_VERSION "pktvisor ${PROJECT_VERSION}${VISOR_PRERELEASE}")
17+
18+
# used in CI
19+
file(WRITE ${CMAKE_BINARY_DIR}/VERSION ${VISOR_VERSION_NUM})
20+
######
1021

1122
set(CMAKE_CXX_STANDARD 17)
1223
set(CMAKE_CXX_STANDARD_REQUIRED ON)

appimage/pktvisor/AppRun

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
2-
set -x
32

43
# borrowed from appimage directly
54
SELF=$(readlink -f "$0")
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This app needs to be run from a terminal to function correctly. See the docs at https://github.com/ns1/pktvisor for more details.
1+
This app needs to be run from a terminal to function correctly. See the docs at https://github.com/ns1labs/pktvisor for more details.

centralized_collection/prometheus/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ the [Grafana Agent](https://github.com/grafana/agent) for collecting and sending
55
[remote write](https://prometheus.io/docs/operating/integrations/#remote-endpoints-and-storage), including cloud
66
providers.
77

8-
There is also a sample [Grafana dashboard](grafana-dashboard-prometheus.json).
8+
There is a sample [Grafana dashboard](grafana-dashboard-prometheus.json), which you can also find online in
9+
the [Grafana community dashboards](https://grafana.com/grafana/dashboards/14221) with ID 14221.
910

1011
Example:
1112

0 commit comments

Comments
 (0)