2022-07-27 16:38:33 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-10-29 15:34:17 +00:00
|
|
|
set -eu
|
2022-07-27 16:38:33 +00:00
|
|
|
|
2022-08-20 21:44:37 +00:00
|
|
|
LXD_HOSTNAME="$1"
|
2022-07-27 16:38:33 +00:00
|
|
|
|
|
|
|
# generate the custom cloud-init file. Cloud init installs and configures sshd
|
|
|
|
SSH_AUTHORIZED_KEY=$(<"$SSH_HOME/id_rsa.pub")
|
|
|
|
eval "$(ssh-agent -s)"
|
|
|
|
ssh-add "$SSH_HOME/id_rsa"
|
|
|
|
export SSH_AUTHORIZED_KEY="$SSH_AUTHORIZED_KEY"
|
|
|
|
|
2022-08-20 21:44:37 +00:00
|
|
|
export FILENAME="$LXD_HOSTNAME.yml"
|
2022-08-24 14:09:09 +00:00
|
|
|
mkdir -p "$PROJECT_PATH/cloud-init"
|
|
|
|
YAML_PATH="$PROJECT_PATH/cloud-init/$FILENAME"
|
2022-07-27 16:38:33 +00:00
|
|
|
|
|
|
|
# If we are deploying the www, we attach the vm to the underlay via macvlan.
|
|
|
|
cat > "$YAML_PATH" <<EOF
|
2022-05-20 15:06:41 +00:00
|
|
|
config:
|
|
|
|
limits.cpu: "${DEV_CPU_COUNT}"
|
|
|
|
limits.memory: "${DEV_MEMORY_MB}MB"
|
2022-07-27 16:38:33 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# if VIRTUAL_MACHINE=sovereign-stack then we are building the base image.
|
2022-08-20 21:44:37 +00:00
|
|
|
if [ "$LXD_HOSTNAME" = "sovereign-stack" ]; then
|
2022-07-27 16:38:33 +00:00
|
|
|
# this is for the base image only...
|
|
|
|
cat >> "$YAML_PATH" <<EOF
|
2022-05-20 15:06:41 +00:00
|
|
|
user.vendor-data: |
|
|
|
|
#cloud-config
|
|
|
|
apt_mirror: http://us.archive.ubuntu.com/ubuntu/
|
|
|
|
package_update: true
|
|
|
|
package_upgrade: false
|
|
|
|
package_reboot_if_required: false
|
|
|
|
|
|
|
|
preserve_hostname: false
|
2022-07-27 16:38:33 +00:00
|
|
|
fqdn: sovereign-stack
|
2022-05-20 15:06:41 +00:00
|
|
|
|
|
|
|
packages:
|
|
|
|
- curl
|
|
|
|
- ssh-askpass
|
|
|
|
- apt-transport-https
|
|
|
|
- ca-certificates
|
|
|
|
- gnupg-agent
|
|
|
|
- software-properties-common
|
|
|
|
- lsb-release
|
|
|
|
- net-tools
|
|
|
|
- htop
|
|
|
|
- rsync
|
|
|
|
- duplicity
|
|
|
|
- sshfs
|
|
|
|
- fswatch
|
|
|
|
- jq
|
|
|
|
- git
|
|
|
|
- nano
|
2022-05-24 18:15:39 +00:00
|
|
|
- wait-for-it
|
2022-06-22 17:42:51 +00:00
|
|
|
- dnsutils
|
|
|
|
- wget
|
|
|
|
|
2022-05-20 15:06:41 +00:00
|
|
|
groups:
|
|
|
|
- docker
|
|
|
|
|
|
|
|
users:
|
|
|
|
- name: ubuntu
|
2022-06-22 17:42:51 +00:00
|
|
|
groups: docker
|
2022-05-20 15:06:41 +00:00
|
|
|
shell: /bin/bash
|
|
|
|
lock_passwd: false
|
2022-06-22 17:42:51 +00:00
|
|
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
2022-05-20 15:06:41 +00:00
|
|
|
ssh_authorized_keys:
|
|
|
|
- ${SSH_AUTHORIZED_KEY}
|
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
|
2022-05-20 15:06:41 +00:00
|
|
|
write_files:
|
2022-07-27 16:38:33 +00:00
|
|
|
- path: /home/ubuntu/docker.asc
|
2022-05-20 15:06:41 +00:00
|
|
|
content: |
|
|
|
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
|
|
|
|
|
|
mQINBFit2ioBEADhWpZ8/wvZ6hUTiXOwQHXMAlaFHcPH9hAtr4F1y2+OYdbtMuth
|
|
|
|
lqqwp028AqyY+PRfVMtSYMbjuQuu5byyKR01BbqYhuS3jtqQmljZ/bJvXqnmiVXh
|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4wbQmpCk
|
|
|
|
SVe2prlLureigXtmZfkqevRz7FrIZiu9ky8wnCAPwC7/zmS18rgP/17bOtL4/iIz
|
|
|
|
QhxAAoAMWVrGyJivSkjhSGx1uCojsWfsTAm11P7jsruIL61ZzMUVE2aM3Pmj5G+W
|
|
|
|
9AcZ58Em+1WsVnAXdUR//bMmhyr8wL/G1YO1V3JEJTRdxsSxdYa4deGBBY/Adpsw
|
|
|
|
24jxhOJR+lsJpqIUeb999+R8euDhRHG9eFO7DRu6weatUJ6suupoDTRWtr/4yGqe
|
|
|
|
dKxV3qQhNLSnaAzqW/1nA3iUB4k7kCaKZxhdhDbClf9P37qaRW467BLCVO/coL3y
|
|
|
|
Vm50dwdrNtKpMBh3ZpbB1uJvgi9mXtyBOMJ3v8RZeDzFiG8HdCtg9RvIt/AIFoHR
|
|
|
|
H3S+U79NT6i0KPzLImDfs8T7RlpyuMc4Ufs8ggyg9v3Ae6cN3eQyxcK3w0cbBwsh
|
|
|
|
/nQNfsA6uu+9H7NhbehBMhYnpNZyrHzCmzyXkauwRAqoCbGCNykTRwsur9gS41TQ
|
|
|
|
M8ssD1jFheOJf3hODnkKU+HKjvMROl1DK7zdmLdNzA1cvtZH/nCC9KPj1z8QC47S
|
|
|
|
xx+dTZSx4ONAhwbS/LN3PoKtn8LPjY9NP9uDWI+TWYquS2U+KHDrBDlsgozDbs/O
|
|
|
|
jCxcpDzNmXpWQHEtHU7649OXHP7UeNST1mCUCH5qdank0V1iejF6/CfTFU4MfcrG
|
|
|
|
YT90qFF93M3v01BbxP+EIY2/9tiIPbrd
|
|
|
|
=0YYh
|
|
|
|
-----END PGP PUBLIC KEY BLOCK-----
|
|
|
|
|
|
|
|
- path: /etc/ssh/ssh_config
|
|
|
|
content: |
|
2022-06-22 17:42:51 +00:00
|
|
|
Port 22
|
|
|
|
ListenAddress 0.0.0.0
|
|
|
|
Protocol 2
|
|
|
|
ChallengeResponseAuthentication no
|
|
|
|
PasswordAuthentication no
|
|
|
|
UsePAM no
|
|
|
|
LogLevel INFO
|
2022-05-20 15:06:41 +00:00
|
|
|
|
2022-05-24 18:15:39 +00:00
|
|
|
- path: /etc/docker/daemon.json
|
|
|
|
content: |
|
2022-06-22 17:42:51 +00:00
|
|
|
{
|
|
|
|
"registry-mirrors": [
|
|
|
|
"${REGISTRY_URL}"
|
|
|
|
]
|
|
|
|
}
|
2022-05-24 18:15:39 +00:00
|
|
|
|
2022-05-20 15:06:41 +00:00
|
|
|
runcmd:
|
2022-07-27 16:38:33 +00:00
|
|
|
- cat /home/ubuntu/docker.asc | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
|
|
|
- sudo rm /home/ubuntu/docker.asc
|
2022-05-20 15:06:41 +00:00
|
|
|
- echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
|
|
|
|
- sudo apt-get update
|
|
|
|
- sudo apt-get install -y docker-ce docker-ce-cli containerd.io
|
2022-07-27 16:38:33 +00:00
|
|
|
- echo "alias ll='ls -lah'" >> /home/ubuntu/.bash_profile
|
2022-06-22 17:42:51 +00:00
|
|
|
- sudo curl -s -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
2022-05-20 15:06:41 +00:00
|
|
|
- sudo chmod +x /usr/local/bin/docker-compose
|
|
|
|
- sudo apt-get install -y openssh-server
|
2022-07-27 16:38:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
else
|
|
|
|
# all other machines.
|
|
|
|
cat >> "$YAML_PATH" <<EOF
|
|
|
|
user.vendor-data: |
|
|
|
|
#cloud-config
|
|
|
|
apt_mirror: http://us.archive.ubuntu.com/ubuntu/
|
|
|
|
package_update: false
|
|
|
|
package_upgrade: false
|
|
|
|
package_reboot_if_required: false
|
|
|
|
|
|
|
|
preserve_hostname: false
|
|
|
|
fqdn: ${FQDN}
|
|
|
|
|
2022-08-19 19:30:30 +00:00
|
|
|
user.network-config: |
|
|
|
|
version: 2
|
|
|
|
ethernets:
|
|
|
|
enp5s0:
|
|
|
|
dhcp4: true
|
|
|
|
match:
|
|
|
|
macaddress: ${MAC_ADDRESS_TO_PROVISION}
|
|
|
|
set-name: enp5s0
|
|
|
|
|
|
|
|
enp6s0:
|
2022-08-20 21:42:38 +00:00
|
|
|
dhcp4: false
|
|
|
|
EOF
|
|
|
|
|
2022-08-24 14:11:50 +00:00
|
|
|
if [[ "$LXD_HOSTNAME" = $WWW_HOSTNAME-* ]]; then
|
2022-08-20 21:42:38 +00:00
|
|
|
cat >> "$YAML_PATH" <<EOF
|
|
|
|
addresses: [10.139.144.5/24]
|
|
|
|
nameservers:
|
|
|
|
addresses: [10.139.144.1]
|
2022-08-24 14:11:50 +00:00
|
|
|
|
2022-07-27 16:38:33 +00:00
|
|
|
EOF
|
2022-08-20 21:42:38 +00:00
|
|
|
fi
|
2022-05-20 15:06:41 +00:00
|
|
|
|
2022-08-24 14:11:50 +00:00
|
|
|
if [[ "$LXD_HOSTNAME" = $BTCPAY_HOSTNAME-* ]]; then
|
2022-08-20 21:42:38 +00:00
|
|
|
cat >> "$YAML_PATH" <<EOF
|
|
|
|
addresses: [10.139.144.10/24]
|
|
|
|
nameservers:
|
|
|
|
addresses: [10.139.144.1]
|
|
|
|
|
|
|
|
EOF
|
|
|
|
fi
|
2022-07-27 16:38:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If we are deploying the www, we attach the vm to the underlay via macvlan.
|
|
|
|
cat >> "$YAML_PATH" <<EOF
|
|
|
|
description: Default LXD profile for ${FILENAME}
|
2022-05-20 15:06:41 +00:00
|
|
|
devices:
|
|
|
|
root:
|
|
|
|
path: /
|
2022-06-22 17:42:51 +00:00
|
|
|
pool: sovereign-stack
|
2022-05-20 15:06:41 +00:00
|
|
|
type: disk
|
|
|
|
config:
|
|
|
|
source: cloud-init:config
|
|
|
|
type: disk
|
2022-07-27 16:38:33 +00:00
|
|
|
EOF
|
|
|
|
|
2022-08-24 14:11:50 +00:00
|
|
|
# Stub out the network piece for the base image.
|
2022-08-20 21:42:38 +00:00
|
|
|
if [ "$LXD_HOSTNAME" = sovereign-stack ] ; then
|
2022-07-27 16:38:33 +00:00
|
|
|
|
|
|
|
# If we are deploying the www, we attach the vm to the underlay via macvlan.
|
|
|
|
cat >> "$YAML_PATH" <<EOF
|
|
|
|
enp5s0:
|
2022-08-19 19:30:30 +00:00
|
|
|
name: enp5s0
|
2022-07-27 16:38:33 +00:00
|
|
|
nictype: macvlan
|
|
|
|
parent: ${DATA_PLANE_MACVLAN_INTERFACE}
|
|
|
|
type: nic
|
2022-08-15 13:35:01 +00:00
|
|
|
name: ${FILENAME}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
else
|
|
|
|
# If we are deploying the www, we attach the vm to the underlay via macvlan.
|
|
|
|
cat >> "$YAML_PATH" <<EOF
|
|
|
|
enp5s0:
|
|
|
|
nictype: macvlan
|
|
|
|
parent: ${DATA_PLANE_MACVLAN_INTERFACE}
|
2022-07-27 16:38:33 +00:00
|
|
|
type: nic
|
2022-08-19 19:30:30 +00:00
|
|
|
enp6s0:
|
|
|
|
name: enp6s0
|
|
|
|
network: lxdbrSS
|
|
|
|
type: nic
|
2022-08-15 13:35:01 +00:00
|
|
|
|
2022-07-27 16:38:33 +00:00
|
|
|
name: ${FILENAME}
|
|
|
|
EOF
|
|
|
|
|
2022-08-15 13:35:01 +00:00
|
|
|
fi
|
|
|
|
|
2022-07-27 16:38:33 +00:00
|
|
|
# let's create a profile for the BCM TYPE-1 VMs. This is per VM.
|
2022-08-20 21:44:37 +00:00
|
|
|
if ! lxc profile list --format csv | grep -q "$LXD_HOSTNAME"; then
|
|
|
|
lxc profile create "$LXD_HOSTNAME"
|
2022-07-27 16:38:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# configure the profile with our generated cloud-init.yml file.
|
2022-08-20 21:44:37 +00:00
|
|
|
cat "$YAML_PATH" | lxc profile edit "$LXD_HOSTNAME"
|