Skip to content

Commit

Permalink
simplified greenboot with implementation in rust
Browse files Browse the repository at this point in the history
the pr currently implements only greenboot health-check,
failing required script and missing required directory
will render health-check as failure whcih in turn will
trigger reboot until boot_counter reaches -1,
motd is implemented with
status as greedboot/redboot in figlet.
greenboot can work without config file as default values
are embedded in the script itself.

Signed-off-by: Sayan Paul <[email protected]>
  • Loading branch information
say-paul committed Apr 3, 2023
1 parent 0ed08a6 commit c836f58
Show file tree
Hide file tree
Showing 12 changed files with 442 additions and 215 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM fedora:latest

RUN bash -c "$(curl -fsSL "https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/common-redhat.sh")" -- "true" "vscode" "1000" "1000" "true"

RUN dnf install -y \
sudo git cargo rust rust-src git-core clippy rustfmt \
&& dnf clean all

USER vscode
28 changes: 28 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "greenboot-rs",
"build": {
"dockerfile": "Dockerfile"
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
"settings": {
"rust-analyzer.checkOnSave.command": "clippy"
},
"extensions": [
"mutantdino.resourcemonitor",
"matklad.rust-analyzer",
"serayuzgur.crates"
],
"hostRequirements": {
"memory": "4gb"
},
"remoteUser": "vscode",
"updateContentCommand": [
"cargo",
"build"
],
"waitFor": "onCreateCommand"
}
48 changes: 12 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
push:
branches:
- main
- greenboot-rs
pull_request:

name: Continuous integration
Expand All @@ -22,20 +22,18 @@ jobs:
skip: "./docs/Gemfile.lock,./docs/_config.yml,./.github,./.git,./greenboot.spec,./dist"

fmt:
name: Rustfmt
name: Cargo fmt
runs-on: ubuntu-latest
container: fedora:latest
steps:
- name: Install deps
run: |
dnf install -y cargo rustfmt
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
args: --check --all

clippy:
name: Clippy
Expand Down Expand Up @@ -67,7 +65,7 @@ jobs:
steps:
- name: Install deps
run: |
dnf install -y make gcc git cargo rust git clevis
dnf install -y make gcc git cargo rust git
- uses: actions/checkout@v3
with:
persist-credentials: false
Expand All @@ -91,30 +89,8 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
# This is primarily to ensure that changes to fdo_data.h are committed,
# which is critical for determining whether any stability changes were made
# during the PR review.
- name: Ensure building did not change any code
run: |
git diff --exit-code
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 'latest'
- name: Install commitlint dependencies
run: npm install commitlint
- uses: wagoid/commitlint-github-action@v5
env:
NODE_PATH: ${{ github.workspace }}/node_modules
with:
configFile: .github/commitlint.config.js
failOnWarnings: true
args: -- --test-threads=1


# manpages:
# name: Test man page generation
Expand All @@ -136,6 +112,6 @@ jobs:
# - name: Install devcontainer CLI
# run: npm install -g @vscode/dev-container-cli
# - name: Build devcontainer
# run: devcontainer build --image-name devcontainer-fdo-rs .
# run: devcontainer build --image-name greenboot-rs .
# - name: Test building in devcontainer
# run: docker run --rm -v `pwd`:/code:z --workdir /code --user root devcontainer-fdo-rs cargo build --verbose
# run: docker run --rm -v `pwd`:/code:z --workdir /code --user root greenboot-rs cargo build --verbose
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ nix = "0.25.0"
glob = "0.3.0"
serde = "1.0"
serde_json = "1.0"
thiserror = "1.0.38"
figlet-rs = "0.1.5"
21 changes: 0 additions & 21 deletions dist/systemd/system/greenboot-trigger.service

This file was deleted.

8 changes: 4 additions & 4 deletions dist/systemd/system/greenboot.service
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[Unit]
Description=Greenboot - TODO
After=multi-user.target
Description=greenboot Health Checks Runner
Before=boot-complete.target
OnFailureJobMode=fail

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/libexec/greenboot/greenboot check
Restart=no
ExecStart=/usr/libexec/greenboot/greenboot health-check

[Install]
RequiredBy=boot-complete.target
WantedBy=multi-user.target
4 changes: 4 additions & 0 deletions etc/greenboot/greenboot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Greenboot configuration file

## Generic
GREENBOOT_MAX_BOOT_ATTEMPTS=3
130 changes: 73 additions & 57 deletions greenboot.spec
Original file line number Diff line number Diff line change
Expand Up @@ -41,94 +41,108 @@ Requires: rpm-ostree
Requires: pam >= 1.4.0
# While not strictly necessary to generate the motd, the main use-case of this package is to display it on SSH login
Recommends: openssh
Provides: greenboot-auto-update-fallback
Obsoletes: greenboot-auto-update-fallback <= 0.12.0
Provides: greenboot-grub2
Obsoletes: greenboot-grub2 <= 0.12.0
Provides: greenboot-reboot
Obsoletes: greenboot-reboot <= 0.12.0
Provides: greenboot-status
Obsoletes: greenboot-status <= 0.12.0
Provides: greenboot-rpm-ostree-grub2
Obsoletes: greenboot-rpm-ostree-grub2 <= 0.12.0
# List of bundled crate in vendor tarball, generated with:
# cargo metadata --locked --format-version 1 | CRATE_NAME="greenboot" ./bundled-provides.jq
Provides: bundled(crate(ahash)) = 0.7.6
Provides: bundled(crate(aho-corasick)) = 0.7.19
Provides: bundled(crate(anyhow)) = 1.0.65
Provides: bundled(crate(async-trait)) = 0.1.57
Provides: bundled(crate(aho-corasick)) = 0.7.20
Provides: bundled(crate(anstream)) = 0.2.6
Provides: bundled(crate(anstyle)) = 0.3.5
Provides: bundled(crate(anstyle-parse)) = 0.1.1
Provides: bundled(crate(anstyle-wincon)) = 0.2.0
Provides: bundled(crate(anyhow)) = 1.0.70
Provides: bundled(crate(async-trait)) = 0.1.68
Provides: bundled(crate(atty)) = 0.2.14
Provides: bundled(crate(autocfg)) = 1.1.0
Provides: bundled(crate(base64)) = 0.13.0
Provides: bundled(crate(base64)) = 0.13.1
Provides: bundled(crate(bitflags)) = 1.3.2
Provides: bundled(crate(block-buffer)) = 0.10.3
Provides: bundled(crate(block-buffer)) = 0.10.4
Provides: bundled(crate(cc)) = 1.0.79
Provides: bundled(crate(cfg-if)) = 1.0.0
Provides: bundled(crate(clap)) = 4.0.4
Provides: bundled(crate(clap_derive)) = 4.0.1
Provides: bundled(crate(clap_lex)) = 0.3.0
Provides: bundled(crate(config)) = 0.13.2
Provides: bundled(crate(cpufeatures)) = 0.2.5
Provides: bundled(crate(clap)) = 4.2.0
Provides: bundled(crate(clap_builder)) = 4.2.0
Provides: bundled(crate(clap_derive)) = 4.2.0
Provides: bundled(crate(clap_lex)) = 0.4.1
Provides: bundled(crate(concolor-override)) = 1.0.0
Provides: bundled(crate(concolor-query)) = 0.3.3
Provides: bundled(crate(config)) = 0.13.3
Provides: bundled(crate(cpufeatures)) = 0.2.6
Provides: bundled(crate(crypto-common)) = 0.1.6
Provides: bundled(crate(digest)) = 0.10.5
Provides: bundled(crate(digest)) = 0.10.6
Provides: bundled(crate(dlv-list)) = 0.3.0
Provides: bundled(crate(env_logger)) = 0.7.1
Provides: bundled(crate(generic-array)) = 0.14.6
Provides: bundled(crate(getrandom)) = 0.2.7
Provides: bundled(crate(glob)) = 0.3.0
Provides: bundled(crate(errno)) = 0.3.0
Provides: bundled(crate(errno-dragonfly)) = 0.1.2
Provides: bundled(crate(figlet-rs)) = 0.1.5
Provides: bundled(crate(generic-array)) = 0.14.7
Provides: bundled(crate(getrandom)) = 0.2.8
Provides: bundled(crate(glob)) = 0.3.1
Provides: bundled(crate(hashbrown)) = 0.12.3
Provides: bundled(crate(heck)) = 0.4.0
Provides: bundled(crate(heck)) = 0.4.1
Provides: bundled(crate(hermit-abi)) = 0.1.19
Provides: bundled(crate(hermit-abi)) = 0.3.1
Provides: bundled(crate(humantime)) = 1.3.0
Provides: bundled(crate(itoa)) = 1.0.3
Provides: bundled(crate(io-lifetimes)) = 1.0.9
Provides: bundled(crate(is-terminal)) = 0.4.6
Provides: bundled(crate(itoa)) = 1.0.6
Provides: bundled(crate(json5)) = 0.4.1
Provides: bundled(crate(lazy_static)) = 1.4.0
Provides: bundled(crate(libc)) = 0.2.133
Provides: bundled(crate(libc)) = 0.2.140
Provides: bundled(crate(linked-hash-map)) = 0.5.6
Provides: bundled(crate(linux-raw-sys)) = 0.3.0
Provides: bundled(crate(log)) = 0.4.17
Provides: bundled(crate(memchr)) = 2.5.0
Provides: bundled(crate(memoffset)) = 0.6.5
Provides: bundled(crate(minimal-lexical)) = 0.2.1
Provides: bundled(crate(nix)) = 0.25.0
Provides: bundled(crate(nom)) = 7.1.1
Provides: bundled(crate(once_cell)) = 1.15.0
Provides: bundled(crate(nix)) = 0.25.1
Provides: bundled(crate(nom)) = 7.1.3
Provides: bundled(crate(once_cell)) = 1.17.1
Provides: bundled(crate(ordered-multimap)) = 0.4.3
Provides: bundled(crate(os_str_bytes)) = 6.3.0
Provides: bundled(crate(pathdiff)) = 0.2.1
Provides: bundled(crate(pest)) = 2.3.1
Provides: bundled(crate(pest_derive)) = 2.3.1
Provides: bundled(crate(pest_generator)) = 2.3.1
Provides: bundled(crate(pest_meta)) = 2.3.1
Provides: bundled(crate(pest)) = 2.5.6
Provides: bundled(crate(pest_derive)) = 2.5.6
Provides: bundled(crate(pest_generator)) = 2.5.6
Provides: bundled(crate(pest_meta)) = 2.5.6
Provides: bundled(crate(pin-utils)) = 0.1.0
Provides: bundled(crate(pretty_env_logger)) = 0.4.0
Provides: bundled(crate(proc-macro-error)) = 1.0.4
Provides: bundled(crate(proc-macro-error-attr)) = 1.0.4
Provides: bundled(crate(proc-macro2)) = 1.0.43
Provides: bundled(crate(proc-macro2)) = 1.0.54
Provides: bundled(crate(quick-error)) = 1.2.3
Provides: bundled(crate(quote)) = 1.0.21
Provides: bundled(crate(regex)) = 1.6.0
Provides: bundled(crate(regex-syntax)) = 0.6.27
Provides: bundled(crate(quote)) = 1.0.26
Provides: bundled(crate(regex)) = 1.7.3
Provides: bundled(crate(regex-syntax)) = 0.6.29
Provides: bundled(crate(ron)) = 0.7.1
Provides: bundled(crate(rust-ini)) = 0.18.0
Provides: bundled(crate(ryu)) = 1.0.11
Provides: bundled(crate(serde)) = 1.0.144
Provides: bundled(crate(serde_derive)) = 1.0.144
Provides: bundled(crate(serde_json)) = 1.0.85
Provides: bundled(crate(sha1)) = 0.10.5
Provides: bundled(crate(rustix)) = 0.37.4
Provides: bundled(crate(ryu)) = 1.0.13
Provides: bundled(crate(serde)) = 1.0.159
Provides: bundled(crate(serde_derive)) = 1.0.159
Provides: bundled(crate(serde_json)) = 1.0.95
Provides: bundled(crate(sha2)) = 0.10.6
Provides: bundled(crate(strsim)) = 0.10.0
Provides: bundled(crate(syn)) = 1.0.100
Provides: bundled(crate(termcolor)) = 1.1.3
Provides: bundled(crate(thiserror)) = 1.0.35
Provides: bundled(crate(thiserror-impl)) = 1.0.35
Provides: bundled(crate(toml)) = 0.5.9
Provides: bundled(crate(typenum)) = 1.15.0
Provides: bundled(crate(syn)) = 1.0.109
Provides: bundled(crate(syn)) = 2.0.11
Provides: bundled(crate(termcolor)) = 1.2.0
Provides: bundled(crate(thiserror)) = 1.0.40
Provides: bundled(crate(thiserror-impl)) = 1.0.40
Provides: bundled(crate(toml)) = 0.5.11
Provides: bundled(crate(typenum)) = 1.16.0
Provides: bundled(crate(ucd-trie)) = 0.1.5
Provides: bundled(crate(unicode-ident)) = 1.0.4
Provides: bundled(crate(unicode-ident)) = 1.0.8
Provides: bundled(crate(utf8parse)) = 0.2.1
Provides: bundled(crate(version_check)) = 0.9.4
Provides: bundled(crate(wasi)) = 0.11.0+wasi_snapshot_preview1
Provides: bundled(crate(winapi)) = 0.3.9
Provides: bundled(crate(winapi-i686-pc-windows-gnu)) = 0.4.0
Provides: bundled(crate(winapi-util)) = 0.1.5
Provides: bundled(crate(winapi-x86_64-pc-windows-gnu)) = 0.4.0
Provides: bundled(crate(windows-sys)) = 0.45.0
Provides: bundled(crate(windows-targets)) = 0.42.2
Provides: bundled(crate(windows_aarch64_gnullvm)) = 0.42.2
Provides: bundled(crate(windows_aarch64_msvc)) = 0.42.2
Provides: bundled(crate(windows_i686_gnu)) = 0.42.2
Provides: bundled(crate(windows_i686_msvc)) = 0.42.2
Provides: bundled(crate(windows_x86_64_gnu)) = 0.42.2
Provides: bundled(crate(windows_x86_64_gnullvm)) = 0.42.2
Provides: bundled(crate(windows_x86_64_msvc)) = 0.42.2
Provides: bundled(crate(yaml-rust)) = 0.4.5

%description
Expand All @@ -147,7 +161,11 @@ cat >.cargo/config << EOF
[build]
rustc = "%{__rustc}"
rustdoc = "%{__rustdoc}"
%if 0%{?rhel} && !0%{?eln}
rustflags = %{__global_rustflags_toml}
%else
rustflags = "%{__global_rustflags_toml}"
%endif
[install]
root = "%{buildroot}%{_prefix}"
Expand Down Expand Up @@ -182,6 +200,7 @@ install -Dpm0644 -t %{buildroot}%{_unitdir} \
# add config
mkdir -p %{buildroot}%{_exec_prefix}/lib/motd.d/
mkdir -p %{buildroot}%{_libexecdir}/%{name}
install -Dpm0644 -t %{buildroot}%{_sysconfdir}/%{name} etc/greenboot/greenboot.conf
mkdir -p %{buildroot}%{_sysconfdir}/%{name}/check/required.d
mkdir %{buildroot}%{_sysconfdir}/%{name}/check/wanted.d
mkdir %{buildroot}%{_sysconfdir}/%{name}/green.d
Expand All @@ -196,23 +215,20 @@ mkdir -p %{buildroot}%{_tmpfilesdir}

%post
%systemd_post greenboot.service
%systemd_post greenboot-trigger.service

%preun
%systemd_preun greenboot.service
%systemd_preun greenboot-trigger.service

%postun
%systemd_postun greenboot.service
%systemd_postun greenboot-trigger.service

%files
%doc README.md
%license LICENSE
%dir %{_libexecdir}/%{name}
%{_libexecdir}/%{name}/%{name}
%{_unitdir}/greenboot.service
%{_unitdir}/greenboot-trigger.service
%{_sysconfdir}/%{name}/greenboot.conf
%dir %{_prefix}/lib/%{name}
%dir %{_prefix}/lib/%{name}/check
%dir %{_prefix}/lib/%{name}/check/required.d
Expand Down
Loading

0 comments on commit c836f58

Please sign in to comment.