Skip to content

Commit

Permalink
This simplifies the stand-up of a sandbox:
Browse files Browse the repository at this point in the history
Only 2 main Vagrant calls are now needed (`vagrant up` and `vagrant up machine1`).
This PR only updates the Vagrant Virtualbox setup. The Vagrant Libvirt and Terraform
still need to be updated.

This uses docker-compose as the entry point for standing up the stack and makes the stand-up
of the sandbox more portal. Vagrant and Terraform are only responsible for standing up infrastructure
and then running docker-compose, not for running any glue scripts.

The docker-compose calls out to single-shot services to do all the glue required to get the fully
functional Tinkerbell stack up and running. All the single-shot services are idempotent.
This increases portability and the development iteration loop. This also simplifies the required
steps needed to get a fully functioning sandbox up and running.

This is intended to help people looking to get started by getting them to a provisioned
machine quicker and more easily.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Jul 16, 2021
1 parent 1ebcf48 commit 5fa17f1
Show file tree
Hide file tree
Showing 58 changed files with 1,855 additions and 1,020 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: "1.15.5"
- run: ./script/release-binaries.sh
- run: ./releases/script/release-binaries.sh
name: get binaries
- name: Create Release
id: create_release
Expand All @@ -30,4 +30,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ github.token }}
with:
asset_paths: '["./out/release/*"]'
asset_paths: '["./releases/out/release/*"]'
3 changes: 2 additions & 1 deletion .github/workflows/vagrant-packet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ jobs:
- name: Vagrant Test
run: |
export VAGRANT_DEFAULT_PROVIDER="virtualbox"
go test --timeout 1h -v ./test/vagrant
cd ./test/vagrant
go test --timeout 1h -v ./
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
envrc
out
.env
!deploy/.env
.vagrant
deploy/state/webroot/misc/osie/current/*
deploy/state/webroot/workflow/*
!deploy/state/webroot/misc/osie/current/.keep
!deploy/state/webroot/workflow/.keep
deploy/state/webroot/*.gz
workflow_id.txt
14 changes: 14 additions & 0 deletions QuickStart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Quick-Starts

The following quick-start guides will walk you through standing up the Tinkerbell stack.
There are a few options for this.
Pick the one that works best for you.

## Options

- [Vagrant and VirtualBox](docs/quickstarts/VAGRANTVBOX.md)
- [Vagrant and Libvirt](docs/quickstarts/VAGRANTLVIRT.md)
- [Docker Compose](docs/quickstarts/COMPOSE.md)
- [Terraform and Equinix Metal](docs/quickstarts/TERRAFORMEM.md)
- [Kubernetes](docs/quickstarts/KUBERNETES.md)
- [Multipass](docs/quickstarts/MULTIPASS.md)
8 changes: 8 additions & 0 deletions deploy/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
OSIE_DOWNLOAD_URL="https://tinkerbell-oss.s3.amazonaws.com/osie-uploads/osie-v0-n=404,c=c35a5f8,b=master.tar.gz"
TINK_CLI_IMAGE="quay.io/tinkerbell/tink-cli:sha-8ea8a0e5"
TINK_SERVER_IMAGE="quay.io/tinkerbell/tink:sha-8ea8a0e5"
BOOTS_SERVER_IMAGE="quay.io/tinkerbell/boots:sha-cb0290f8"
HEGEL_SERVER_IMAGE="quay.io/tinkerbell/hegel:sha-9f5da0a8"
TINKERBELL_HOST_IP=192.168.50.4
TINKERBELL_CLIENT_IP=192.168.50.43
TINKERBELL_CLIENT_MAC=08:00:27:9E:F5:3A
1 change: 0 additions & 1 deletion deploy/.gitignore

This file was deleted.

85 changes: 85 additions & 0 deletions deploy/compose/manifests/apply_manifests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env sh
# shellcheck disable=SC2039,SC2155,SC2086

set -x

# update_hw_ip_addr the hardware json with a specified IP address
update_hw_ip_addr() {
local ip_address="$1"
local hw_file="$2"
sed -i "s/\"address\":.*,/\"address\": \"${ip_address}\",/" "${hw_file}"
}

# update_hw_mac_addr the hardware json with a specified MAC address
update_hw_mac_addr() {
local mac_address="$1"
local hw_file="$2"
sed -i "s/\"mac\":.*,/\"mac\": \"${mac_address}\",/" "${hw_file}"
}

# hardware creates a hardware record in tink from the file_loc provided
hardware() {
local file_loc="$1"
tink hardware push --file "${file_loc}"
}

# update_template_img_ip the template yaml with a specified IP address
update_template_img_ip() {
local ip_address="$1"
local template_file="$2"
sed -i "s,IMG_URL: \"http://.*,IMG_URL: \"http://${ip_address}:8080/focal-server-cloudimg-amd64.raw.gz\"," "${template_file}"
}

# template create a template record in tink from the file_loc provided
template() {
local file_loc="$1"
tink template create --file "${file_loc}"
}

# workflow creates a workflow record in tink from the hardware and template records
workflow() {
local workflow_dir="$1"
local mac_address="$2"
local mac=$(echo "${mac_address}" | tr '[:upper:]' '[:lower:]')
local template_id=$(tink template get --no-headers 2>/dev/null | grep -v "+" | cut -d" " -f2 | xargs)
tink workflow create --template "${template_id}" --hardware "{\"device_1\":\"${mac}\"}" | tee "${workflow_dir}"/workflow_id.txt
# write just the workflow id to a file. `|| true` is a failsafe in case the workflow creation fails
sed -i 's/Created Workflow: //g' ${workflow_dir}/workflow_id.txt || true
}

# workflow_exists checks if a workflow record exists in tink before creating a new one
workflow_exists() {
local workflow_dir="$1"
local mac_address="$2"
if [ ! -f "${workflow_dir}"/workflow_id.txt ]; then
workflow "${workflow_dir}" "${mac_address}"
return 0
fi
local workflow_id=$(cat "${workflow_dir}"/workflow_id.txt)
tink workflow get | grep -q "${workflow_id}"
local result=$?
if [ "${result}" -ne 0 ]; then
workflow "${workflow_dir}" "${mac_address}"
else
echo "Workflow [$(cat "${workflow_dir}"/workflow_id.txt)] already exists"
fi
}

# main runs the creation functions in order
main() {
local hw_file="$1"
local template_file="$2"
local workflow_dir="$3"
local ip_address="$4"
local client_ip_address="$5"
local client_mac_address="$6"

update_hw_ip_addr "${client_ip_address}" "${hw_file}"
update_hw_mac_addr "${client_mac_address}" "${hw_file}"
hardware "${hw_file}"
update_template_img_ip "${ip_address}" "${template_file}"
template "${template_file}"
workflow_exists "${workflow_dir}" "${client_mac_address}"
}

main "$1" "$2" "$3" "$4" "$5" "$6"
31 changes: 31 additions & 0 deletions deploy/compose/manifests/hardware/hardware.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "0eba0bf8-3772-4b4a-ab9f-6ebe93b90a94",
"metadata": {
"facility": {
"facility_code": "onprem",
"plan_slug": "c2.medium.x86",
"plan_version_slug": ""
},
"instance": {},
"state": "provisioning"
},
"network": {
"interfaces": [
{
"dhcp": {
"arch": "x86_64",
"ip": {
"address": "192.168.50.43",
"netmask": "255.255.255.0"
},
"mac": "08:00:27:9E:F5:3A",
"uefi": false
},
"netboot": {
"allow_pxe": true,
"allow_workflow": true
}
}
]
}
}
76 changes: 76 additions & 0 deletions deploy/compose/manifests/template/ubuntu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
version: "0.1"
name: debian_Focal
global_timeout: 1800
tasks:
- name: "os-installation"
worker: "{{.device_1}}"
volumes:
- /dev:/dev
- /dev/console:/dev/console
- /lib/firmware:/lib/firmware:ro
actions:
- name: "stream-ubuntu-image"
image: image2disk:v1.0.0
timeout: 600
environment:
DEST_DISK: /dev/sda
IMG_URL: "http://192.168.50.4:8080/focal-server-cloudimg-amd64.raw.gz"
COMPRESSED: true
- name: "install-openssl"
image: cexec:v1.0.0
timeout: 90
environment:
BLOCK_DEVICE: /dev/sda1
FS_TYPE: ext4
CHROOT: y
DEFAULT_INTERPRETER: "/bin/sh -c"
CMD_LINE: "apt -y update && apt -y install openssl"
- name: "create-user"
image: cexec:v1.0.0
timeout: 90
environment:
BLOCK_DEVICE: /dev/sda1
FS_TYPE: ext4
CHROOT: y
DEFAULT_INTERPRETER: "/bin/sh -c"
CMD_LINE: "useradd -p $(openssl passwd -1 tink) -s /bin/bash -d /home/tink/ -m -G sudo tink"
- name: "enable-ssh"
image: cexec:v1.0.0
timeout: 90
environment:
BLOCK_DEVICE: /dev/sda1
FS_TYPE: ext4
CHROOT: y
DEFAULT_INTERPRETER: "/bin/sh -c"
CMD_LINE: "ssh-keygen -A; systemctl enable ssh.service; sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config"
- name: "disable-apparmor"
image: cexec:v1.0.0
timeout: 90
environment:
BLOCK_DEVICE: /dev/sda1
FS_TYPE: ext4
CHROOT: y
DEFAULT_INTERPRETER: "/bin/sh -c"
CMD_LINE: "systemctl disable apparmor; systemctl disable snapd"
- name: "write-netplan"
image: writefile:v1.0.0
timeout: 90
environment:
DEST_DISK: /dev/sda1
FS_TYPE: ext4
DEST_PATH: /etc/netplan/config.yaml
CONTENTS: |
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: true
enp0s8:
dhcp4: true
ens33:
dhcp4: true
UID: 0
GID: 0
MODE: 0644
DIRMODE: 0755
Empty file.
47 changes: 47 additions & 0 deletions deploy/compose/osie/lastmile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env sh
# shellcheck disable=SC2039

# osie_download from url and save it to directory
osie_download() {
local url="$1"
local directory="$2"
wget "${url}" -O "${directory}"/osie.tar.gz
}

# osie_extract from tarball and save it to directory
osie_extract() {
local source_dir="$1"
local dest_dir="$2"
tar -zxvf "${source_dir}"/osie.tar.gz -C "${dest_dir}" --strip-components 1
}

# osie_move_helper_scripts moves workflow helper scripts to the workflow directory
osie_move_helper_scripts() {
local source_dir="$1"
local dest_dir="$2"
cp "${source_dir}"/workflow-helper.sh "${source_dir}"/workflow-helper-rc "${dest_dir}"/
}

# main runs the functions in order to download, extract, and move helper scripts
main() {
local url="$1"
local extract_dir="$2"
local source_dir="$3"
local dest_dir="$4"

if [ ! -f "${extract_dir}"/osie.tar.gz ]; then
echo "downloading osie..."
osie_download "${url}" "${extract_dir}"
else
echo "osie already downloaded"
fi
if [ ! -f "${source_dir}"/workflow-helper.sh ] && [ ! -f "${source_dir}"/workflow-helper-rc ]; then
echo "extracting osie..."
osie_extract "${extract_dir}" "${source_dir}"
else
echo "osie files already exist, not extracting"
fi
osie_move_helper_scripts "${source_dir}" "${dest_dir}"
}

main "$1" "$2" "$3" "$4"
4 changes: 4 additions & 0 deletions deploy/compose/registry/registry_images.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
quay.io/tinkerbell/tink-worker:latest
quay.io/tinkerbell-actions/image2disk:v1.0.0
quay.io/tinkerbell-actions/cexec:v1.0.0
quay.io/tinkerbell-actions/writefile:v1.0.0
19 changes: 19 additions & 0 deletions deploy/compose/registry/upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# shellcheck disable=SC2001,SC2155,SC2046

set -x

main() {
local reg_user="$1"
local reg_pw="$2"
local reg_url="$3"
local images_file="$4"
# this confusing IFS= and the || is to capture the last line of the file if there is no newline at the end
while IFS= read -r img || [ -n "${img}" ]; do
# trim trailing whitespace
local imgr="$(echo "${img}" | sed 's/ *$//g')"
skopeo copy --all --dest-tls-verify=false --dest-creds="${reg_user}":"${reg_pw}" docker://"${imgr}" docker://"${reg_url}"/$(basename "${imgr}")
done <"${images_file}"
}

main "$1" "$2" "$3" "$4"
43 changes: 43 additions & 0 deletions deploy/compose/ubuntu/setup_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

install_deps() {
apt -y update
DEBIAN_FRONTEND=noninteractive apt -y install qemu-utils wget gzip
}

download_image() {
local url="$1"
wget "${url}"
}

img_to_raw() {
local img_file="$1"
local raw_file="$2"
qemu-img convert "${img_file}" -O raw "${raw_file}"
}

compress_raw() {
local raw_file="$1"
gzip "${raw_file}"
}

cleanup() {
local img_file="$1"
rm -rf "${img_file}"
}

main() {
local image_url="$1"
local img_file="$2"
local raw_file="$3"

if [ ! -f "${raw_file}.gz" ]; then
install_deps
download_image "${image_url}"
img_to_raw "${img_file}" "${raw_file}"
compress_raw "${raw_file}"
cleanup "${img_file}"
fi
}

main "$1" "$2" "$3"
Loading

0 comments on commit 5fa17f1

Please sign in to comment.