Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:fix some wrong situation and update dockerfile for ceseal #360

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
"pallets/mq/runtime-api",
"standalone/chain/*",
"standalone/teeworker/cifrost",
"standalone/handover",
"standalone/teeworker/handover",
]

resolver = "2"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ node:
cifrost:
cargo build -p cifrost ${XARGS}
handover:
cargo build -p handover ${XARGS}
cargo build -p handover --release
ceseal:
make -C standalone/teeworker/ceseal
test:
Expand Down
12 changes: 7 additions & 5 deletions scripts/docker/ceseal/gramine/handover.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN <<EOF
mkdir prebuilt
EOF

COPY ./scripts/docker/cargo-config.toml /usr/local/cargo/config
# COPY ./scripts/docker/cargo-config.toml /usr/local/cargo/config
COPY pallets ./cess-code/pallets
COPY crates ./cess-code/crates
COPY standalone ./cess-code/standalone
Expand All @@ -32,8 +32,11 @@ ENV VERGEN_GIT_SHA=${GIT_SHA}

RUN <<EOF
set -e
cd cess-code/standalone/teeworker/ceseal/gramine-build
PATH=$PATH:/root/.cargo/bin
cd /root/cess-code
make handover
cp ./target/release/handover /root/prebuilt
cd /root/cess-code/standalone/teeworker/ceseal/gramine-build
make dist PREFIX=/root/prebuilt
make clean
rm -rf /root/.cargo/registry
Expand All @@ -42,7 +45,7 @@ EOF

# ====== runtime ======

FROM cesslab/intel-sgx-deno-env:latest AS runtime
FROM cesslab/intel-sgx-env:latest AS runtime

ARG https_proxy
ARG http_proxy
Expand All @@ -56,15 +59,14 @@ ARG REAL_CESEAL_DATA_DIR=${CESEAL_HOME}/data/${CESEAL_VERSION}
COPY --from=builder /root/prebuilt/ ${CESEAL_DIR}
ADD --chmod=0755 ./scripts/docker/ceseal/gramine/start.sh ${CESEAL_DIR}/start.sh
ADD --chmod=0755 ./scripts/docker/ceseal/gramine/start-with-handover.sh ${CESEAL_HOME}/start.sh
ADD ./scripts/docker/ceseal/gramine/handover.ts ${CESEAL_HOME}/handover.ts


RUN <<EOF
set -e
ln -s ${CESEAL_DIR} ${CESEAL_HOME}/releases/current
mkdir -p ${REAL_CESEAL_DATA_DIR}
rm -rf ${CESEAL_DIR}/data
ln -s ${REAL_CESEAL_DATA_DIR} ${CESEAL_DIR}/data
deno cache --reload ${CESEAL_HOME}/handover.ts
EOF

WORKDIR ${CESEAL_HOME}/releases/current
Expand Down
9 changes: 2 additions & 7 deletions scripts/docker/ceseal/gramine/start-with-handover.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't need the deno anymore. so the runtime image base better change to cesslab/intel-sgx-env.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,5 @@ if [ "$SGX" -eq 1 ] && [ "$SKIP_AESMD" -eq 0 ]; then
fi
fi

cd /opt/ceseal && deno run --allow-all handover.ts
if [ $? -eq 0 ]
then
cd /opt/ceseal/releases/current && SKIP_AESMD=1 ./start.sh
else
exit 1
fi
./handover
cd /opt/ceseal/releases/current && SKIP_AESMD=1 ./start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ async fn main() {
.expect("wait for previous ceseal log fail");
log(format!("previous ceseal started!"));

let current_ceseal_storage_path =
Path::new(&args.current_version_ceseal_path).join(&args.ceseal_storage_files_path);
let previous_ceseal_storage_path = previous_ceseal_path.join(&args.ceseal_storage_files_path);
ensure_data_dir(current_ceseal_storage_path.parent().unwrap().to_str().unwrap())
let current_ceseal_real_storage_path =
Path::new(&args.ceseal_data_path).join(&current_version.to_string());
ensure_data_dir(&current_ceseal_real_storage_path)
.await
.expect("ensure current data dir fail");

Expand Down Expand Up @@ -141,6 +140,9 @@ async fn main() {
old_process.kill().await.expect("old ceseal stop fail");
kill_previous_ceseal(previous_version).await;

let current_ceseal_storage_path =
Path::new(&args.current_version_ceseal_path).join(&args.ceseal_storage_files_path);
let previous_ceseal_storage_path = previous_ceseal_path.join(&args.ceseal_storage_files_path);
match tokio::fs::remove_dir_all(&current_ceseal_storage_path).await {
Ok(_) => log("Removed current storage successfully.".to_string()),
Err(e) => eprintln!("Error removing previous storage: {}", e),
Expand Down Expand Up @@ -300,19 +302,19 @@ pub async fn confirm_previous_ceseal_version(
Ok(previous_version)
}

async fn ensure_data_dir(data_dir: &str) -> Result<(), std::io::Error> {
if !Path::new(data_dir).exists() {
async fn ensure_data_dir(data_dir: &Path) -> Result<(), std::io::Error> {
if !data_dir.exists() {
tokio::fs::create_dir_all(data_dir).await?;
}

// Create the protected_files subdirectory if it does not exist
let protected_files_dir = Path::new(data_dir).join("protected_files");
let protected_files_dir = data_dir.join("protected_files");
if !protected_files_dir.exists() {
tokio::fs::create_dir_all(&protected_files_dir).await?;
log("create protected file for current ceseal...".to_string())
}

let storage_files_dir = Path::new(data_dir).join("storage_files");
let storage_files_dir = data_dir.join("storage_files");
if !storage_files_dir.exists() {
tokio::fs::create_dir_all(&storage_files_dir).await?;
log("create storage file for current ceseal...".to_string())
Expand Down
Loading