diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 0000000..900d5dd --- /dev/null +++ b/ci/Dockerfile @@ -0,0 +1,21 @@ +FROM rust:1.65.0-slim-bullseye + +LABEL maintainer="augustinas@status.im" +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 diff --git a/ci/Jenkinsfile.prs.linux b/ci/Jenkinsfile.prs.linux new file mode 100644 index 0000000..34ff07d --- /dev/null +++ b/ci/Jenkinsfile.prs.linux @@ -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() } + } +} diff --git a/ci/Jenkinsfile.prs.macos b/ci/Jenkinsfile.prs.macos new file mode 100644 index 0000000..2566e54 --- /dev/null +++ b/ci/Jenkinsfile.prs.macos @@ -0,0 +1,45 @@ +library 'status-jenkins-lib@v1.6.0' + +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() } + } +} diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 0000000..d58a2bb --- /dev/null +++ b/ci/README.md @@ -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. diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..7e7ffcf --- /dev/null +++ b/shell.nix @@ -0,0 +1,23 @@ +{ pkgs ? import { + 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 + ]; +}