Skip to content

Commit 2380976

Browse files
committed
Makefile: Changed old allocator script with new allocators binary
Changed makefile to build allocator as a separated binary. Since binary and the bash script has the same the allocator.service will pick up the new one. Also i found this NITRO_CLI_INSTALL_DIR env variable. It fails to read config file if env variable is not exist. If env variable not exist then allocator will try to find the config file in / directory. Tried to build everything manually i bumped into this error in amazon linux and ubuntu instances. Also legacy allocator has the same mechanism but it was not failing. it was failing in Rust so i had to add a sanity check.
1 parent 97c9782 commit 2380976

File tree

5 files changed

+58
-18
lines changed

5 files changed

+58
-18
lines changed

Cargo.lock

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

Makefile

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ aws-nitro-enclaves-cli.tar.gz:
9393
sources: aws-nitro-enclaves-cli.tar.gz crates-dependencies
9494

9595
.PHONY: all
96-
all: build-setup nitro-cli vsock-proxy
96+
all: build-setup nitro-cli vsock-proxy nitro-enclaves-allocator
9797

9898
.PHONY: driver-deps
9999
driver-deps:
@@ -289,6 +289,32 @@ vsock-proxy-native:
289289
--manifest-path=${BASE_PATH}/vsock_proxy/Cargo.toml \
290290
--target-dir=${OBJ_PATH}/vsock_proxy
291291

292+
# See .build-container rule for explanation.
293+
.build-nitro-enclaves-allocator: $(shell find $(BASE_PATH)/allocator/src -name "*.rs")
294+
$(DOCKER) run \
295+
-v "$$(readlink -f ${BASE_PATH})":/nitro_src \
296+
-v "$$(readlink -f ${OBJ_PATH})":/nitro_build \
297+
$(CONTAINER_TAG) bin/bash -c \
298+
'source /root/.cargo/env && \
299+
CC=${CC} cargo build \
300+
--release \
301+
--target-dir=/nitro_build/allocator \
302+
--target=${CARGO_TARGET} \
303+
--manifest-path=/nitro_src/allocator/Cargo.toml && \
304+
chmod -R 777 nitro_build '
305+
ln -sf ../${CARGO_TARGET}/release/nitro-enclaves-allocator \
306+
${OBJ_PATH}/allocator/release/nitro-enclaves-allocator
307+
touch $@
308+
309+
nitro-enclaves-allocator: build-setup build-container .build-nitro-enclaves-allocator
310+
311+
.PHONY: nitro-enclaves-allocator-native
312+
nitro-enclaves-allocator-native:
313+
cargo build \
314+
--release \
315+
--manifest-path=${BASE_PATH}/allocator/Cargo.toml \
316+
--target-dir=${OBJ_PATH}/allocator
317+
292318
.PHONY: install-command-executer
293319
install-command-executer:
294320
$(INSTALL) -D -m 0755 $(OBJ_PATH)/command-executer/release/command-executer ${NITRO_CLI_INSTALL_DIR}/${BIN_DIR}/command-executer
@@ -300,7 +326,7 @@ install-tools:
300326
$(INSTALL) -D -m 0755 $(OBJ_PATH)/vsock_proxy/release/vsock-proxy ${NITRO_CLI_INSTALL_DIR}${BIN_DIR}/vsock-proxy
301327
$(INSTALL) -D -m 0644 vsock_proxy/service/nitro-enclaves-vsock-proxy.service ${NITRO_CLI_INSTALL_DIR}${UNIT_DIR}/nitro-enclaves-vsock-proxy.service
302328
$(INSTALL) -D -m 0644 vsock_proxy/configs/vsock-proxy.yaml ${NITRO_CLI_INSTALL_DIR}${CONF_DIR}/nitro_enclaves/vsock-proxy.yaml
303-
$(INSTALL) -D -m 0755 bootstrap/nitro-enclaves-allocator ${NITRO_CLI_INSTALL_DIR}${BIN_DIR}/nitro-enclaves-allocator
329+
$(INSTALL) -D -m 0755 $(OBJ_PATH)/allocator/release/nitro-enclaves-allocator ${NITRO_CLI_INSTALL_DIR}${BIN_DIR}/nitro-enclaves-allocator
304330
$(INSTALL) -D -m 0664 bootstrap/allocator.yaml ${NITRO_CLI_INSTALL_DIR}${CONF_DIR}/nitro_enclaves/allocator.yaml
305331
$(INSTALL) -D -m 0644 bootstrap/nitro-enclaves-allocator.service ${NITRO_CLI_INSTALL_DIR}${UNIT_DIR}/nitro-enclaves-allocator.service
306332
$(MKDIR) -p ${NITRO_CLI_INSTALL_DIR}${DATA_DIR}/nitro_enclaves/blobs

allocator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "allocator"
2+
name = "nitro-enclaves-allocator"
33
version = "0.1.0"
44
edition = "2021"
55

allocator/src/configuration.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ pub enum ResourcePoolConfig {
6868
/// Loads resource requirements from '/etc/nitro_enclaves/allocator.yaml'
6969
/// and returns a vector of resource pools for allocation.
7070
pub fn get_resource_pool_from_config() -> Result<Vec<ResourcePool>> {
71-
let f = std::fs::File::open("/etc/nitro_enclaves/allocator.yaml")?;
71+
let f = std::fs::File::open(format!(
72+
"{}/etc/nitro_enclaves/allocator.yaml",
73+
std::env::var("NITRO_CLI_INSTALL_DIR").unwrap_or("".to_string())
74+
))?;
7275
let config: ResourcePoolConfig =
7376
serde_yaml::from_reader(f).map_err(|_| Error::ConfigFileCorruption)?;
74-
7577
Ok(configure_resource_pool(config))
7678
}
7779
/// Processes the configuration into a consistent format

bootstrap/allocator.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ cpu_count: 2
1212
# Note: cpu_count and cpu_pool conflict with each other. Only use exactly one of them.
1313
# Example of reserving CPUs 2, 3, and 6 through 9:
1414
# cpu_pool: 2,3,6-9
15+
#
16+
# Allocator configuration for multiple enclaves
17+
# Each list item represents a separate enclave
18+
# Use YAML array like the example below.
19+
# Example:
20+
# - memory_mib: 512
21+
# cpu_count: 2
22+
# - memory_mib: 512
23+
# cpu_pool: 2,3,6-9
24+
# You can add more enclave configurations as needed.
25+
# Allocated Resources are not tied with enclaves.
26+
# It's a mechanism to separate resources from each other.

0 commit comments

Comments
 (0)