Skip to content

Build Enclave

Build Enclave #54

Workflow file for this run

name: Build Enclave
on:
workflow_dispatch:
inputs:
test_environment:
description: 'Select environment for testing'
required: true
default: 'staging'
jobs:
build-enclave:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Verify required files are present
run: |
if [[ ! -f Dockerfile || ! -f setup.sh || ! -f supervisord.conf ]]; then
echo "Required files (Dockerfile, setup.sh, supervisord.conf) are missing!"
exit 1
fi
- name: Move files to folder structure
run: |
# Ensure setup directory exists
mkdir -p setup
# Move files into setup/ directory if not already there
mv Dockerfile setup/ || echo "Dockerfile already in setup/"
mv setup.sh setup/ || echo "setup.sh already in setup/"
mv supervisord.conf setup/ || echo "supervisord.conf already in setup/"
# Check and add outer Dockerfile and entrypoint.sh if not present
if [ ! -f Dockerfile ]; then
echo "Creating outer Dockerfile"
cat <<EOF > Dockerfile
# base image
FROM marlinorg/nitro-cli
# working directory
WORKDIR /app/setup
# add files
COPY entrypoint.sh ./
RUN chmod +x entrypoint.sh
# entry point
ENTRYPOINT [ "/app/setup/entrypoint.sh" ]
EOF
fi
# Create entrypoint.sh if not present
if [ ! -f entrypoint.sh ]; then
echo "Creating entrypoint.sh"
cat <<EOF > entrypoint.sh
#!/bin/sh
dockerd &
sleep 10
# Determine architecture
ARCH=\$(uname -m)
if [ "\$ARCH" = "aarch64" ]; then
PLATFORM=linux/arm64
else
PLATFORM=linux/amd64
fi
docker buildx create --name multiplatformEnclave --driver docker-container --bootstrap
docker buildx use multiplatformEnclave
cd /app/mount/setup
docker buildx build --platform \$PLATFORM -t enclave:latest --load .
mkdir -p /app/mount/enclave
mkdir -p /var/log/nitro_enclaves
touch /var/log/nitro_enclaves/nitro_enclaves.log
nitro-cli build-enclave --docker-uri enclave:latest --output-file /app/mount/enclave/enclave.eif
EOF
chmod +x entrypoint.sh
fi
- name: Build and Run Enclave
run: |
docker build -t enclave .
docker run --privileged -v $(pwd):/app/mount enclave
- name: Verify enclave.eif file
id: verify_eif
run: |
echo "Searching for enclave.eif file..."
EIF_PATH=$(find / -name "enclave.eif" 2>/dev/null | head -n 1)
echo "EIF_PATH is set to: $EIF_PATH"
if [ -z "$EIF_PATH" ] || [ ! -f "$EIF_PATH" ]; then
echo "Error: enclave.eif file not found!"
exit 1
fi
echo "File found at $EIF_PATH"
echo "EIF_PATH=$EIF_PATH" >> $GITHUB_ENV
- name: Create GitHub Release and upload enclave.eif
id: create_release
run: |
TAG_NAME="v1.0.0" # You can adjust this dynamically based on input or versioning logic
RELEASE_NAME="Enclave Build $TAG_NAME"
BODY="This release contains the generated enclave.eif file."
# Create a GitHub release and upload the enclave.eif file
gh release create $TAG_NAME $EIF_PATH --title "$RELEASE_NAME" --notes "$BODY"
# Construct the release URL
REPO_URL="https://github.com/${{ github.repository }}"
RELEASE_URL="$REPO_URL/releases/tag/$TAG_NAME"
echo "RELEASE_URL=$RELEASE_URL" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Print Download URL
run: |
echo "The enclave.eif file can be downloaded from the release:"
echo "${{ env.RELEASE_URL }}"