Skip to content

Commit

Permalink
Merge pull request #248 from threefoldtech/sshinit-update
Browse files Browse the repository at this point in the history
updating ssh-init script
  • Loading branch information
PeterNashaat authored May 16, 2024
2 parents d5d3eb9 + 46a2ddc commit 288ffdb
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 162 deletions.
8 changes: 1 addition & 7 deletions tfgrid3/alpine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ in the alpine-3 directory
### Running

```bash
docker run -dti -e SSH_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDL/IvQhp..." {user|org}/grid3_alpine:3
```

### Access using SSH
```bash
CONTAINER_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker container ls -lq))
ssh root@$CONTAINER_IP
docker run -dti {user|org}/grid3_alpine:3
```

## Deploying on grid 3
Expand Down
3 changes: 1 addition & 2 deletions tfgrid3/alpine/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ ssh-keygen -A

# add user key to authorized_keys
mkdir -p /root/.ssh
echo $SSH_KEY >> /root/.ssh/authorized_keys

# do not detach (-D), log to stderr (-e), passthrough other arguments
exec /usr/sbin/sshd -D -e "$@"
exec /usr/sbin/sshd -D -e "$@"
5 changes: 3 additions & 2 deletions tfgrid3/centos-8/Dockerfile → tfgrid3/centos-9/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM centos:8
FROM quay.io/centos/centos:stream9

RUN yum install -y openssh-server && yum clean all

COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
RUN rm -f /run/nologin
RUN /bin/echo -e "LANG=\"en_US.UTF-8\"">/etc/default/local

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
16 changes: 5 additions & 11 deletions tfgrid3/centos-8/README.md → tfgrid3/centos-9/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
# centos-8
# centos-stream9

## what in this image
- based on official docker centos 8
- based on Quay.io official CentOS stream 9
- include preinstalled openssh-server package.

## Building

in the centos-8 directory
in the centos-stream9 directory

`docker build -t {user|org}/grid3_centos:8 .`
`docker build -t {user|org}/grid3_centos:stream9 .`

## Testing
### Running

```bash
docker run -dti -e SSH_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDL/IvQhp..." {user|org}/grid3_centos:8
```

### Access using SSH
```bash
CONTAINER_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker container ls -lq))
ssh root@$CONTAINER_IP
docker run -dti {user|org}/grid3_centos:stream9
```

## Deploying on grid 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ ssh-keygen -A

# add user key to authorized_keys
mkdir -p /root/.ssh
echo $SSH_KEY >> /root/.ssh/authorized_keys

# do not detach (-D), log to stderr (-e), passthrough other arguments
exec /usr/sbin/sshd -D -e "$@"
exec /usr/sbin/sshd -D -e "$@"
2 changes: 0 additions & 2 deletions tfgrid3/debian/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ touch /root/.ssh/authorized_keys

chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys

echo "$SSH_KEY" >> /root/.ssh/authorized_keys
13 changes: 13 additions & 0 deletions tfgrid3/ubuntu22.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:22.04

RUN apt update && \
apt -y install wget openssh-server

RUN wget -O /sbin/zinit https://github.com/threefoldtech/zinit/releases/download/v0.2.5/zinit && \
chmod +x /sbin/zinit

COPY zinit /etc/zinit
COPY start.sh /start.sh

RUN chmod +x /sbin/zinit && chmod +x /start.sh
ENTRYPOINT ["zinit", "init"]
75 changes: 10 additions & 65 deletions tfgrid3/ubuntu22.04/README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,17 @@
# Creating Minimal Ubuntu Jammy FLIST : A Step-by-Step Guide

## Automated Process

**Script Name**: `ubuntu22-flist-builder.sh`

This script automates the setup, configuration, archiving, and uploading of an Ubuntu system ready for use as an FLIST.
# Development Guide for Ubuntu:22.04 image
## This guide will take you through steps for pulling & running ubuntu:22.04 image

### Pull the image
```bash
chmod +x ubuntu22-flist-builder.sh
./ubuntu22-flist-builder.sh ${your_api_key_here}
```

## Manual Process

### Install arch-install-scripts package to use arch-chroot
```
sudo apt install arch-install-scripts -y
```

### Setup and Bootstrap
```
mkdir ubuntu-jammy
sudo debootstrap jammy ubuntu-jammy http://archive.ubuntu.com/ubuntu
```
#### Enter the new environment using arch-chroot.
```
arch-chroot ubuntu-jammy/
```

### Configure the system PATH and networking settings, then update the package repository and install necessary packages.
```
export PATH=/usr/local/sbin/:/usr/local/bin/:/usr/sbin/:/usr/bin/:/sbin:/bin
rm /etc/resolv.conf
echo 'nameserver 1.1.1.1' > /etc/resolv.conf
apt-get update
apt-get install cloud-init openssh-server curl initramfs-tools -y
docker pull threefolddev/ubuntu:22.04
```

### Cloud-init and Kernel Modules
#### Prepare the system for cloud environments using cloud-init and install additional kernel modules.
```
cloud-init clean
apt-get install linux-modules-extra-5.15.0-25-generic -y
echo 'fs-virtiofs' >> /etc/initramfs-tools/modules
update-initramfs -c -k all
apt-get clean
```

### Clean up
```
rm -rf ubuntu-jammy/dev/*
```

### Kernel Extraction
```
sudo ./extract-vmlinux ubuntu-jammy/boot/vmlinuz | sudo tee ubuntu-jammy/boot/vmlinuz-5.15.0-25-generic.elf > /dev/null
sudo mv ubuntu-jammy/boot/vmlinuz-5.15.0-25-generic.elf ubuntu-jammy/boot/vmlinuz-5.15.0-25-generic
```

### Create a compressed archive of the configured system for uploading to hub.
```
tar -czf ubuntu-jammy.tar.gz -C ubuntu-jammy .
### Build the image
```bash
docker build -t threefolddev/ubuntu:22.04 .
```

### Uploading flist
#### From the hub you can generate api key to use
```
clsecret="$API_KEY"
curl -X Post -H "Authorization: Bearer ${clsecret}" -F "file=@ubuntu-jammy.tar.gz" https://hub.grid.tf/api/flist/me/upload
### RUN the image
```bash
sudo docker run -d --name <container_name> threefolddev/ubuntu:22.04
```

8 changes: 8 additions & 0 deletions tfgrid3/ubuntu22.04/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

mkdir -p /var/run/sshd
mkdir -p /root/.ssh
touch /root/.ssh/authorized_keys

chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
71 changes: 0 additions & 71 deletions tfgrid3/ubuntu22.04/ubuntu22-flist-builder.sh

This file was deleted.

3 changes: 3 additions & 0 deletions tfgrid3/ubuntu22.04/zinit/ssh-init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exec: bash /start.sh
log: stdout
oneshot: true
3 changes: 3 additions & 0 deletions tfgrid3/ubuntu22.04/zinit/sshd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exec: bash -c "/usr/sbin/sshd -D"
after:
- ssh-init

0 comments on commit 288ffdb

Please sign in to comment.