From 4f55cc78b19365705c7e7b93b6919d995391e15c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 24 Feb 2021 20:22:23 +0100 Subject: Move constants to dedicated module Signed-off-by: Matthias Beyer --- src/consts.rs | 22 ++++++++++++++++++++++ src/endpoint/configured.rs | 10 +++++----- src/main.rs | 1 + 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/consts.rs diff --git a/src/consts.rs b/src/consts.rs new file mode 100644 index 0000000..8891f81 --- /dev/null +++ b/src/consts.rs @@ -0,0 +1,22 @@ +// +// Copyright (c) 2020-2021 science+computing ag and other contributors +// +// This program and the accompanying materials are made +// available under the terms of the Eclipse Public License 2.0 +// which is available at https://www.eclipse.org/legal/epl-2.0/ +// +// SPDX-License-Identifier: EPL-2.0 +// + + +/// The path to the directory inside the container where the inputs for the script run are copied +/// to. +pub const INPUTS_DIR_PATH: &str = "/inputs"; + +/// The path to the directory inside the container where the outputs of a compile job must be +/// located after the script was run +pub const OUTPUTS_DIR_PATH: &str = "/outputs"; + +/// The path where the script that is executed inside the container is copied to. +pub const SCRIPT_PATH: &str = "/script"; + diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index b90263e..849a76c 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -343,7 +343,7 @@ impl<'a> PreparedContainer<'a> { .into_iter() .map(|entry| async { let source_path = entry.path(); - let destination = PathBuf::from("/inputs").join({ + let destination = PathBuf::from(crate::consts::INPUTS_DIR_PATH).join({ source_path .file_name() .ok_or_else(|| anyhow!("Not a file: {}", source_path.display())) @@ -402,7 +402,7 @@ impl<'a> PreparedContainer<'a> { container.id() ) })?; - let destination = PathBuf::from("/inputs/").join(artifact_file_name); + let destination = PathBuf::from(crate::consts::INPUTS_DIR_PATH).join(artifact_file_name); trace!( "Copying {} to container: {}:{}", art.display(), @@ -456,7 +456,7 @@ impl<'a> PreparedContainer<'a> { container: &Container<'ca>, script: &Script, ) -> Result<()> { - let script_path = PathBuf::from("/script"); + let script_path = PathBuf::from(crate::consts::SCRIPT_PATH); container .copy_file_into(script_path, script.as_ref().as_bytes()) .await @@ -637,9 +637,9 @@ impl<'a> ExecutedContainer<'a> { Some((true, _)) | None => { let container = self.endpoint.docker.containers().get(&self.create_info.id); - trace!("Fetching /outputs from container {}", self.create_info.id); + trace!("Fetching {} from container {}", crate::consts::OUTPUTS_DIR_PATH, self.create_info.id); let tar_stream = container - .copy_from(&PathBuf::from("/outputs/")) + .copy_from(&PathBuf::from(crate::consts::OUTPUTS_DIR_PATH)) .map(|item| { item.with_context(|| { anyhow!( diff --git a/src/main.rs b/src/main.rs index 50bbe4a..1c1f838 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,6 +63,7 @@ use funty as _; // doc-helper crate mod cli; mod commands; mod config; +mod consts; mod db; mod endpoint; mod filestore; -- cgit v1.2.3