Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

[Do Not Merge] Add LXD container build scripts for ACA #279

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion alcor
Submodule alcor updated 1508 files
73 changes: 73 additions & 0 deletions build/lxd-container/build-lxd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

# MIT License
# Copyright(c) 2020 Futurewei Cloud
#
# Permission is hereby granted,
# free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


function install_distrobuilder {
apt update &&\
apt install -y debootstrap rsync gpg squashfs-tools git

# install golang
wget https://go.dev/dl/go1.18.2.linux-amd64.tar.gz
rm -rf /usr/local/go &&\
tar -C /usr/local -xzf go1.18.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
rm go1.18.2.linux-amd64.tar.gz

# install distobuilder
git clone https://github.com/lxc/distrobuilder
cd ./distrobuilder
make
cd ..
rm -rf ./distrobuilder
}

function build_aca_lxc {
BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo "build path is $BUILD"
DEP_PATH="/var/local/git"

$HOME/go/bin/distrobuilder build-lxd lxd.yaml && \
lxc image import lxd.tar.xz rootfs.squashfs --alias aca && \
rm -rf lxd.tar.xz \
rootfs.squashfs \
*.service \
ignite && \
lxc launch aca aca
lxc exec aca -- bash -c "chmod +x /root/aca/build/aca-machine-init.sh"
lxc exec aca -- bash -c "/root/aca/build/aca-machine-init.sh"
chown -R lxd /etc/run/openvswitch
lxc config device add aca modules disk source=/lib/modules path=/lib/modules && \
lxc config device add aca log disk source=/var/log/openvswitch path=/var/log/openvswitch && \
lxc config device add aca lib disk source=/var/lib/openvswitch path=/var/lib/openvswitch && \
lxc config device add aca run disk source=/var/run/openvswitch path=/var/run/openvswitch && \
lxc config device add aca etc disk source=/etc/openvswitch path=/etc/openvswitch
}


while getopts "ib" opt; do
case $opt in
i)
echo "Install distrobuilder"
install_distrobuilder
;;
b)
echo "Build aca lxc container"
build_aca_lxc
;;
\?)
echo "Invalid arguements"
esac
done
200 changes: 200 additions & 0 deletions build/lxd-container/lxd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
image:
name: ubuntu-bionic-x86_64
distribution: ubuntu
release: bionic
description: |-
Alcor Control Agent
architecture: x86_64

source:
downloader: debootstrap
same_as: gutsy
url: http://archive.ubuntu.com/ubuntu
keyserver: keyserver.ubuntu.com
keys:
- 0x790BC7277767219C42C86F933B4FE6ACC0B21F32
- 0xf6ecb3762474eda9d21b7022871920d1991bc93c

targets:
lxc:
create-message: |-
You just created an {{ image.description }} container.

To enable SSH, run: apt install openssh-server
No default root or user password are set by LXC.
config:
- type: all
before: 5
content: |-
lxc.include = LXC_TEMPLATE_CONFIG/ubuntu.common.conf

- type: user
before: 5
content: |-
lxc.include = LXC_TEMPLATE_CONFIG/ubuntu.userns.conf

- type: all
after: 4
content: |-
lxc.include = LXC_TEMPLATE_CONFIG/common.conf

- type: user
after: 4
content: |-
lxc.include = LXC_TEMPLATE_CONFIG/userns.conf

- type: all
content: |-
lxc.arch = {{ image.architecture_personality }}

files:
- path: /etc/hostname
generator: hostname

- path: /etc/hosts
generator: hosts

- path: /etc/resolvconf/resolv.conf.d/original
generator: remove

- path: /etc/resolvconf/resolv.conf.d/tail
generator: remove

- path: /etc/machine-id
generator: dump

- path: /etc/user/profile
generator: copy
source: /etc/profile

- path: /var/lib/dbus/machine-id
generator: remove

- path: /etc/netplan/10-lxc.yaml
generator: dump
content: |-
network:
version: 2
ethernets:
eth0:
dhcp4: true
dhcp-identifier: mac
releases:
- bionic
types:
- container
variants:
- default

- path: /etc/netplan/10-lxc.yaml
generator: dump
content: |-
network:
version: 2
ethernets:
enp5s0:
dhcp4: true
dhcp-identifier: mac
releases:
- bionic
types:
- vm
variants:
- default

- name: meta-data
generator: cloud-init
variants:
- cloud

- name: network-config
generator: cloud-init
variants:
- cloud

- name: user-data
generator: cloud-init
variants:
- cloud

- name: vendor-data
generator: cloud-init
variants:
- cloud

- name: ext4
generator: fstab
types:
- vm

- name: lxd-agent
generator: lxd-agent
types:
- vm

- path: /etc/default/grub.d/50-lxd.cfg
generator: dump
content: |-
GRUB_RECORDFAIL_TIMEOUT=0
GRUB_TIMEOUT=0
GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} console=tty1 console=ttyS0"
GRUB_TERMINAL=console
types:
- vm

- path: /etc/sudoers.d/90-lxd
generator: dump
mode: 0440
content: |-
# User rules for ubuntu
ubuntu ALL=(ALL) NOPASSWD:ALL
variants:
- default

- path: /root/aca
generator: copy
source: ./aca

- path: /root/dependencis
generator: copy
source: ./dependencis

packages:
manager: apt
update: true
cleanup: true
sets:
- packages:
- openssh-client
- vim
- build-essential
- iputils-ping
- iperf
- net-tools
- inetutils-telnet
- iperf
- openssh-server
action: install

repositories:
- name: sources.list
url: |-
deb http://archive.ubuntu.com/ubuntu {{ image.release }} main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu {{ image.release }}-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu {{ image.release }}-security main restricted universe multiverse
architectures:
- amd64

# TODO: actions part is provided by official but not working
# actions:
# - trigger: post-files
# action: |-
# #!/bin/bash
# chmod +x /root/ignite/bin/ignite.sh
# systemctl daemon-reload
# systemctl enable ignite
# systemctl enable dpm


mappings:
architecture_map: debian