From 7a6db4ce3f02668282df5a64538b47ec8aecf541 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Thu, 22 Feb 2024 12:33:15 +0100 Subject: [PATCH] Add entrypoint and cleanup scripts for github action Signed-off-by: Carlos Eduardo Arango Gutierrez --- Dockerfile | 7 +++++-- scripts/cleanup.sh | 29 +++++++++++++++++++++++++++++ scripts/run.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 scripts/cleanup.sh create mode 100755 scripts/run.sh diff --git a/Dockerfile b/Dockerfile index f1241e28..2fbd36a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,15 +12,18 @@ ## limitations under the License. ## -FROM golang:1.21 AS builder +FROM golang:1.21 WORKDIR /src COPY . . RUN make build +RUN install -m 755 /src/bin/holodeck /usr/local/bin/holodeck && \ + install -m 755 /src/scripts/run.sh /usr/local/bin/run.sh && \ + install -m 755 /src/scripts/cleanup.sh /usr/local/bin/cleanup.sh RUN echo "nobody:x:65534:65534:Nobody:/:" > /etc_passwd # Run as unprivileged user USER 65534:65534 -ENTRYPOINT ["/holodeck"] +ENTRYPOINT ["/usr/local/bin/run.sh"] diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh new file mode 100644 index 00000000..ccd039a6 --- /dev/null +++ b/scripts/cleanup.sh @@ -0,0 +1,29 @@ +## Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +#! /usr/bin/env bash +set +x + +export DEBIAN_FRONTEND=noninteractive + +if [ ! -d /github/workspace/.cache ]; then + echo "Cache directory not found in /workspace" + exit 1 +fi + +/user/bin/holodeck delete -f /github/workspace/$INPUT_HOLODECK_CONFIG -c /github/workspace/.cache + +rm -rf /github/workspace/.cache +rm -f /github/workspace/key.pem +rm -f /github/workspace/kubeconfig diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100755 index 00000000..9de2cef2 --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,44 @@ +## Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +#! /usr/bin/env bash +set +x + +export DEBIAN_FRONTEND=noninteractive + +if [ -n "$INPUT_HOLODECK_CONFIG" ]; then + if [ ! -f "/github/workspace/$INPUT_HOLODECK_CONFIG" ]; then + echo "Holodeck config file not found in /workspace" + exit 1 + fi +fi + +if [ -z "$INPUT_AWS_ACCESS_KEY_ID" ] || [ -z "$INPUT_AWS_SECRET_ACCESS_KEY" ]; then + echo "AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are not set" + exit 1 +fi + +export AWS_ACCESS_KEY_ID=$INPUT_AWS_ACCESS_KEY_ID +export AWS_SECRET_ACCESS_KEY=$INPUT_AWS_SECRET_ACCESS_KEY + +if [ -n "$SSH_KEY" ]; then + $(umask 077; echo "$SSH_KEY" > /github/workspace/key.pem) +fi + +mkdir -p /github/workspace/.cache + +/user/local/bin/holodeck create --provision \ + -f /github/workspace/$INPUT_HOLODECK_CONFIG \ + -c /github/workspace/.cache \ + -k /github/workspace/kubeconfig