Skip to content

Commit c243148

Browse files
Add config for docker-building/-running up-subscription-cli (#5)
1 parent 41911e5 commit c243148

File tree

8 files changed

+91
-17
lines changed

8 files changed

+91
-17
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

.github/workflows/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ This is implemented in [`nightly.yaml`](nightly.yaml)
2828

2929
In addition to the main workflows described above, there exist a number of modules that are used by these main workflows. They can also be run standalone, and are intendet to make composing the capabilities of our main workflows simpler. These are:
3030

31-
- `verify-msrv.yaml` - checks if the MSRV ('Minimum Supported Rust Version) declared in Cargo.toml is correct
32-
- `coverage.yaml` - collects test code coverage, and can optionally upload the results to codecov.io
31+
- [`coverage.yaml`](coverage.yaml) - collects test code coverage, and can optionally upload the results to codecov.io
3332
- Will publish coverage data to CodeCov if `${{ secrets.CODECOV_TOKEN }}` is set
3433
- outputs: download URL for the workflow-generated coverage info file
35-
- `license-report.yaml` - create a license report for `up-rust` and all its dependencies in html format
34+
- [`license-report.yaml`](license-report.yaml) - create a license report for `up-rust` and all its dependencies in html format
3635
- outputs: download URL for the workflow-generated license report
37-
- `test-featurematrix.yaml` - Test all feature combinations on a range of OS platforms
38-
- `x-build.yaml` - Run release builds on multiple architecture targets
36+
- [`test-featurematrix.yaml`](test-featurematrix.yaml) - Test all feature combinations on a range of OS platforms
37+
- [`verify-msrv.yaml`](verify-msrv.yaml) - checks if the MSRV ('Minimum Supported Rust Version) declared in Cargo.toml is correct
38+
- [`x-build.yaml`](x-build.yaml) - Run release builds on multiple architecture targets

Dockerfile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
################################################################################
2+
# Copyright (c) 2024 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
################################################################################
13+
14+
FROM rust:slim as build
15+
16+
# create a new empty shell project
17+
RUN USER=root mkdir /up-subscription-rust
18+
WORKDIR /up-subscription-rust
19+
20+
# clone workspace
21+
COPY ./ ./
22+
# not yet available on stable syntax
23+
#COPY --exclude=target ./ ./
24+
25+
# this build step will cache your dependencies, use same profile as cargo-dist
26+
RUN cargo build --all-features --profile=dist
27+
28+
# our final base
29+
FROM debian:stable-slim
30+
31+
# copy the build artifact from the build stage
32+
COPY --from=build /up-subscription-rust/target/dist/up-subscription-cli .
33+
RUN chmod +x /up-subscription-cli
34+
35+
ADD tools/startup.sh /
36+
RUN chmod +x /startup.sh
37+
38+
# set the startup command to run your binary
39+
ENTRYPOINT ["/startup.sh"]

docker-compose.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
################################################################################
2+
# Copyright (c) 2024 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
################################################################################
13+
14+
services:
15+
up-subscription:
16+
container_name: up-subscription
17+
image: up-subscription:latest
18+
build:
19+
context: .
20+
network_mode: host
21+
restart: unless-stopped
22+
environment:
23+
- AUTHORITY=usubscription.local
24+
- TRANSPORT=zenoh
25+
- VERBOSE=true

tools/startup.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
/up-subscription-cli

up-subscription-cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ zenoh = ["dep:up-transport-zenoh"]
3535
[dependencies]
3636
async-mutex = { workspace = true }
3737
async-trait = { workspace = true }
38-
clap = { version = "4.5", features = ["derive"] }
38+
clap = { version = "4.5", features = ["derive", "env"] }
3939
clap-num = { version = "1.1" }
4040
env_logger = { workspace = true }
4141
futures = { workspace = true }

up-subscription-cli/src/main.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ enum Transports {
7272
#[command(version, about = "Rust implementation of Eclipse uProtocol USubscription service.", long_about = None)]
7373
pub(crate) struct Args {
7474
/// Authority name for usubscription service
75-
#[arg(short, long)]
75+
#[arg(short, long, env)]
7676
authority: String,
7777

7878
/// Run as a daemon (in the background)
@@ -81,19 +81,19 @@ pub(crate) struct Args {
8181
daemon: bool,
8282

8383
/// The transport implementation to use
84-
#[arg(short, long)]
84+
#[arg(short, long, env)]
8585
transport: Transports,
8686

8787
/// Buffer size of subscription command channel - minimum 1, maximum 1024, defaults to 1024
88-
#[arg(short, long, value_parser=between_1_and_1024)]
88+
#[arg(short, long, env, value_parser=between_1_and_1024)]
8989
subscription_buffer: Option<usize>,
9090

9191
/// Buffer size of notification command channel - minimum 1, maximum 1024, defaults to 1024
92-
#[arg(short, long, value_parser=between_1_and_1024)]
92+
#[arg(short, long, env, value_parser=between_1_and_1024)]
9393
notification_buffer: Option<usize>,
9494

9595
/// Increase verbosity of output
96-
#[arg(short, long, default_value_t = false)]
96+
#[arg(short, long, env, default_value_t = false)]
9797
verbose: bool,
9898
}
9999

@@ -155,17 +155,20 @@ async fn main() {
155155
);
156156

157157
// Daemonize or wait for shutdown signal
158-
if cfg!(unix) && args.daemon {
158+
#[cfg(unix)]
159+
if args.daemon {
159160
let daemonize = Daemonize::new();
160161
match daemonize.start() {
161-
Ok(_) => debug!("Success, daemonized"),
162+
Ok(_) => {
163+
debug!("Success, running daemonized");
164+
}
162165
Err(e) => error!("Error, {}", e),
163166
}
164-
} else {
165-
signal::ctrl_c().await.expect("failed to listen for event");
166-
info!("Stopping usubscription service");
167-
ustop.stop().await;
168167
}
168+
169+
signal::ctrl_c().await.expect("failed to listen for event");
170+
info!("Stopping usubscription service");
171+
ustop.stop().await;
169172
}
170173

171174
fn config_from_args(args: &Args) -> Result<Arc<USubscriptionConfiguration>, ConfigurationError> {

up-subscription/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ uriparse = { version = "0.6" }
3636
[dev-dependencies]
3737
mockall = { workspace = true }
3838
test-case = { workspace = true }
39+
40+
[package.metadata.dist]
41+
all-features = true

0 commit comments

Comments
 (0)