Skip to content

Commit

Permalink
ci: Add Jenkins configuration and related files
Browse files Browse the repository at this point in the history
  • Loading branch information
bacv committed Dec 13, 2022
1 parent d6cc851 commit d3788a8
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM rust:1.65.0-slim-bullseye

LABEL maintainer="[email protected]"
LABEL source="https://github.com/logos-co/Overwatch"
LABEL description="Overwatch ci build image"

# Using backports for go 1.19
RUN echo 'deb http://deb.debian.org/debian bullseye-backports main' >> /etc/apt/sources.list

# Dependecies for publishing documentation and building waku-bindings.
RUN apt-get update && apt-get install -yq \
openssh-client git clang \
golang-src/bullseye-backports \
golang-doc/bullseye-backports \
golang/bullseye-backports

RUN rustup component add rustfmt clippy

# Jenkins user needs a specific UID/GID to work.
RUN groupadd -g 1001 jenkins \
&& useradd -u 1001 -g jenkins jenkins
46 changes: 46 additions & 0 deletions ci/Jenkinsfile.prs.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
pipeline {
agent {
dockerfile {
label 'linux'
dir 'ci'
}
}

environment {
GOPATH = '/tmp/go'
GOCACHE = '/tmp/'
}

options {
disableConcurrentBuilds()
buildDiscarder(logRotator(
numToKeepStr: '20',
daysToKeepStr: '30',
))
}

stages {
stage('Check') {
steps {
sh 'cargo check --all --all-features'
sh 'cargo fmt -- --check'
sh 'cargo clippy --all --all-features -- --deny warnings'
}
}

stage('Build') {
steps {
sh 'cargo build --all --all-features'
}
}

stage('Test') {
steps {
sh 'cargo test --all --all-features'
}
}
}
post {
cleanup { cleanWs() }
}
}
45 changes: 45 additions & 0 deletions ci/Jenkinsfile.prs.macos
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
library '[email protected]'

pipeline {
agent {
label 'macos && x86_64'
}

environment {
GOPATH = '/tmp/go'
GOCACHE = '/tmp/'
}

options {
disableConcurrentBuilds()
buildDiscarder(logRotator(
numToKeepStr: '20',
daysToKeepStr: '30',
))
}

stages {
stage('Check') {
steps { script {
nix.shell('cargo check --all --all-features')
nix.shell('cargo fmt -- --check')
nix.shell('cargo clippy --all --all-features -- --deny warnings')
} }
}

stage('Build') {
steps { script {
nix.shell('cargo build --all --all-features')
} }
}

stage('Test') {
steps { script {
nix.shell('cargo test --all --all-features')
} }
}
}
post {
cleanup { cleanWs() }
}
}
22 changes: 22 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Building `Overwatch` with Jenkins

This is a short introduction for developers on how to use `ci` folder to update build dependencies or to modify the build process.

## ci/Dockerfile (Docs, linux target)

Dockerfile is used when `Overwatch` documentation is being built and to lint/test/build for linux target. Official rust image is used with a predefined version. In addition, golang and cargo components are downloaded when the image is being built.
In general, this file should be used just for defining dependencies. Related steps and build commands for linux target should be defined in `ci/Jenkinsfile.prs.linux`.

## ci/Jenkinsfile.prs.linux

Two most important places in this file are `environment` and `stages`.
* `environment` - variables defined here will be accessible to every stage that runs on an image built from the `ci/Dockerfile`
* `stages` - used to group shell commands that are related to different steps and their layout reflects in the build job summary.

## ci/Jenkinsfile.prs.macos

Same as in `Jenkinsfile.prs.macos` the only difference is that instead of Docker image, macos is using `shell.nix` to build a shell with all dependencies. The steps defined here should be identical or similar to what's defined in linux file, just instead of running those commands straight in `sh`, use `nix.shell('command')` wrapper.

## shell.nix

Configuration file for the Nix package manager. It defines the build dependencies for `macos` target and can be used to manage and update the dependencies similarly to Dockerfile.
23 changes: 23 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ pkgs ? import <nixpkgs> {
builtins = [(import (fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/3389f23412877913b9d22a58dfb241684653d7e9.tar.gz";
sha256 = "sha256:0wgm7sk9fca38a50hrsqwz6q79z35gqgb9nw80xz7pfdr4jy9pf8";
}))];
overlays = [
(import (fetchGit {
url = "https://github.com/oxalica/rust-overlay.git";
rev = "fe185fac76e009b4bd543704a8c61077cf70155b";
}))
];
}
}:

pkgs.mkShell {
name = "overwatch-build-shell";

buildInputs = with pkgs; [
pkg-config
rust-bin.stable."1.65.0".default
go_1_19
];
}

0 comments on commit d3788a8

Please sign in to comment.