Skip to content

Commit

Permalink
Add charm-dev-12f blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
weiiwang01 committed Jan 17, 2024
1 parent 2278799 commit e816f2c
Showing 1 changed file with 143 additions and 0 deletions.
143 changes: 143 additions & 0 deletions v1/charm-dev-12f.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# This blueprint creates a variant of the charm-dev environment with the 12-factor charm toolchain support.

description: A development and testing environment for 12-factor charm toolchain
version: latest

runs-on:
- x86_64

instances:
charm-dev-12f:
image: 22.04
limits:
min-cpu: 2
min-mem: 4G
min-disk: 30G
timeout: 1800
cloud-init:
vendor-data: |
package_update: true
packages:
- python3-pip
- jq
- sysstat
- zsh
- fzf
- tox
- gnome-keyring
- kitty-terminfo
snap:
commands:
# Juju 3.1 is supported until 25.04
- snap install juju --channel=3.1/stable
- snap install microk8s --channel=1.27-strict/stable
- snap alias microk8s.kubectl kubectl
- snap alias microk8s.kubectl k
- snap install --classic --channel edge/12f charmcraft
- snap install --classic --channel edge/12f rockcraft
- snap install jhack --channel=latest/stable
- snap install yq
- snap refresh
runcmd:
- DEBIAN_FRONTEND=noninteractive apt remove -y landscape-client landscape-common adwaita-icon-theme humanity-icon-theme
- DEBIAN_FRONTEND=noninteractive apt -y upgrade
- DEBIAN_FRONTEND=noninteractive apt -y autoremove
- |
# disable swap
sysctl -w vm.swappiness=0
echo "vm.swappiness = 0" | tee -a /etc/sysctl.conf
swapoff -a
- |
# disable unnecessary services
systemctl disable man-db.timer man-db.service --now
systemctl disable apport.service apport-autoreport.service --now
systemctl disable apt-daily.service apt-daily.timer --now
systemctl disable apt-daily-upgrade.service apt-daily-upgrade.timer --now
systemctl disable unattended-upgrades.service --now
systemctl disable motd-news.service motd-news.timer --now
systemctl disable bluetooth.target --now
systemctl disable ua-messaging.service ua-messaging.timer --now
systemctl disable ua-timer.timer ua-timer.service --now
systemctl disable systemd-tmpfiles-clean.timer --now
# Disable IPv6
echo "net.ipv6.conf.all.disable_ipv6=1" | tee -a /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6=1" | tee -a /etc/sysctl.conf
echo "net.ipv6.conf.lo.disable_ipv6=1" | tee -a /etc/sysctl.conf
sysctl -p
- |
# oh-my-zsh + juju plugin
sudo -u ubuntu sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
sudo -u ubuntu git clone https://github.com/zsh-users/zsh-autosuggestions.git ~ubuntu/.oh-my-zsh/custom/plugins/zsh-autosuggestions
sudo -u ubuntu git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~ubuntu/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
sudo -u ubuntu sed -i 's/plugins=(git)/plugins=(fzf git zsh-autosuggestions zsh-syntax-highlighting virtualenv colored-man-pages juju colorize)/g' ~ubuntu/.zshrc
- |
# setup charmcraft
lxd init --auto
adduser ubuntu lxd
- |
# Make sure juju directory is there
# https://bugs.launchpad.net/juju/+bug/1995697
sudo -u ubuntu mkdir -p /home/ubuntu/.local/share/juju
- |
# setup microk8s and bootstrap
usermod -a -G snap_microk8s ubuntu
usermod -a -G microk8s ubuntu
microk8s status --wait-ready
microk8s.enable metrics-server
microk8s.kubectl rollout status deployments/metrics-server -n kube-system -w --timeout=600s
# The dns addon will restart the api server so you may see a blip in the availability
# Separating addons to avoid errors such as
# dial tcp 127.0.0.1:16443: connect: connection refused
microk8s.enable dns rbac
microk8s.kubectl rollout status deployments/coredns -n kube-system -w --timeout=600s
# wait for storage become available
microk8s.enable hostpath-storage
microk8s.kubectl rollout status deployments/hostpath-provisioner -n kube-system -w --timeout=600s
# enable microk8s registry
microk8s.enable registry
microk8s.kubectl rollout status deployment registry -n container-registry -w --timeout=600s
# MetalLB
IPADDR=$(ip -4 -j route get 2.2.2.2 | jq -r '.[] | .prefsrc')
microk8s enable metallb:$IPADDR-$IPADDR
microk8s.kubectl rollout status daemonset.apps/speaker -n metallb-system -w --timeout=600s
# bootstrap controllers
sudo -u ubuntu juju bootstrap localhost lxd
sudo -u ubuntu juju add-model --config logging-config="<root>=WARNING; unit=DEBUG" --config update-status-hook-interval="60m" welcome-lxd
sudo -u ubuntu juju bootstrap microk8s microk8s
sudo -u ubuntu juju add-model --config logging-config="<root>=WARNING; unit=DEBUG" --config update-status-hook-interval="60m" welcome-k8s
# dump config (this is needed for utils such as k9s or kdash)
sudo -u ubuntu mkdir -p /home/ubuntu/.kube
microk8s config | sudo -u ubuntu tee /home/ubuntu/.kube/config > /dev/null
# We need to connect the dot-local-share-juju interface with jhack
sudo snap connect jhack:dot-local-share-juju snapd
final_message: "The system is finally up, after $UPTIME seconds"
health-check: |
set -e
charmcraft version
mkdir hello-world
cd hello-world
charmcraft init
charmcraft pack

0 comments on commit e816f2c

Please sign in to comment.