Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit 38bde86

Browse files
committed
Ported build code from operators for rpm.
Also changed default paths for a lot of agent directories - this definitely needs calling out in the commit message! Config file is now empty, as all settings are used with their default values.
1 parent 1555057 commit 38bde86

File tree

8 files changed

+114
-49
lines changed

8 files changed

+114
-49
lines changed

.github/workflows/nightly.yml

+13-22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- rpm
78

89
env:
910
CARGO_TERM_COLOR: always
@@ -27,32 +28,22 @@ jobs:
2728
--data-binary "@./$(find target/debian/ -name *.deb)"
2829
"https://repo.stackable.tech/repository/deb-nightly/"
2930
30-
centos7:
31-
runs-on: centos7
31+
centos:
32+
runs-on: centos${{ matrix.node }}
33+
strategy:
34+
matrix:
35+
node: [ 7, 8 ]
3236
steps:
3337
- uses: actions/checkout@v2
34-
- name: Build rpm package
35-
run: ~/.cargo/bin/cargo rpm build -vvvvv
36-
- name: Publish rpm package
37-
run: >-
38-
/usr/bin/curl
39-
-vvvv
40-
--fail
41-
-u 'github:${{ secrets.NEXUS_PASSWORD }}'
42-
--upload-file "./$(find target/release/rpmbuild/RPMS/x86_64/ -name *.rpm)"
43-
"https://repo.stackable.tech/repository/rpm-nightly/el7/"
44-
45-
centos8:
46-
runs-on: centos8
47-
steps:
48-
- uses: actions/checkout@v2
49-
- name: Build rpm package
50-
run: ~/.cargo/bin/cargo rpm build -vvvvv
51-
- name: Publish rpm package
38+
- name: Build
39+
run: ~/.cargo/bin/cargo +nightly build --verbose --release
40+
- name: Build RPM package
41+
run: packaging/buildrpm.sh stackable-agent
42+
- name: Publish RPM package
5243
run: >-
5344
/usr/bin/curl
5445
-vvvv
5546
--fail
5647
-u 'github:${{ secrets.NEXUS_PASSWORD }}'
57-
--upload-file "./$(find target/release/rpmbuild/RPMS/x86_64/ -name *.rpm)"
58-
"https://repo.stackable.tech/repository/rpm-nightly/el8/"
48+
--upload-file "./$(find target/rpm/RPMS/x86_64/ -name *.rpm)"
49+
"https://repo.stackable.tech/repository/rpm-nightly/el${{ matrix.node }}/"

.rpm/config/agent.conf

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
--package-directory=/var/lib/stackable/packages
2-
--config-directory=/var/lib/stackable/config
3-
--data-directory=/var/lib/stackable/agent
4-
--server-key-file=/var/lib/stackable/agent/config/agent.key
5-
--server-cert-file=/var/lib/stackable/agent/config/agent.crt

Cargo.toml

+1-13
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,4 @@ systemd-units = { enable = false }
5757
assets = [
5858
["packaging/config/agent.conf", "etc/stackable-agent/", "644"],
5959
["target/release/agent", "opt/stackable-agent/stackable-agent", "755"],
60-
]
61-
[package.metadata.rpm]
62-
package = "stackable-agent"
63-
64-
[package.metadata.rpm.cargo]
65-
buildflags = ["--release"]
66-
67-
[package.metadata.rpm.targets]
68-
agent = { path = "/opt/stackable-agent/stackable-agent" }
69-
70-
[package.metadata.rpm.files]
71-
"config/agent.conf" = { path = "/etc/stackable-agent/agent.conf"}
72-
"systemd/stackable-agent.service" = { path = "/lib/systemd/system/stackable-agent.service"}
60+
]

packaging/buildrpm.sh

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
# This script creates an RPM package containing the binary created by this Cargo project.
3+
# The script is not universally applicable, since it makes a few assumptions about the project structure:
4+
# 1. The RPM scaffolding needs to be provided in server/packaging/rpm
5+
# 2. The binary to be packaged needs to be created in target/release
6+
7+
# The script takes one argument, which is the name of the binary that has been created by the build process.
8+
# This argument will be reused for naming the final RPM file.
9+
10+
# Check if one parameter was specified - we'll use this as the name parameter for all files
11+
# This allows us to reuse the script across all operators
12+
if [ -z $1 ]; then
13+
echo "This script requires the project name to be specified as the first parameter!"
14+
exit 1
15+
fi
16+
17+
export PACKAGE_NAME=$1
18+
BINARY_FILE=target/release/$PACKAGE_NAME
19+
20+
# The package description is parsed from the output of `cargo metadata` by using jq.
21+
# We need to look up the package with a select statement to match the name from an array of packages
22+
# The name is passed into jq as a jq variable, as no substitution would take place within the single
23+
# quotes of the jq expression.
24+
export PACKAGE_DESCRIPTION=$(~/.cargo/bin/cargo metadata --format-version 1| jq --arg NAME "$PACKAGE_NAME" '.packages[] | select(.name == $NAME) | .description')
25+
if [ -z $PACKAGE_DESCRIPTION ]; then
26+
echo "Unable to parse package description from output of `cargo metadata`, cannot build RPM without this field!"
27+
exit 2
28+
fi
29+
echo
30+
31+
# Check that we are being called from the main directory and the release build process has been run
32+
if [ ! -f $BINARY_FILE ]; then
33+
echo "Binary file not found at [$BINARY_FILE] - this script should be called from the root directory of the repository and 'cargo build --release' needs to have run before calling this script!"
34+
exit 3
35+
fi
36+
37+
echo Cleaning up prior build attempts
38+
rm -rf target/rpm
39+
40+
# Parse the version and release strings from the PKGID reported by Cargo
41+
# This is in the form Path#Projectname:version, which we parse by repeated calls to awk with different separators
42+
# This could most definitely be improved, but works for now
43+
export VERSION_STRING=$(~/.cargo/bin/cargo pkgid | awk -F'#' '{print $2}' | awk -F':' '{print $2}')
44+
echo version: ${VERSION_STRING}
45+
46+
export PACKAGE_VERSION=$(echo ${VERSION_STRING} | awk -F '-' '{print $1}')
47+
48+
# Any suffix like '-nightly' is split out into the release here, as - is not an allowed character in rpm versions
49+
# The final release will look like 0.suffix or 0 if no suffix is specified.
50+
export PACKAGE_RELEASE="0$(echo ${VERSION_STRING} | awk -F '-' '{ if ($2 != "") print "."$2;}')"
51+
52+
echo Defined package version: [${PACKAGE_VERSION}]
53+
echo Defined package release: [${PACKAGE_RELEASE}]
54+
echo Defined package description: [${PACKAGE_DESCRIPTION}]
55+
56+
echo Creating directory scaffolding for RPM
57+
cp -r packaging/rpm target/
58+
# Create empty directory for the binary to be placed into
59+
mkdir -p target/rpm/SOURCES/${PACKAGE_NAME}-VERSION/opt/stackable/${PACKAGE_NAME}
60+
61+
# Create config directory and copy config file template over
62+
mkdir -p target/rpm/SOURCES/${PACKAGE_NAME}-VERSION/etc/stackable/${PACKAGE_NAME}
63+
cp packaging/config/agent.config target/rpm/SOURCES/${PACKAGE_NAME}-VERSION/etc/stackable/${PACKAGE_NAME}
64+
65+
# The packaging source directory does not contain the version yet, as this will need to be replaced for every
66+
# execution. Instead the directory name contains the marker "VERSION" which we now replace with the actual version.
67+
rename VERSION ${PACKAGE_VERSION} target/rpm/SOURCES/${PACKAGE_NAME}-VERSION
68+
69+
cp target/release/${PACKAGE_NAME} target/rpm/SOURCES/${PACKAGE_NAME}-${PACKAGE_VERSION}/opt/stackable/${PACKAGE_NAME}/
70+
71+
pushd target/rpm/SOURCES
72+
tar czvf ${PACKAGE_NAME}-${PACKAGE_VERSION}.tar.gz ${PACKAGE_NAME}-${PACKAGE_VERSION}
73+
popd
74+
75+
rpmbuild --define "_topdir `pwd`/target/rpm" -v -ba target/rpm/SPECS/${PACKAGE_NAME}.spec

packaging/debian/postinst

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env bash
22

3-
mkdir -p /var/lib/stackable/packages
4-
mkdir -p /var/lib/stackable/config
5-
mkdir -p /var/lib/stackable/agent/config
3+
mkdir -p /opt/stackable/packages
4+
mkdir -p /var/lib/stackable/agent
5+
mkdir -p /var/log/stackable/servicelogs
6+
mkdir -p /etc/stackable/agent
7+
mkdir -m 700 /etc/stackable/agent/secret
68

79
#DEBHELPER#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=Stackable Agent
3+
Before=
4+
After=network.target
5+
[Service]
6+
User=root
7+
ExecStart=/opt/stackable/agent/stackable-agent
8+
Restart=on-abort
9+
StandardOutput=journal
10+
StandardError=journal
11+
Environment="CONFIG_FILE=/etc/stackable/agent/agent.conf"
12+
Environment="RUST_LOG=info"
13+
[Install]
14+
WantedBy=multi-user.target
File renamed without changes.

src/config/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl AgentConfig {
5353

5454
pub const DATA_DIR: ConfigOption = ConfigOption {
5555
name: "data-directory",
56-
default: Some("/var/stackable/agent/data"),
56+
default: Some("/var/lib/stackable/agent"),
5757
required: false,
5858
takes_argument: true,
5959
help: "The directory where the stackable agent should keep its working data.",
@@ -63,7 +63,7 @@ impl AgentConfig {
6363

6464
pub const BOOTSTRAP_FILE: ConfigOption = ConfigOption {
6565
name: "bootstrap-file",
66-
default: Some("/etc/kubernetes/bootstrap-kubelet.conf"),
66+
default: Some("/etc/stackable/agent/bootstrap-kubelet.conf"),
6767
required: false,
6868
takes_argument: true,
6969
help: "The bootstrap file to use in case Kubernetes bootstraping is used to add the agent.",
@@ -83,7 +83,7 @@ impl AgentConfig {
8383

8484
pub const SERVER_CERT_FILE: ConfigOption = ConfigOption {
8585
name: "server-cert-file",
86-
default: None,
86+
default: Some("/etc/stackable/agent/secret/agent.crt"),
8787
required: false,
8888
takes_argument: true,
8989
help: "The certificate file for the local webserver which the Krustlet starts.",
@@ -93,7 +93,7 @@ impl AgentConfig {
9393

9494
pub const SERVER_KEY_FILE: ConfigOption = ConfigOption {
9595
name: "server-key-file",
96-
default: None,
96+
default: Some("/etc/stackable/agent/secret/agent.key"),
9797
required: false,
9898
takes_argument: true,
9999
help:
@@ -124,7 +124,7 @@ impl AgentConfig {
124124

125125
pub const CONFIG_DIR: ConfigOption = ConfigOption {
126126
name: "config-directory",
127-
default: Some("/opt/stackable/config"),
127+
default: Some("/etc/stackable/serviceconfig"),
128128
required: false,
129129
takes_argument: true,
130130
help: "The base directory under which configuration will be generated for all executed services.",
@@ -134,7 +134,7 @@ impl AgentConfig {
134134

135135
pub const LOG_DIR: ConfigOption = ConfigOption {
136136
name: "log-directory",
137-
default: Some("/opt/stackable/logs"),
137+
default: Some("/var/log/stackable/servicelogs"),
138138
required: false,
139139
takes_argument: true,
140140
help: "The base directory under which log files will be placed for all services.",

0 commit comments

Comments
 (0)