├── LICENSE ├── README.md └── sonic-cloud-init.yaml /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 antongisli 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sonic-builder 2 | Automating local sonic builds. Motivation for this is to use a sane environment without messing up your local machine. 3 | 4 | Uses multipass to spawn Ubuntu VMs for building, and cloud-init to do all the tedious work of setting up the build env. 5 | 6 | At the end, you have freedom to try the build in different ways, but there are two example scripts provided. 7 | 8 | ## Requirements 9 | - multipass installed 10 | - A host with enough CPU/RAM/disk (16 GB RAM, 300GB free disk space) 11 | - Assumes you are using Ubuntu as a host, but has been tested and works on a windows host too. 12 | 13 | ## Instructions 14 | 15 | Use the `sonic-cloud-init.yaml` file as a cloud-init script. 16 | It will setup docker and all the other tedious things needed to build sonic for you. 17 | You'll be left with a machine ready to build. 18 | 19 | 20 | To use this with multipass, do this: 21 | - `git clone https://github.com/antongisli/sonic-builder.git` 22 | - `multipass launch 20.04 -n sonic-builder -c8 -m10G -d300G --cloud-init sonic-builder/sonic-cloud-init.yaml` 23 | - Log in: `multipass shell sonic-builder` 24 | - From here, you have a ready and clean build environment. 25 | - Note: change `-c` to match the CPU cores you have available. `-m` for memory, `-d` for disk space. 26 | 27 | Docker sonic VS build scripts are made for you in home dir, one to build arm & one x86. 28 | Note that you may want to edit these to checkout a different version of sonic, since 29 | sometimes builds just don't work otherwise. By default, the scripts use the master branch. 30 | To change the branch, add e.g. `git checkout 202106` **before** the sed lines because 31 | they modify `rules/config`. 32 | - `./build-vs-arm-docker.sh` 33 | - `./build-vs-docker.sh` 34 | 35 | Now pray to the Gods above, and perhaps you will end up with a working docker image :). 36 | 37 | If you want to remove the multipass VM when you're done, then from your host: `multipass delete --purge sonic-builder` 38 | 39 | Notes on using the docker images: 40 | ~/sonic-buildimage/platform/vs/README.vsdocker.md 41 | -------------------------------------------------------------------------------- /sonic-cloud-init.yaml: -------------------------------------------------------------------------------- 1 | package_upgrade: true 2 | packages: 3 | - make 4 | - python3-pip 5 | - ca-certificates 6 | - curl 7 | - gnupg 8 | - lsb-release 9 | 10 | write_files: 11 | - path: /tmp/docker.sh 12 | permissions: 0744 13 | owner: root 14 | content: | 15 | #!/usr/bin/env bash 16 | echo \ 17 | "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ 18 | $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null 19 | - path: /tmp/prep.sh 20 | permissions: 0744 21 | owner: root 22 | content: | 23 | #!/usr/bin/env bash 24 | cd ~ubuntu 25 | git clone https://github.com/Azure/sonic-buildimage.git 26 | # uncomment below if you want to change the branch 27 | # cd sonic-buildimage; git checkout 202106; cd .. 28 | sed -i 's/SONIC_CONFIG_BUILD_JOBS = 1/SONIC_CONFIG_BUILD_JOBS = 4/g' sonic-buildimage/rules/config 29 | sed -i 's/DEFAULT_PASSWORD = YourPaSsWoRd/DEFAULT_PASSWORD = admin/g' sonic-buildimage/rules/config 30 | sed -i 's/# SHUTDOWN_BGP_ON_START = y/SHUTDOWN_BGP_ON_START = n/g' sonic-buildimage/rules/config 31 | chown -R ubuntu:ubuntu sonic-buildimage 32 | - path: /home/ubuntu/build-vs-docker.sh 33 | permissions: 0744 34 | owner: root 35 | content: | 36 | #!/usr/bin/env bash 37 | cd sonic-buildimage 38 | make init 39 | make configure PLATFORM=vs 40 | make SONIC_BUILD_JOBS=4 target/docker-sonic-vs.gz 41 | - path: /home/ubuntu/build-vs-arm-docker.sh 42 | permissions: 0744 43 | owner: root 44 | content: | 45 | #!/usr/bin/env bash 46 | cd sonic-buildimage 47 | make init 48 | make configure PLATFORM=vs PLATFORM_ARCH=arm64 49 | make SONIC_BUILD_JOBS=4 target/docker-sonic-vs.gz 50 | 51 | runcmd: 52 | - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 53 | - bash /tmp/docker.sh 54 | - apt-get -y update 55 | - apt-get -y install docker-ce docker-ce-cli containerd.io 56 | - pip install j2cli 57 | - git clone https://github.com/Azure/sonic-buildimage.git 58 | - modprobe overlay 59 | - bash /tmp/prep.sh 60 | - chown ubuntu:ubuntu /home/ubuntu/build-vs-arm-docker.sh 61 | - chown ubuntu:ubuntu /home/ubuntu/build-vs-docker.sh 62 | - usermod -a -G docker ubuntu 63 | --------------------------------------------------------------------------------