Skip to content

Commit b40d939

Browse files
committed
Allow user-defined host containers
This adds a host-containers service that asks the API for the defined host-containers and tells systemd to start/stop them to match their 'enabled' setting. The settings are written to an EnvironmentFile that's read by the new host-container@ service, a systemd templated service used for all host containers by way of a suffix like "host-container@admin". The existing container-specific thar-be-settings templated systemd unit files were removed in favor of this more general approach. Existing metadata for these was also removed, replaced with a single metadata entry that invokes the new tool. The existing host-containers package, which just contains the Go host-ctr source, was renamed to host-ctr.
1 parent 87031a2 commit b40d939

29 files changed

+602
-74
lines changed

Makefile.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ for ws in workspaces packages images ; do
3434
done
3535
chmod o+r -R ${CARGO_HOME}
3636
37-
cd ${BUILDSYS_SOURCES_DIR}/host-containers/cmd/host-ctr
37+
cd ${BUILDSYS_SOURCES_DIR}/host-ctr/cmd/host-ctr
3838
docker run --rm \
3939
-e GOPRIVATE='*' \
4040
-e GOCACHE='/tmp/.cache' \

packages/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ members = [
2222
"golang",
2323
"growpart",
2424
"grub",
25-
"host-containers",
25+
"host-ctr",
2626
"iproute",
2727
"iptables",
2828
"iputils",

packages/api/api.spec

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Source7: settings-applier.service
2222
Source8: data-store-version
2323
Source9: migrator.service
2424
Source10: api-sysusers.conf
25+
26+
Source12: host-containers-tmpfiles.conf
2527
BuildRequires: gcc-%{_cross_target}
2628
BuildRequires: %{_cross_os}glibc-devel
2729
BuildRequires: %{_cross_os}systemd-devel
@@ -83,6 +85,12 @@ Requires: %{_cross_os}apiserver = %{version}-%{release}
8385
%description -n %{_cross_os}servicedog
8486
%{summary}.
8587

88+
%package -n %{_cross_os}host-containers
89+
Summary: Manages system- and user-defined host containers
90+
Requires: %{_cross_os}apiserver = %{version}-%{release}
91+
%description -n %{_cross_os}host-containers
92+
%{summary}.
93+
8694
%package -n %{_cross_os}storewolf
8795
Summary: Data store creator
8896
Requires: %{_cross_os}apiserver = %{version}-%{release}
@@ -109,7 +117,8 @@ Summary: Commits settings from user data, defaults, and generators at boot
109117
for p in \
110118
apiclient \
111119
moondog netdog sundog pluto bork \
112-
thar-be-settings servicedog storewolf settings-committer \
120+
thar-be-settings servicedog host-containers \
121+
storewolf settings-committer \
113122
migration/migrator ;
114123
do
115124
%cargo_build --path %{workspace_dir}/${p}
@@ -128,15 +137,16 @@ install -d %{buildroot}%{_cross_bindir}
128137
for p in \
129138
apiclient apiserver \
130139
moondog netdog sundog pluto bork \
131-
thar-be-settings servicedog storewolf settings-committer \
140+
thar-be-settings servicedog host-containers \
141+
storewolf settings-committer \
132142
migrator ;
133143
do
134144
install -p -m 0755 bin/${p} %{buildroot}%{_cross_bindir}
135145
done
136146

137147
install -d %{buildroot}%{_cross_unitdir}
138148
install -p -m 0644 \
139-
%{S:1} %{S:2} %{S:3} %{S:4} %{S:5} %{S:7} %{S:9} \
149+
%{S:1} %{S:2} %{S:3} %{S:4} %{S:5} %{S:7} %{S:9} %{S:11} \
140150
%{buildroot}%{_cross_unitdir}
141151

142152
install -d %{buildroot}%{_cross_datadir}/thar
@@ -150,6 +160,7 @@ done
150160

151161
install -d %{buildroot}%{_cross_tmpfilesdir}
152162
install -p -m 0644 %{S:6} %{buildroot}%{_cross_tmpfilesdir}/migration.conf
163+
install -p -m 0644 %{S:12} %{buildroot}%{_cross_tmpfilesdir}/host-containers.conf
153164

154165
install -d %{buildroot}%{_cross_sysusersdir}
155166
install -p -m 0644 %{S:10} %{buildroot}%{_cross_sysusersdir}/api.conf
@@ -188,6 +199,11 @@ install -p -m 0644 %{S:10} %{buildroot}%{_cross_sysusersdir}/api.conf
188199
%files -n %{_cross_os}servicedog
189200
%{_cross_bindir}/servicedog
190201

202+
%files -n %{_cross_os}host-containers
203+
%{_cross_bindir}/host-containers
204+
%{_cross_unitdir}/[email protected]
205+
%{_cross_tmpfilesdir}/host-containers.conf
206+
191207
%files -n %{_cross_os}storewolf
192208
%{_cross_bindir}/storewolf
193209
%{_cross_unitdir}/storewolf.service
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d /etc/host-containers 0755 root root -

packages/api/[email protected]

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
Description=Host container: %i
3+
After=host-containerd.service
4+
Requires=host-containerd.service
5+
6+
[Service]
7+
Type=simple
8+
EnvironmentFile=/etc/host-containers/%i.env
9+
ExecStart=/usr/bin/host-ctr -ctr-id='%i' -source='${CTR_SOURCE}' -superpowered='${CTR_SUPERPOWERED}'
10+
Restart=always
11+
RestartSec=10
12+
TimeoutStopSec=60
13+
KillMode=mixed
14+
15+
[Install]
16+
WantedBy=multi-user.target

packages/host-containers/Cargo.toml renamed to packages/host-ctr/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
2-
name = "host-containers"
2+
name = "host-ctr"
33
version = "0.1.0"
44
edition = "2018"
55
publish = false
66
build = "build.rs"
77

88
[package.metadata.build-package]
9-
source-groups = [ "host-containers" ]
9+
source-groups = [ "host-ctr" ]
1010

1111
[lib]
1212
path = "pkg.rs"
File renamed without changes.

packages/host-containers/host-containers.spec renamed to packages/host-ctr/host-ctr.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
%global workspace_name host-containers
1+
%global workspace_name host-ctr
22
%global systemd_systemdir %{_cross_libdir}/systemd/system
33

44
Name: %{_cross_os}%{workspace_name}
55
Version: 0.0
66
Release: 0%{?dist}
7-
Summary: Thar host container management
7+
Summary: Thar host container runner
88
License: FIXME
99
BuildRequires: gcc-%{_cross_target}
1010
BuildRequires: %{_cross_os}glibc-devel
File renamed without changes.

packages/release/host-containers-systemd-unit-admin.template

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/release/host-containers-systemd-unit-control.template

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/release/release.spec

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Source99: release-tmpfiles.conf
1616

1717
# FIXME What should own system-level file templates?
1818
Source200: hostname.template
19-
Source201: host-containers-systemd-unit-admin.template
20-
Source202: host-containers-systemd-unit-control.template
2119

2220
Source1000: eth0.xml
2321
Source1002: configured.target
@@ -55,7 +53,7 @@ Requires: %{_cross_os}signpost
5553
Requires: %{_cross_os}sundog
5654
Requires: %{_cross_os}pluto
5755
Requires: %{_cross_os}storewolf
58-
Requires: %{_cross_os}servicedog
56+
Requires: %{_cross_os}host-containers
5957
Requires: %{_cross_os}settings-committer
6058
Requires: %{_cross_os}systemd
6159
Requires: %{_cross_os}thar-be-settings
@@ -64,7 +62,7 @@ Requires: %{_cross_os}updog
6462
Requires: %{_cross_os}util-linux
6563
Requires: %{_cross_os}preinit
6664
Requires: %{_cross_os}wicked
67-
Requires: %{_cross_os}host-containers
65+
Requires: %{_cross_os}host-ctr
6866

6967
%description
7068
%{summary}.
@@ -107,8 +105,6 @@ install -p -m 0644 %{S:1002} %{S:1003} %{S:1006} %{S:1007} %{S:1008} %{S:1009} %
107105

108106
install -d %{buildroot}%{_cross_templatedir}
109107
install -p -m 0644 %{S:200} %{buildroot}%{_cross_templatedir}/hostname
110-
install -p -m 0644 %{S:201} %{buildroot}%{_cross_templatedir}/host-containers-systemd-unit-admin
111-
install -p -m 0644 %{S:202} %{buildroot}%{_cross_templatedir}/host-containers-systemd-unit-control
112108

113109
%files
114110
%if %{with shell}
@@ -130,7 +126,5 @@ install -p -m 0644 %{S:202} %{buildroot}%{_cross_templatedir}/host-containers-sy
130126
%{_cross_unitdir}/var-lib-thar.mount
131127
%dir %{_cross_templatedir}
132128
%{_cross_templatedir}/hostname
133-
%{_cross_templatedir}/host-containers-systemd-unit-admin
134-
%{_cross_templatedir}/host-containers-systemd-unit-control
135129

136130
%changelog

workspaces/Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workspaces/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"api/sundog",
1010
"api/pluto",
1111
"api/servicedog",
12+
"api/host-containers",
1213
"api/storewolf",
1314
"api/thar-be-settings",
1415
"api/settings-committer",

workspaces/api/apiserver/src/model.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
77
use std::collections::HashMap;
88
use std::net::Ipv4Addr;
99

10-
use crate::modeled_types::ValidBase64;
10+
use crate::modeled_types::{SingleLineString, ValidBase64};
1111

1212
///// Primary user-visible settings
1313

@@ -32,7 +32,7 @@ pub struct Settings {
3232
pub updates: Option<UpdatesSettings>,
3333

3434
#[serde(skip_serializing_if = "Option::is_none")]
35-
pub host_containers: Option<HashMap<String, ContainerImage>>,
35+
pub host_containers: Option<HashMap<SingleLineString, ContainerImage>>,
3636

3737
#[serde(skip_serializing_if = "Option::is_none")]
3838
pub ntp: Option<NtpSettings>,
@@ -86,7 +86,7 @@ pub struct UpdatesSettings {
8686
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
8787
pub struct ContainerImage {
8888
#[serde(skip_serializing_if = "Option::is_none")]
89-
pub source: Option<String>,
89+
pub source: Option<SingleLineString>,
9090

9191
#[serde(skip_serializing_if = "Option::is_none")]
9292
pub enabled: Option<bool>,

0 commit comments

Comments
 (0)