Skip to content

added nvm runtime config #3

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions create-aleph-nvm-runtime/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM debian:stable

ARG OUTPUT_PATH
ENV OUTPUT_PATH=$OUTPUT_PATH

RUN apt-get update

RUN apt-get install -y build-essential zlib1g-dev libncurses5-dev \
libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev \
debootstrap squashfs-tools

# Install Python3
RUN apt-get install -y python3 python3-pip

# Copy runtime files (TODO: add feature to get the last runtime version from git)
COPY runtime /app/runtime

RUN chmod +x /app/runtime/create_disk_image.sh

VOLUME /tmp

ENTRYPOINT ["/app/runtime/create_disk_image.sh"]
21 changes: 21 additions & 0 deletions create-aleph-nvm-runtime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Hello world docker action

This action prints "Hello World" or "Hello" + the name of a person to greet to the log.

## Inputs

## `who-to-greet`

**Required** The name of the person to greet. Default `"World"`.

## Outputs

## `time`

The time we greeted you.

## Example usage

uses: actions/hello-world-docker-action@v1
with:
who-to-greet: 'Mona the Octocat'
13 changes: 13 additions & 0 deletions create-aleph-nvm-runtime/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# action.yml
name: 'Create Aleph NVM Runtime'
description: 'Create Aleph NVM Runtime'
inputs:
output_path:
description: 'Path to save the runtime filesystem'
required: false
default: '/tmp/rootfs.squashfs'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.output_path }}
110 changes: 110 additions & 0 deletions create-aleph-nvm-runtime/runtime/create_disk_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

rm ./rootfs.squashfs

set -euf

rm -fr ./rootfs
mkdir ./rootfs

debootstrap --variant=minbase bullseye ./rootfs http://deb.debian.org/debian/

chroot ./rootfs /bin/sh <<EOT

set -euf

apt-get install -y --no-install-recommends --no-install-suggests \
python3-minimal \
openssh-server \
socat libsecp256k1-0 \
python3-aiohttp python3-msgpack \
python3-setuptools \
python3-pip python3-cytoolz python3-pydantic \
iproute2 unzip \
build-essential python3-dev \
iputils-ping \
cgroupfs-mount nftables \
curl

pip3 install 'fastapi~=0.71.0'

echo "Pip installing aleph-client"
pip3 install 'aleph-client>=0.4.6' 'coincurve==15.0.0'

# Compile all Python bytecode
python3 -m compileall -f /usr/local/lib/python3.9

# install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash

echo "root:toor" | /usr/sbin/chpasswd

mkdir -p /overlay

# Set up a login terminal on the serial console (ttyS0):
ln -s agetty /etc/init.d/agetty.ttyS0
echo ttyS0 > /etc/securetty
EOT

cat <<EOT > ./rootfs/etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOT

# In case we want to pre-install the latest lts version (v18.18.0)
chroot ./rootfs /bin/bash <<EOT
. /root/.bashrc
nvm install v18.18.0
nvm use v18.18.0
node -v
npm -v
EOT

echo "PermitRootLogin yes" >> ./rootfs/etc/ssh/sshd_config

cat <<EOT > ./rootfs/etc/inittab
# /etc/inittab

::sysinit:/sbin/init sysinit
::sysinit:/sbin/init boot
::wait:/sbin/init default

# Set up a couple of getty's
tty1::respawn:/sbin/getty 38400 tty1
tty2::respawn:/sbin/getty 38400 tty2
tty3::respawn:/sbin/getty 38400 tty3
tty4::respawn:/sbin/getty 38400 tty4
tty5::respawn:/sbin/getty 38400 tty5
tty6::respawn:/sbin/getty 38400 tty6

# Put a getty on the serial port
ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100

# Stuff to do for the 3-finger salute
::ctrlaltdel:/sbin/reboot

# Stuff to do before rebooting
::shutdown:/sbin/init shutdown
EOT

# Reduce size
rm -fr ./rootfs/root/.cache
rm -fr ./rootfs/var/cache
mkdir -p ./rootfs/var/cache/apt/archives/partial
rm -fr ./rootfs/usr/share/doc
rm -fr ./rootfs/usr/share/man
rm -fr ./rootfs/var/lib/apt/lists/

# Custom init
cp /app/runtime/init0.sh ./rootfs/sbin/init
cp /app/runtime/init1.py ./rootfs/root/init1.py
cp /app/runtime/run.sh ./rootfs/root/run.sh

chmod +x ./rootfs/sbin/init
chmod +x ./rootfs/root/init1.py
chmod +x ./rootfs/root/run.sh

# cp -r ./rootfs/ /tmp/rootfs
mksquashfs ./rootfs/ /tmp/rootfs.squashfs
49 changes: 49 additions & 0 deletions create-aleph-nvm-runtime/runtime/init0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh

set -euf

mount -t proc proc /proc -o nosuid,noexec,nodev

log() {
echo "$(cat /proc/uptime | awk '{printf $1}')" '|S' "$@"
}
log "init0.sh is launching"

# Switch root from read-only ext4 to to read-write overlay
mkdir -p /overlay
/bin/mount -t tmpfs -o noatime,mode=0755 tmpfs /overlay
mkdir -p /overlay/root /overlay/work
/bin/mount -o noatime,lowerdir=/,upperdir=/overlay/root,workdir=/overlay/work -t overlay "overlayfs:/overlay/root" /mnt
mkdir -p /mnt/rom
pivot_root /mnt /mnt/rom

mount --move /rom/proc /proc
mount --move /rom/dev /dev

mkdir -p /dev/pts
mkdir -p /dev/shm

mount -t sysfs sys /sys -o nosuid,noexec,nodev
mount -t tmpfs run /run -o mode=0755,nosuid,nodev
#mount -t devtmpfs dev /dev -o mode=0755,nosuid
mount -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
mount -t tmpfs shm /dev/shm -omode=1777,nosuid,nodev

# List block devices
lsblk

#cat /proc/sys/kernel/random/entropy_avail

# TODO: Move in init1
mkdir -p /run/sshd
/usr/sbin/sshd &
log "SSH UP"

log "Setup socat"
socat UNIX-LISTEN:/tmp/socat-socket,fork,reuseaddr VSOCK-CONNECT:2:53 &
log "Socat ready"

export PATH=$PATH:/usr/local/bin:/usr/bin:/usr/sbin

# Replace this script with the manager
exec /root/init1.py
Loading