Skip to content

Commit

Permalink
Consolidate install stages into one script (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-mkaar authored Jun 16, 2022
1 parent db188cd commit 4f26ca4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 48 deletions.
11 changes: 1 addition & 10 deletions foundry-appliance.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,7 @@ build {
"APPLIANCE_VERSION=${var.appliance_version}",
"SSH_USERNAME=${var.ssh_username}",
]
script = "install/stage1"
}

provisioner "shell" {
script = "install/stage2"
}

provisioner "shell" {
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'"
script = "install/stage3"
script = "setup-appliance"
}

provisioner "shell" {
Expand Down
14 changes: 0 additions & 14 deletions install/stage2

This file was deleted.

18 changes: 0 additions & 18 deletions install/stage3

This file was deleted.

28 changes: 22 additions & 6 deletions install/stage1 → setup-appliance
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Released under a BSD (SEI)-style license, please see LICENSE.md in the
# project root or contact [email protected] for full terms.
#
# Foundry Appliance Install - Stage 1
# Foundry Appliance Setup
#

echo "$APPLIANCE_VERSION" > /etc/appliance_version
Expand Down Expand Up @@ -65,9 +65,9 @@ mkdir -p /etc/rancher/k3s
echo "nameserver 10.0.1.1" >> /etc/rancher/k3s/resolv.conf
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.23.6+k3s1" INSTALL_K3S_EXEC="--disable traefik --disable servicelb --resolv-conf /etc/rancher/k3s/resolv.conf" sh -
sudo -u $SSH_USERNAME mkdir ~/.kube
cp /etc/rancher/k3s/k3s.yaml /home/$SSH_USERNAME/.kube/config
sed -i 's/default/foundry/g' /home/$SSH_USERNAME/.kube/config
chown $SSH_USERNAME:$SSH_USERNAME /home/$SSH_USERNAME/.kube/config
cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sed -i 's/default/foundry/g' ~/.kube/config
chown $SSH_USERNAME:$SSH_USERNAME ~/.kube/config

# Install CFSSL for certificate generation
curl -sLo /usr/local/bin/cfssl https://github.com/cloudflare/cfssl/releases/download/v1.6.1/cfssl_1.6.1_linux_amd64
Expand All @@ -82,8 +82,8 @@ sudo -u $SSH_USERNAME git clone https://github.com/jaggedmountain/k-alias.git
chmod -x /etc/update-motd.d/00-header
chmod -x /etc/update-motd.d/10-help-text
sed -i -r 's/(ENABLED=)1/\10/' /etc/default/motd-news
cp /home/foundry/$SSH_USERNAME/foundry-banner /etc/update-motd.d/05-foundry-banner
rm /home/foundry/$SSH_USERNAME/foundry-banner
cp ~/foundry/foundry-banner /etc/update-motd.d/05-foundry-banner
rm ~/foundry/foundry-banner
sed -i "s/{version}/$APPLIANCE_VERSION/" ~/mkdocs/docs/index.md
echo -e "Foundry Appliance $APPLIANCE_VERSION \\\n \l \n" > /etc/issue

Expand All @@ -103,3 +103,19 @@ ExecStart=configure-nic
WantedBy=multi-user.target
EOF
systemctl enable configure-nic

# Generate SSH key
sudo -u $SSH_USERNAME ssh-keygen -t rsa -f ~/.ssh/id_rsa -q -N ''

# Generate CA and host certificates
sudo -u $SSH_USERNAME ~/foundry/certs/generate-certs -loglevel 3

# Add newly generated CA certificate to trusted roots
cp ~/foundry/certs/root-ca.pem /usr/local/share/ca-certificates/foundry-appliance-root-ca.crt
update-ca-certificates

# Restart mDNS daemon to avoid conflict with other hosts
systemctl restart avahi-daemon

# Delete Ubuntu machine ID for proper DHCP operation on deploy
echo -n > /etc/machine-id

0 comments on commit 4f26ca4

Please sign in to comment.