Skip to content

Commit 4417127

Browse files
committed
feat: local install of ProSA for Linux and MacOS
Signed-off-by: Jeremy HERGAULT <[email protected]>
1 parent f268bdf commit 4417127

File tree

12 files changed

+566
-93
lines changed

12 files changed

+566
-93
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ serde = { version = "1", features = ["derive"] }
3232
url = { version = "2", features = ["serde"] }
3333
tokio = { version = "1", features = ["fs", "macros", "net", "parking_lot", "rt", "rt-multi-thread", "signal", "sync", "time"] }
3434
config = { version = "0.15", default-features = false, features = ["toml", "json", "yaml", "json5", "convert-case", "async"] }
35-
toml = "0.8"
35+
toml = "0.9"
3636

3737
# Config Observability
3838
log = "0.4"

assets/macos_prosa_background.png

70.4 KB
Loading

cargo-prosa/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-prosa"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
authors.workspace = true
55
description = "ProSA utility to package and deliver a builded ProSA"
66
homepage.workspace = true
@@ -20,7 +20,7 @@ clap = "4"
2020
clap_complete = "4"
2121
serde.workspace = true
2222
toml.workspace = true
23-
toml_edit = { version = "0.22", features = ["serde"] }
23+
toml_edit = { version = "0.23", features = ["serde"] }
2424
serde_json = "1"
2525
serde_yaml = "0.9"
2626
config.workspace = true

cargo-prosa/README.md

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ This builder is packaged within cargo as a custom command to be well integrated
88

99
## Install
1010

11-
As you can tell by its name, cargo-prosa, is tool embeded in [Cargo](https://doc.rust-lang.org/book/ch14-05-extending-cargo.html).
12-
13-
Therefore, you can install it via the Cargo command:
11+
`cargo-prosa` is a [Cargo subcommand](https://doc.rust-lang.org/book/ch14-05-extending-cargo.html), so you need to have [Cargo installed](https://doc.rust-lang.org/cargo/getting-started/installation.html) to use it.
12+
Install cargo-prosa using the following command:
1413
```bash
1514
cargo install cargo-prosa
1615
```
1716

18-
You should have the command installed with its bounch of functions:
17+
After installation, verify that the command is available and explore its features:
1918
```bash
2019
cargo prosa --help
2120
```
@@ -94,6 +93,115 @@ target/debug/my-prosa -n "MyBuiltProSA" -c default_config.yaml
9493
This builder offer you several possibilities to deploy your ProSA.
9594
The goal is to use the easiest method of a plateform to run your application.
9695

96+
### Locally
97+
98+
On Linux or MacOS, you can install ProSA directly on your machine:
99+
```bash
100+
# Install ProSA
101+
cargo prosa install
102+
103+
# Uninstall ProSA
104+
cargo prosa uninstall
105+
```
106+
107+
To avoid conflicts, specify a unique name during installation:
108+
```bash
109+
cargo prosa install --name dummy
110+
```
111+
112+
Use the same name when uninstalling:
113+
```bash
114+
cargo prosa uninstall --name dummy
115+
```
116+
117+
If the package isn't compiled for debug or release (--release), it will automatically compile during installation.
118+
119+
Simulate an installation with:
120+
```bash
121+
cargo prosa install --dry_run -n dummy
122+
```
123+
124+
#### Linux
125+
126+
When you want to install ProSA with `cargo prosa install`:
127+
```bash
128+
$ cargo prosa install -r -n dummy
129+
Creating service file OK
130+
Copying binary OK
131+
Generating configuration OK
132+
Installed [12183 kB] ProSA `dummy`
133+
Binary file : $HOME/.local/bin/prosa-dummy
134+
Config file : $HOME/.config/prosa/dummy/prosa.toml
135+
Service file: $HOME/.config/systemd/user/dummy.service
136+
```
137+
138+
And you'll be able to handle it through `systemctl`:
139+
```bash
140+
$ systemctl --user status dummy.service
141+
○ dummy.service - Local ProSA instance
142+
Loaded: loaded ($HOME/.config/systemd/user/dummy.service; disabled; preset: enabled)
143+
Active: inactive (dead)
144+
```
145+
146+
To install it for the whole system, you can use the `--system` option:
147+
```bash
148+
$ sudo -E $HOME/.cargo/bin/cargo prosa install -r -s -n dummy
149+
Creating service file OK
150+
Copying binary OK
151+
Generating configuration OK
152+
Installed [12184 kB] ProSA `dummy`
153+
Binary file : /usr/local/bin/prosa-dummy
154+
Config file : /etc/prosa/dummy/prosa.toml
155+
Service file: /etc/systemd/system/dummy.service
156+
```
157+
158+
By installing ProSA system wide, you are able to see the service:
159+
```bash
160+
$ sudo service dummy status
161+
○ dummy.service - Local ProSA instance
162+
Loaded: loaded (/etc/systemd/system/dummy.service; disabled; preset: enabled)
163+
Active: inactive (dead)
164+
```
165+
166+
#### MacOS
167+
168+
On MacOS it's the same as Linux, but with MacOS specifics.
169+
170+
So you can install it, and if the binary don't exist, it'll compil the project:
171+
```bash
172+
$ cargo prosa install -r -n dummy
173+
Creating service OK
174+
Compiling ...
175+
Finished `release` profile [optimized] target(s) in 24.58s
176+
Copying binary OK
177+
Generating configuration OK
178+
Installed [10578 kB] ProSA `dummy`
179+
Binary file : $HOME/.local/bin/prosa-dummy
180+
Config file : $HOME/.config/prosa/dummy/prosa.toml
181+
Service file: $HOME/Library/LaunchAgents/com.prosa.dummy.plist
182+
```
183+
184+
And once cargo-prosa installed the service, MacOS should notify you to indicate the new created service:
185+
186+
![MacOS service creation notification](/assets/macos_prosa_background.png)
187+
188+
You can now load it and run it with:
189+
```bash
190+
launchctl load $HOME/Library/LaunchAgents/com.prosa.dummy.plist
191+
```
192+
193+
and you can uninstall it with:
194+
```bash
195+
$ launchctl unload $HOME/Library/LaunchAgents/com.prosa.dummy.plist
196+
$ cargo prosa uninstall -n dummy
197+
Remove service OK
198+
Remove binary OK
199+
Uninstalled ProSA `dummy`
200+
Binary file : $HOME/.local/bin/prosa-dummy
201+
Config file : $HOME/.config/prosa/dummy/prosa.toml
202+
Service file: $HOME/Library/LaunchAgents/com.prosa.dummy.plist
203+
```
204+
97205
### Container
98206

99207
Containerization will allow you to build and load ProSA in an image:

cargo-prosa/assets/launchd.j2

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>Label</key>
6+
<string>com.prosa.{{ name }}.daemon.plist</string>
7+
8+
<key>RunAtLoad</key>
9+
<true/>
10+
11+
<key>ProgramArguments</key>
12+
<array>
13+
<string>{{ bin }}</string>
14+
<string>-c</string>
15+
<string>{{ config }}</string>
16+
</array>
17+
</dict>
18+
</plist>

cargo-prosa/src/cargo.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ pub struct PackageMetadata {
231231

232232
/// Metadata of the package
233233
metadata: Option<HashMap<String, serde_json::Value>>,
234+
/// target of the package
235+
targets: Option<Vec<HashMap<String, serde_json::Value>>>,
234236
}
235237

236238
impl PackageMetadata {
@@ -243,6 +245,30 @@ impl PackageMetadata {
243245
}
244246
}
245247

248+
/// Getter of the targets for a specific `kind` (bin, custom-build)
249+
pub fn get_targets(&self, kind: &str) -> Option<Vec<String>> {
250+
if let Some(targets) = &self.targets {
251+
let kind_tera_value = tera::Value::String(kind.to_string());
252+
let mut binary_targets = Vec::new();
253+
for target in targets {
254+
if let Some(kinds) = target.get("kind").and_then(|k| k.as_array())
255+
&& kinds.contains(&kind_tera_value)
256+
&& let Some(name) = target.get("name").and_then(|k| k.as_str())
257+
{
258+
binary_targets.push(name.to_string());
259+
}
260+
}
261+
262+
if binary_targets.is_empty() {
263+
None
264+
} else {
265+
Some(binary_targets)
266+
}
267+
} else {
268+
None
269+
}
270+
}
271+
246272
/// Know if the package contain ProSA metadata
247273
pub fn is_prosa(&self) -> bool {
248274
self.contain_metadata("prosa")

0 commit comments

Comments
 (0)