Add drone builds

This commit is contained in:
Jason Rhinelander 2021-10-08 21:33:19 -03:00 committed by Sean Darcy
parent 953b752100
commit c5624b6280
5 changed files with 185 additions and 61 deletions

134
.drone.jsonnet Normal file
View File

@ -0,0 +1,134 @@
local cargo = 'cargo --color=always --verbose ';
// Regular build on a rust docker image:
local rust_pipeline(
name,
image='rust:1-bullseye',
cargo_extra='--release',
tests=true,
deb=null, // set to distro name to make a deb
deb_revision_suffix='',
jobs=6,
arch='amd64'
) = {
kind: 'pipeline',
type: 'docker',
name: name,
platform: { arch: arch },
steps: [{
name: 'check',
image: image,
commands: [
'echo "Running on ${DRONE_STAGE_MACHINE}"',
cargo + 'check -j' + jobs + ' ' + cargo_extra,
],
}, {
name: 'build',
image: image,
commands: [cargo + 'build -j' + jobs + ' ' + cargo_extra],
}] + (if tests then [{
name: 'tests',
image: image,
commands: [cargo + 'test -j' + jobs + ' ' + cargo_extra],
}] else [])
+ (if deb != null then [{
name: 'deb',
image: image,
commands: [
cargo + 'install -j' + jobs + ' cargo-deb',
'sed -i -Ee \'s/^revision = "([^~]*)(~.*)?"$/revision = "\\\\\\\\1' + deb_revision_suffix + '"/\' Cargo.toml',
cargo + 'deb',
],
}] else []),
};
local apt_get_quiet = 'apt-get -o=Dpkg::Use-Pty=0 -q';
local default_apt_deps = 'pkg-config libssl-dev';
// Build on a stock debian/ubuntu distro
local debian_pipeline(
name,
image,
cargo_extra='--release',
apt_deps=default_apt_deps,
tests=true,
deb=null, // set to distro name to make a deb
deb_revision_suffix='',
jobs=6,
arch='amd64'
) = {
kind: 'pipeline',
type: 'docker',
name: name,
platform: { arch: arch },
steps: [{
name: 'build',
image: image,
environment: { SSH_KEY: { from_secret: 'SSH_KEY' } },
commands: [
'echo "Building on ${DRONE_STAGE_MACHINE}"',
'echo "man-db man-db/auto-update boolean false" | debconf-set-selections',
apt_get_quiet + ' update',
apt_get_quiet + ' install -y eatmydata',
'eatmydata ' + apt_get_quiet + ' dist-upgrade -y',
'eatmydata ' + apt_get_quiet + ' install -y cargo ' + apt_deps + (if deb != null then ' openssh-client' else ''),
cargo + 'build -j' + jobs + ' ' + cargo_extra,
]
+ (if tests then [cargo + 'test -j' + jobs + ' ' + cargo_extra] else [])
+ (if deb != null then [
cargo + 'install -j' + jobs + ' cargo-deb',
'sed -i -Ee \'s/^revision = "([^~]*)(~.*)?"$/revision = "\\\\\\\\1' + deb_revision_suffix + '"/\' Cargo.toml',
cargo + 'deb',
'./contrib/ci/drone-debs-upload.sh ' + deb,
] else []),
}],
};
[
{
name: 'lint check',
kind: 'pipeline',
type: 'docker',
platform: { arch: 'amd64' },
steps: [{
name: 'format',
image: 'rust:1-bullseye',
commands: [
'echo "Running on ${DRONE_STAGE_MACHINE}"',
'rustup component add rustfmt',
'cargo fmt -- --check --color=always',
],
}],
},
rust_pipeline('Rust latest/Release (amd64)'),
rust_pipeline('Rust latest/Debug (amd64)', cargo_extra=''),
rust_pipeline('Rust latest/Release (ARM64)', arch='arm64'),
// Various debian builds
debian_pipeline('Debian sid (amd64)', 'debian:sid', deb='sid', deb_revision_suffix=''),
debian_pipeline('Debian 11 (amd64)', 'debian:bullseye', deb='bullseye', deb_revision_suffix='~deb11'),
debian_pipeline('Debian 11 (ARM64)', 'debian:bullseye', arch='arm64', deb='bullseye', deb_revision_suffix='~deb11'),
debian_pipeline('Ubuntu 21.04 (amd64)', 'ubuntu:hirsute', deb='hirsute', deb_revision_suffix='~ubuntu2104'),
debian_pipeline('Ubuntu 20.04 (amd64)', 'ubuntu:focal', deb='focal', deb_revision_suffix='~ubuntu2004'),
debian_pipeline('Ubuntu 18.04 (amd64)', 'ubuntu:bionic', deb='bionic', deb_revision_suffix='~ubuntu1804'),
rust_pipeline('Debian 10 (amd64)', 'rust:1-buster', deb='buster', deb_revision_suffix='~deb10'),
// Macos build:
{
kind: 'pipeline',
type: 'exec',
name: 'MacOS/Release',
platform: { os: 'darwin', arch: 'amd64' },
steps: [
{
name: 'build',
commands: [
'echo "Building on ${DRONE_STAGE_MACHINE}"',
'cargo build -j6 --release',
'cargo test -j6 --release',
],
},
],
},
]

View File

@ -1,31 +0,0 @@
name: Check
on: [push, pull_request]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Prepare
run: |
openssl genpkey -algorithm x25519 -out x25519_private_key.pem
openssl pkey -in x25519_private_key.pem -pubout -out x25519_public_key.pem
- name: Check build
run: cargo check --verbose --release
- name: Run tests
run: cargo test --verbose
- name: Check formatting
run: cargo fmt -- --check

View File

@ -1,30 +0,0 @@
name: Build DEB (Ubuntu 20.04)
on: release
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build DEB
run: |
cargo install cargo-deb
cargo deb
- name: Upload DEB
uses: actions/upload-artifact@v2
with:
name: "ubuntu-20.04"
path: target/debian/*.deb

View File

@ -11,6 +11,7 @@ systemd-units = { enable = true, start = true }
maintainer-scripts = "debian/"
depends = "libssl1.1, openssl"
section = "net"
revision = "1"
[dependencies]
aes-gcm = "0.8"

50
contrib/ci/drone-debs-upload.sh Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
# Script used with Drone CI to upload debs from the deb building pipelines (because specifying all
# this in .drone.jsonnet is too painful). This is expected to run from the base project dir after
# having build with debuild (which will leave the debs in ..).
set -o errexit
distro="$1"
if [ -z "$distro" ]; then
echo "Bad usage: need distro name as first argument"
exit 1
fi
if [ -z "$SSH_KEY" ]; then
echo -e "\n\n\n\e[31;1mUnable to upload debs: SSH_KEY not set\e[0m"
# Just warn but don't fail, so that this doesn't trigger a build failure for untrusted builds
exit 0
fi
echo "$SSH_KEY" >~/ssh_key
set -o xtrace # Don't start tracing until *after* we write the ssh key
chmod 600 ~/ssh_key
upload_to="oxen.rocks/debs/${DRONE_REPO// /_}@${DRONE_BRANCH// /_}/$(date --date=@$DRONE_BUILD_CREATED +%Y%m%dT%H%M%SZ)-${DRONE_COMMIT:0:9}/$distro/$DRONE_STAGE_ARCH"
# sftp doesn't have any equivalent to mkdir -p, so we have to split the above up into a chain of
# -mkdir a/, -mkdir a/b/, -mkdir a/b/c/, ... commands. The leading `-` allows the command to fail
# without error.
upload_dirs=(${upload_to//\// })
mkdirs=
dir_tmp=""
for p in "${upload_dirs[@]}"; do
dir_tmp="$dir_tmp$p/"
mkdirs="$mkdirs
-mkdir $dir_tmp"
done
sftp -i ~/ssh_key -b - -o StrictHostKeyChecking=off drone@oxen.rocks <<SFTP
$mkdirs
put target/debian/*.*deb $upload_to
SFTP
set +o xtrace
echo -e "\n\n\n\n\e[32;1mUploaded debs to https://${upload_to}/\e[0m\n\n\n"