Skip to content

Commit 2347d4c

Browse files
authored
chore(cli): docker builds (#114)
* chore(cli): docker builds * add info cmd * fix ci-cli os * add push option * build release artifacts * test red ci * fix * disable cargo publish * tmp * fix * fix * add drone
1 parent f093c97 commit 2347d4c

File tree

21 files changed

+757
-451
lines changed

21 files changed

+757
-451
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/target/

.drone/drone.jsonnet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
local pipelines = import './pipelines.jsonnet';
2+
3+
(import 'pipelines/test.jsonnet')

.drone/drone.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
kind: pipeline
3+
name: make cli/test
4+
platform:
5+
arch: amd64
6+
os: linux
7+
steps:
8+
- commands:
9+
- make cli/test
10+
image: grafana/agent-build-image:1
11+
name: make cli/test
12+
trigger:
13+
event:
14+
- pull_request
15+
type: docker
16+
---
17+
kind: signature
18+
hmac: 4d1b6f4e26c9419cb25638d02d585eeb5c1c2b47b9c5775e377f36bf48f916c7
19+
20+
...

.drone/pipelines/test.jsonnet

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local build_image = import '../util/build_image.jsonnet';
2+
local pipelines = import '../util/pipelines.jsonnet';
3+
4+
[
5+
pipelines.linux('make cli/test') {
6+
trigger: {
7+
event: ['pull_request'],
8+
},
9+
steps: [{
10+
name: 'make cli/test',
11+
image: build_image.linux,
12+
commands: [
13+
'make cli/test',
14+
],
15+
}],
16+
},
17+
]

.drone/util/build_image.jsonnet

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
local version = std.extVar('BUILD_IMAGE_VERSION'),
3+
4+
linux: 'grafana/agent-build-image:%s' % version,
5+
6+
}

.drone/util/pipelines.jsonnet

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
linux(name):: {
3+
kind: 'pipeline',
4+
type: 'docker',
5+
name: name,
6+
platform: {
7+
os: 'linux',
8+
arch: 'amd64',
9+
},
10+
},
11+
}

.drone/util/secrets.jsonnet

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
local newSecret(name) = {
2+
kind: 'secret',
3+
name: name,
4+
5+
getFrom(path, name):: self {
6+
get: { path: path, name: name },
7+
},
8+
9+
fromSecret:: local secret = self; { from_secret: secret.name },
10+
};
11+
12+
{
13+
dockerconfigjson: newSecret('dockerconfigjson').getFrom(path='secret/data/common/gcr', name='.dockerconfigjson'),
14+
gcr_admin: newSecret('gcr_admin').getFrom(path='infra/data/ci/gcr-admin', name='.dockerconfigjson'),
15+
gh_token: newSecret('gh_token').getFrom(path='infra/data/ci/github/grafanabot', name='pat'),
16+
gpg_public_key: newSecret('gpg_public_key').getFrom(path='infra/data/ci/packages-publish/gpg', name='public-key'),
17+
gpg_private_key: newSecret('gpg_private_key').getFrom(path='infra/data/ci/packages-publish/gpg', name='private-key'),
18+
gpg_passphrase: newSecret('gpg_passphrase').getFrom(path='infra/data/ci/packages-publish/gpg', name='passphrase'),
19+
docker_login: newSecret('docker_login').getFrom(path='infra/data/ci/docker_hub', name='username'),
20+
docker_password: newSecret('docker_password').getFrom(path='infra/data/ci/docker_hub', name='password'),
21+
22+
asList:: [self[k] for k in std.sort(std.objectFields(self))],
23+
}

.github/workflows/ci-cli.yml

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,11 @@ on:
88

99

1010
jobs:
11-
build:
12-
name: ${{ matrix.os }} - ${{ matrix.target }}
13-
runs-on: ${{ matrix.os }}
14-
strategy:
15-
matrix:
16-
os: [ubuntu-latest, macos-latest]
17-
target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, x86_64-apple-darwin, aarch64-apple-darwin]
18-
exclude:
19-
- os: ubuntu-latest
20-
target: x86_64-apple-darwin
21-
- os: ubuntu-latest
22-
target: aarch64-apple-darwin
23-
- os: macos-latest
24-
target: x86_64-unknown-linux-gnu
25-
- os: macos-latest
26-
target: aarch64-unknown-linux-gnu
11+
build-linux:
12+
runs-on: ubuntu-22.04
2713
steps:
28-
- name: install libunwind (for pprof and pyspy)
29-
if: matrix.os == 'ubuntu-latest'
30-
continue-on-error: true
31-
run: sudo apt install libunwind8-dev
32-
33-
- name: Checkout sources
34-
uses: actions/checkout@v3
14+
- uses: actions/checkout@v3
3515
with:
3616
submodules: recursive
37-
38-
- name: Install stable toolchain
39-
uses: omarabid-forks/rs-toolchain@v1
40-
with:
41-
profile: minimal
42-
toolchain: stable
43-
override: true
44-
45-
- name: Cargo build for pyroscope-cli
46-
uses: omarabid-forks/rs-cargo@v1
47-
with:
48-
args: --manifest-path pyroscope_cli/Cargo.toml
49-
command: build
50-
51-
- name: Tests for pyroscope-cli
52-
uses: omarabid-forks/rs-cargo@v1
53-
with:
54-
args: --manifest-path pyroscope_cli/Cargo.toml
55-
command: test
17+
- name: test
18+
run: USE_CONTAINER=1 make cli/test

.github/workflows/publish.yml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ jobs:
2323
run: |
2424
cargo login ${{ secrets.CARGO_TOKEN }}
2525
cargo publish
26-
publish-cli:
27-
name: pyroscope-cli
28-
runs-on: ubuntu-latest
29-
if: "startsWith(github.event.release.tag_name, 'cli-')"
30-
steps:
31-
- uses: actions/checkout@v3
32-
with:
33-
submodules: recursive
34-
- uses: actions-rs/toolchain@v1
35-
with:
36-
toolchain: stable
37-
override: true
38-
- name: install libunwind (for pprof)
39-
run: sudo apt install libunwind8-dev
40-
- name: publish pyroscope crate
41-
continue-on-error: true
42-
run: |
43-
cargo login ${{ secrets.CARGO_TOKEN }}
44-
cargo publish --manifest-path pyroscope_cli/Cargo.toml
26+
# publish-cli:
27+
# name: pyroscope-cli
28+
# runs-on: ubuntu-latest
29+
# if: "startsWith(github.event.release.tag_name, 'cli-')"
30+
# steps:
31+
# - uses: actions/checkout@v3
32+
# with:
33+
# submodules: recursive
34+
# - uses: actions-rs/toolchain@v1
35+
# with:
36+
# toolchain: stable
37+
# override: true
38+
# - name: install libunwind (for pprof)
39+
# run: sudo apt install libunwind8-dev
40+
# - name: publish pyroscope crate
41+
# continue-on-error: true
42+
# run: |
43+
# cargo login ${{ secrets.CARGO_TOKEN }}
44+
# cargo publish --manifest-path pyroscope_cli/Cargo.toml
4545
publish-pprofrs:
4646
name: "Backend: pprofrs"
4747
runs-on: ubuntu-latest

.github/workflows/release.yml

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -34,96 +34,27 @@ jobs:
3434
cli-artifacts:
3535
name: pyroscope-cli - build aritifacts
3636
needs: cli-release
37-
runs-on: ${{ matrix.os }}
38-
env:
39-
# For some builds, we use cross to test on 32-bit and big-endian
40-
# systems.
41-
CARGO: cargo
42-
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
43-
TARGET_FLAGS: ""
44-
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
45-
TARGET_DIR: ./target
46-
# Emit backtraces on panics.
47-
RUST_BACKTRACE: 1
48-
strategy:
49-
matrix:
50-
build: [linux, linux-arm, macos]
51-
# todo build everything in docker, use 18.04, do not depend on gh runners
52-
include:
53-
- build: linux
54-
os: ubuntu-20.04
55-
rust: stable
56-
target: x86_64-unknown-linux-musl
57-
- build: linux-arm
58-
os: ubuntu-20.04
59-
rust: stable
60-
target: arm-unknown-linux-gnueabihf
61-
- build: macos
62-
os: macos-latest
63-
rust: stable
64-
target: x86_64-apple-darwin
37+
runs-on: ubunut-22.04
6538
steps:
66-
- name: Checkout repository
67-
uses: actions/checkout@v3
39+
- uses: actions/checkout@v3
6840
with:
6941
submodules: recursive
70-
71-
- name: Install packages (Ubuntu)
72-
if: matrix.os == 'ubuntu-18.04'
73-
run: |
74-
ci/ubuntu-install-packages
75-
76-
- name: Install packages (macOS)
77-
if: matrix.os == 'macos-latest'
78-
run: |
79-
ci/macos-install-packages
80-
81-
- name: Install Rust
82-
uses: actions-rs/toolchain@v1
42+
- uses: docker/login-action@v2
43+
name: Login to Docker Hub
8344
with:
84-
toolchain: ${{ matrix.rust }}
85-
profile: minimal
86-
override: true
87-
target: ${{ matrix.target }}
88-
89-
- name: Use Cross
90-
shell: bash
91-
run: |
92-
cargo install cross
93-
echo "CARGO=cross" >> $GITHUB_ENV
94-
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
95-
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
96-
97-
- name: Show command used for Cargo
98-
run: |
99-
echo "cargo command is: ${{ env.CARGO }}"
100-
echo "target flag is: ${{ env.TARGET_FLAGS }}"
101-
echo "target dir is: ${{ env.TARGET_DIR }}"
102-
103-
- name: Build release binary
104-
run: ${{ env.CARGO }} build --manifest-path pyroscope_cli/Cargo.toml --verbose --release ${{ env.TARGET_FLAGS }}
105-
106-
- name: Strip release binary (linux and macos)
107-
if: matrix.build == 'linux' || matrix.build == 'macos'
108-
run: strip "pyroscope_cli/target/${{ matrix.target }}/release/pyroscope-cli"
109-
110-
- name: Strip release binary (arm)
111-
if: matrix.build == 'linux-arm'
112-
run: |
113-
docker run --rm -v \
114-
"$PWD/target:/target:Z" \
115-
rustembedded/cross:arm-unknown-linux-gnueabihf \
116-
arm-linux-gnueabihf-strip \
117-
/target/arm-unknown-linux-gnueabihf/release/pyroscope-cli
45+
username: ${{ secrets.DOCKERHUB_USERNAME }}
46+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
47+
- run: DOCKER_EXTRA="--push" make cli/docker-image
48+
- run: DOCKER_EXTRA="--output=." make cli/docker-image
11849

11950
- name: Upload release archive
12051
uses: actions/[email protected]
12152
env:
12253
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12354
with:
12455
upload_url: ${{ needs.cli-release.outputs.upload_url }}
125-
asset_path: "pyroscope_cli/target/${{ matrix.target }}/release/pyroscope-cli"
126-
asset_name: "pyroscope-cli-${{ matrix.target }}"
56+
asset_path: "./pyroscope-cli"
57+
asset_name: "pyroscope-cli"
12758
asset_content_type: application/octet-stream
12859
pprofrs-release:
12960
name: pyroscope-pprofrs

0 commit comments

Comments
 (0)