diff --git a/.drone.yml b/.drone.yml index addca37..96952f3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,6 +39,11 @@ steps: - name: docker_sock path: /var/run/docker.sock + - name: build-rpm + image: casperlabs/rpm-package + commands: + - cargo rpm build -v + volumes: - name: docker_sock host: @@ -99,16 +104,6 @@ steps: commands: - cargo deb - - name: publish-bintray - image: casperlabs/casper-node-launcher-build - commands: - - "./upload_to_bintray.sh --repo-name debian --package-name casper-node-launcher --package-tag true" - environment: - CL_VAULT_TOKEN: - from_secret: vault_token - CL_VAULT_HOST: - from_secret: vault_host - - name: publish-repo-prod image: casperlabs/aptly:latest failure: ignore @@ -156,6 +151,31 @@ steps: DOCKER_PASSWORD: from_secret: docker_password + - name: build-rpm + image: casperlabs/rpm-package + commands: + - cargo rpm build -v + + + - name: publish-github-release + image: plugins/github-release + settings: + api_key: + from_secret: github_token + checksum: + - sha256 + - md5 + files: + - "./target/debian/*.deb" + - "./target/release/rpmbuild/RPMS/x86_64/*.rpm" + prerelease: + - true + when: + ref: + - refs/tags/v* + + # Need to attach rpm to github artifacts. + volumes: - name: docker_sock host: diff --git a/.rpm/casper-node-launcher.spec b/.rpm/casper-node-launcher.spec new file mode 100644 index 0000000..6825c53 --- /dev/null +++ b/.rpm/casper-node-launcher.spec @@ -0,0 +1,104 @@ +BuildRequires: systemd-rpm-macros +Requires: curl +%define __spec_install_post %{nil} +%define __os_install_post %{_dbpath}/brp-compress +%define debug_package %{nil} + +Name: casper-node-launcher +Summary: A binary which runs and upgrades the casper-node of the Casper network +Version: @@VERSION@@ +Release: @@RELEASE@@%{?dist} +License: CasperLabs Open Source License (COSL) +Group: Applications/System +Source0: %{name}-%{version}.tar.gz +URL: https://casperlabs.io + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root + +%description +%{summary} + +%prep +%setup -q + +%pre +# Default Variables +# --- +DEFAULT_USERNAME="casper" +DEFAULT_CONFIG_DIRECTORY="/etc/${DEFAULT_USERNAME}" +DEFAULT_DATA_DIRECTORY="/var/lib/${DEFAULT_USERNAME}/bin" +DEFAULT_LOG_DIRECOTRY="/var/log/${DEFAULT_USERNAME}" + +# Creation of Files/Directories +# --- +# Assure DEFAULT_DATA_DIRECTORY is available for state data +if [ -d ${DEFAULT_DATA_DIRECTORY} ] ; then + echo "Directory ${DEFAULT_DATA_DIRECTORY} already exists." +else + mkdir -p ${DEFAULT_DATA_DIRECTORY} +fi + +# Assure DEFAULT_CONFIG_DIRECTORY is available for config data +if [ -d ${DEFAULT_CONFIG_DIRECTORY} ] ; then + echo "Directory ${DEFAULT_CONFIG_DIRECTORY} already exists." +else + mkdir -p ${DEFAULT_CONFIG_DIRECTORY} +fi + +# Assure DEFAULT_LOG_DIRECOTRY is available for logging +if [ -d ${DEFAULT_LOG_DIRECOTRY} ] ; then + echo "Directory ${DEFAULT_LOG_DIRECOTRY} already exists." +else + mkdir -p ${DEFAULT_LOG_DIRECOTRY} +fi +exit 0 + +%post +# Default Variables +# --- +DEFAULT_USERNAME="casper" +DEFAULT_CONFIG_DIRECTORY="/etc/${DEFAULT_USERNAME}" +DEFAULT_DATA_DIRECTORY="/var/lib/${DEFAULT_USERNAME}" +DEFAULT_LOG_DIRECOTRY="/var/log/${DEFAULT_USERNAME}" + +# User Creation +# --- +# Assure DEFAULT_USERNAME user exists +getent group casper >/dev/null || groupadd -r casper +getent passwd casper >/dev/null || \ + useradd -r -g casper -s /sbin/nologin \ + -c "User for running casper-node-launcher" casper + +# Take ownership of directories and files installed +chown -R ${DEFAULT_USERNAME}:${DEFAULT_USERNAME} ${DEFAULT_DATA_DIRECTORY} +chown -R ${DEFAULT_USERNAME}:${DEFAULT_USERNAME} ${DEFAULT_CONFIG_DIRECTORY} +chown -R ${DEFAULT_USERNAME}:${DEFAULT_USERNAME} ${DEFAULT_LOG_DIRECOTRY} + +# Update systemd for unit file +systemctl daemon-reload + +exit 0 + + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot} +cp -a * %{buildroot} + +%clean +rm -rf %{buildroot} + +%files +%defattr(-,casper,casper,-) +%{_bindir}/* +/var/lib/casper/bin/README.md +/etc/logrotate.d/casper-node +/etc/casper/PLATFORM +/etc/casper/pull_casper_node_version.sh +/etc/casper/network_configs/casper.conf +/etc/casper/network_configs/casper-test.conf +/etc/casper/delete_local_db.sh +/etc/casper/config_from_example.sh +/etc/casper/README.md +/etc/casper/validator_keys/README.md +/etc/systemd/system/casper-node-launcher.service diff --git a/Cargo.lock b/Cargo.lock index e4b3a72..8632544 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,7 +75,7 @@ checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" [[package]] name = "casper-node-launcher" -version = "0.3.3" +version = "0.3.4" dependencies = [ "anyhow", "backtrace", diff --git a/Cargo.toml b/Cargo.toml index bf03486..d40d1f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "casper-node-launcher" -version = "0.3.3" +version = "0.3.4" authors = ["Fraser Hutchison ", "Joe Sacher "] edition = "2018" description = "A binary which runs and upgrades the casper-node of the Casper network" readme = "README.md" documentation = "https://docs.rs/casper-node-launcher" -homepage = "https://casperlabs.io" +homepage = "https://casper.network" repository = "https://github.com/CasperLabs/casper-node/tree/master/client" license-file = "./LICENSE" @@ -35,11 +35,12 @@ assets = [ ["./target/release/casper-node-launcher", "/usr/bin/casper-node-launcher", "755"], ["./resources/BIN_README.md", "/var/lib/casper/bin/README.md", "755"], ["./resources/maintainer_scripts/logrotate.d/casper-node", "/etc/logrotate.d/casper-node", "644"], + ["./resources/PLATFORM_DEB", "/etc/casper/PLATFORM", "644"], ["./resources/maintainer_scripts/pull_casper_node_version.sh", "/etc/casper/pull_casper_node_version.sh", "755"], ["./resources/maintainer_scripts/network_configs/*", "/etc/casper/network_configs/", "644"], ["./resources/maintainer_scripts/delete_local_db.sh", "/etc/casper/delete_local_db.sh", "755"], ["./resources/maintainer_scripts/config_from_example.sh", "/etc/casper/config_from_example.sh", "755"], - ["./resources/DEB_README.md", "/etc/casper/README.md", "644"], + ["./resources/ETC_README.md", "/etc/casper/README.md", "644"], ["./resources/VALIDATOR_KEYS_README.md", "/etc/casper/validator_keys/README.md", "644"] ] maintainer-scripts = "./resources/maintainer_scripts/debian" @@ -52,3 +53,27 @@ For information on using package, see https://github.com/CasperLabs/casper-node- [package.metadata.deb.systemd-units] unit-scripts = "./resources/maintainer_scripts/casper_node_launcher" restart-after-upgrade = false + +[package.metadata.rpm] +package = "casper-node-launcher" + +[package.metadata.rpm.cargo] +buildflags = ["--release"] + +[package.metadata.rpm.systemd-units] +unit-scripts = "./resources/maintainer_scripts/casper_node_launcher" +restart-after-upgrade = false + +[package.metadata.rpm.targets] +casper-node-launcher = { path = "/usr/bin/casper-node-launcher" } +"../../resources/BIN_README.md" = {path = "/var/lib/casper/bin/README.md"} +"../../resources/PLATFORM_RPM" = {path = "/etc/casper/PLATFORM"} +"../../resources/maintainer_scripts/logrotate.d/casper-node" = {path = "/etc/logrotate.d/casper-node"} +"../../resources/maintainer_scripts/pull_casper_node_version.sh" = {path = "/etc/casper/pull_casper_node_version.sh"} +"../../resources/maintainer_scripts/network_configs/casper.conf" = {path = "/etc/casper/network_configs/casper.conf"} +"../../resources/maintainer_scripts/network_configs/casper-test.conf" = {path = "/etc/casper/network_configs/casper-test.conf"} +"../../resources/maintainer_scripts/delete_local_db.sh" = {path = "/etc/casper/delete_local_db.sh"} +"../../resources/maintainer_scripts/config_from_example.sh" = {path = "/etc/casper/config_from_example.sh"} +"../../resources/ETC_README.md" = {path = "/etc/casper/README.md"} +"../../resources/VALIDATOR_KEYS_README.md" = {path = "/etc/casper/validator_keys/README.md"} +"../../resources/maintainer_scripts/casper_node_launcher/casper-node-launcher.service" = {path = "/etc/systemd/system/casper-node-launcher.service"} diff --git a/resources/BIN_README.md b/resources/BIN_README.md index 3350c9c..b0e2362 100644 --- a/resources/BIN_README.md +++ b/resources/BIN_README.md @@ -2,4 +2,4 @@ This directory holds casper-node executables in semver folder using underscores. example: -`casper-node` version `1.0.2` would exist as `./1_0_2/casper-node` \ No newline at end of file +`casper-node` version `1.0.0` would exist as `./1_0_0/casper-node` \ No newline at end of file diff --git a/resources/DEB_README.md b/resources/ETC_README.md similarity index 90% rename from resources/DEB_README.md rename to resources/ETC_README.md index 018ddd9..e198390 100644 --- a/resources/DEB_README.md +++ b/resources/ETC_README.md @@ -53,14 +53,17 @@ To stop: If you need to delete the db for a new run, you can use the script in `/etc/casper` with `sudo /etc/casper/delete_local_db.sh`. -## Upgrading casper-node +## Staging casper-node protocols Upgrading is done by staging a new casper-node and configuration prior to the agreed upgrade era. -To simplify this, the `sudo -u casper /etc/casper/pull_casper_node_version.sh [semver] [network]` script is included. This will +To simplify this, the `sudo -u casper /etc/casper/pull_casper_node_version.sh [network config] [semver]` script is included. This will pull files from the appropriate version. If desired, the casper-node can be built from source at the same version. +To get a working default config.toml for a protocol version: `sudo -u casper /etc/casper/config_from_example.sh [semver]`. + + When the upgrade era occurs, the currently running casper-node will exit and casper-node-launcher will start the new upgraded version of casper-node. diff --git a/resources/PLATFORM_DEB b/resources/PLATFORM_DEB new file mode 100644 index 0000000..811c85f --- /dev/null +++ b/resources/PLATFORM_DEB @@ -0,0 +1 @@ +deb \ No newline at end of file diff --git a/resources/PLATFORM_RPM b/resources/PLATFORM_RPM new file mode 100644 index 0000000..7c88ef3 --- /dev/null +++ b/resources/PLATFORM_RPM @@ -0,0 +1 @@ +rpm \ No newline at end of file