This repo contains tools for creating BOSH stemcells. A stemcell is a bootable disk image that is used as a template by a BOSH Director to create VMs.
export short_name="jammy"
git clone git@github.com:cloudfoundry/bosh-linux-stemcell-builder.git
cd bosh-linux-stemcell-builder
git checkout ubuntu-${short_name}
mkdir -p tmp
docker build \
--platform linux/amd64 \
--build-arg SYFT_VERSION=v1.42.3 \
-t bosh/os-image-stemcell-builder:${short_name} \
ci/docker/os-image-stemcell-builder/
docker run \
--platform linux/amd64 \
--privileged \
-v "$(pwd):/opt/bosh" \
--workdir /opt/bosh \
--user=1000:1000 \
-it \
bosh/os-image-stemcell-builder:${short_name}
# You're now in the Docker container
pushd bosh-stemcell
bundle install
popd
# build OS image
bundle exec rake stemcell:build_os_image[ubuntu,${short_name},${PWD}/tmp/ubuntu_base_image.tgz]
# build vSphere stemcell
bundle exec rake stemcell:build[vsphere,esxi,ubuntu,${short_name},${PWD}/tmp/ubuntu_base_image.tgz]
When building a vSphere stemcell, you must download VMware-ovftool-*.bundle
and place it in the ci/docker/os-image-stemcell-builder/ directory before
running docker build. See External Assets for download
instructions.
An OS image is a tarball that contains a snapshot of an OS filesystem, including the libraries and system utilities needed by the BOSH agent; however, it does not contain the BOSH agent nor the virtualization tools: a subsequent Rake task adds the BOSH agent and a set of virtualization tools to the base OS image to produce a stemcell.
The OS Image should be rebuilt when you are making changes to the packages installed in the operating system or when making changes to the configuration of those packages.
export short_name="jammy"
bundle exec rake stemcell:build_os_image[ubuntu,${short_name},${PWD}/tmp/ubuntu_base_image.tgz]
The arguments to the stemcell:build_os_image rake task follow:
operating_system_name (ubuntu): identifies which type of OS to fetch.
Determines which package repository and packaging tool will be used to
download and assemble the files. Currently, only ubuntu is recognized.operating_system_version (<short_name>): an identifier that the system may use
to decide which release of the OS to download. Acceptable values depend on
the operating system. For ubuntu, use <short_name>.os_image_path (${PWD}/tmp/ubuntu_base_image.tgz): the path to write the
finished OS image tarball to. If a file exists at this path already, it will
be overwritten without warning.Rebuild the stemcell when you are making and testing BOSH-specific changes such as a new BOSH agent.
export short_name="jammy"
export build_number="0.0.8"
bundle exec rake stemcell:build[vsphere,esxi,ubuntu,${short_name},${PWD}/tmp/ubuntu_base_image.tgz,${build_number}]
The arguments to stemcell:build are:
infrastructure_name: Which IaaS you are producing the stemcell for.
Determines which virtualization tools to package on top of the stemcell.hypervisor_name: Depending on what the IAAS supports, which hypervisor to
target:aws → xen-hvmazure → hypervgoogle → kvmopenstack → kvmvsphere → esxioperating_system_name (ubuntu): Type of OS. Same as
stemcell:build_os_image.operating_system_version (<short_name>): OS release. Same as
stemcell:build_os_image. Can optionally include a variant suffix (<short_name>-fips)os_image_path (${PWD}/tmp/ubuntu_base_image.tgz): Path to base OS image
produced in stemcell:build_os_imagebuild_number (0.0.8): Stemcell version. Pro-tip: take the version number
of the most recent release and add one, e.g.: "0.0.7" → "0.0.8". If not
specified, it will default to "0000".You can find the resulting stemcell in the tmp/ directory of the host, or in
the /opt/bosh/tmp directory in the Docker container. Using the above example,
the stemcell would be at
tmp/bosh-stemcell-0.0.8-vsphere-esxi-ubuntu-<short_name>-go_agent.tgz. You can
upload the stemcell to a vSphere BOSH Director:
export short_name="jammy"
bosh upload-stemcell tmp/bosh-stemcell-0.0.8-vsphere-esxi-ubuntu-${short_name}-go_agent.tgz
The OS tests are meant to be run against the OS environment to which they
belong. When you run the stemcell:build_os_image rake task, it will create a
.raw OS image that it runs the OS specific tests against. You will need to run
the rake task the first time you create your docker container, but everytime
after, as long as you do not destroy the container, you should be able to run
the specific tests.
To run the OS image tests in spec/os_image/ubuntu_spec.rb (assuming you've already built
the OS image at the tmp/ubuntu_base_image.tgz and you're within the Docker
container):
export short_name="jammy"
cd /opt/bosh/bosh-stemcell
bundle install
OS_IMAGE=/opt/bosh/tmp/ubuntu_base_image.tgz bundle exec rspec -fd spec/os_image/ubuntu_spec.rb
When you run the stemcell:build rake task, it will create a stemcell that it
runs the stemcell-specific tests against. You will need to run the rake task
the first time you create your docker container, but every time after, as
long as you do not destroy the container, you should be able to run the
specific tests:
cd /opt/bosh/bosh-stemcell; \
bundle install; \
STEMCELL_IMAGE=/mnt/stemcells/vsphere/esxi/ubuntu/work/work/vsphere-esxi-ubuntu.raw \
STEMCELL_WORKDIR=/mnt/stemcells/vsphere/esxi/ubuntu/work/work/chroot \
OS_NAME=ubuntu \
bundle exec rspec -fd --tag ~exclude_on_vsphere \
spec/os_image/ubuntu_spec.rb \
spec/stemcells/ubuntu_spec.rb \
spec/stemcells/go_agent_spec.rb \
spec/stemcells/vsphere_spec.rb \
spec/stemcells/stig_spec.rb \
spec/stemcells/cis_spec.rb
ShelloutTypesIn pursuit of more robustly testing, we wrote our testing library for stemcell
contents, called ShelloutTypes.
The ShelloutTypes code has its own unit tests, but require root privileges and
an ubuntu chroot environment to run. For this reason, we use the
bosh/main-ubuntu-chroot docker image for unit tests. To run these unit tests
locally, run:
cd /opt/bosh/bosh-stemcell
bundle install
OS_IMAGE=/opt/bosh/tmp/ubuntu_base_image.tgz bundle exec rake spec:shellout_types
The BOSH Linux Stemcell Builder code itself can be tested with the following command's:
cd /opt/bosh/bosh-stemcell
bundle install
bundle exec rake
If you find yourself debugging any of the above processes, here is what you need to know:
stemcell_builder/stages/<stage_name>/apply.sh.resume_from=<stage_name> to the end of
your bundle exec rake command. When a stage's apply.sh fails, you should
see a message of the form Can't find stage '<stage>' to resume from.
Aborting. so you know which stage failed and where you can resume from after
fixing the problem. Please use caution as stages are not guaranteed to be
idempotent.Example usage:
```shell export short_name="jammy"
bundle exec rake stemcell:build_os_image[ubuntu,${short_name},${PWD}/tmp/ubuntu_base_image.tgz] resume_from=rsyslog_config ```
How to run tests for OS ImagesHow to run tests for Stemcell/mnt/stemcells/vsphere/esxi/ubuntu/work/work/chrootThe installer for ovftool can be found at:
- https://developer.broadcom.com/tools/open-virtualization-format-ovf-tool/latest.
The ovftool installer for linux must be copied into
os-image-stemcell-builder
next to the Dockerfile before building the Docker image. If not you will
see an error similar to:
ADD failed: failed to compute cache key: "/VMware-ovftool-4.4.3-18663434-lin.x86_64.bundle": not found
The Docker image is published to
bosh/os-image-stemcell-builder.
You will need the ovftool installer present in
ci/docker/os-image-stemcell-builder/.
Rebuild the container with:
export short_name="jammy"
docker build \
--platform linux/amd64 \
--build-arg BASE_IMAGE="ubuntu:${short_name}" \
--build-arg META4_CLI_URL="https://github.com/dpb587/metalink/releases/download/v0.5.0/meta4-0.5.0-linux-amd64" \
--build-arg SYFT_CLI_URL="https://github.com/anchore/syft/releases/download/v1.42.3/syft_1.42.3_linux_amd64.tar.gz" \
--build-arg YQ_CLI_URL="https://github.com/mikefarah/yq/releases/download/v4.52.5/yq_linux_amd64" \
--build-arg RUBY_INSTALL_URL="https://github.com/postmodern/ruby-install/releases/download/v0.10.2/ruby-install-0.10.2.tar.gz" \
--build-arg RUBY_VERSION="$(cat .ruby-version)" \
--build-arg GEM_HOME="/usr/local/bundle" \
--build-arg OVF_TOOL_INSTALLER="VMware-ovftool-4.4.3-18663434-lin.x86_64.bundle" \
--build-arg OVF_TOOL_INSTALLER_SHA1="6c24e473be49c961cfc3bb16774b52b48e822991" \
-t bosh/os-image-stemcell-builder:${short_name} \
ci/docker/os-image-stemcell-builder/
When creating a new LTS stemcell you will need to create a folder and upload
the appropriate ovftool to the GCP bucket bosh-vmware-ovftool:
gsutil cp MY_OVFTOOL_FILE gs://bosh-vmware-ovftool/MY_OS/
Example:
export short_name="jammy"
gsutil cp VMware-ovftool-4.4.3-18663434-lin.x86_64.bundle gs://bosh-vmware-ovftool/${short_name}/
The stemcell pipelines currently run on a Concourse instance configured here:
Concourse publishes its artifacts to GCS.
export gcp_region="europe-west4"
gsutil mb -l "${gcp_region}" gs://bosh-aws-light-stemcells
gsutil mb -l "${gcp_region}" gs://bosh-aws-light-stemcells-candidate
gsutil mb -l "${gcp_region}" gs://bosh-gce-light-stemcell-ci-terraform-state
gsutil mb -l "${gcp_region}" gs://bosh-gce-light-stemcells
gsutil mb -l "${gcp_region}" gs://bosh-gce-light-stemcells-candidate
gsutil mb -l "${gcp_region}" gs://bosh-gce-raw-stemcells-new
gsutil mb -l "${gcp_region}" gs://bosh-core-stemcells
gsutil mb -l "${gcp_region}" gs://bosh-core-stemcells-candidate
gsutil mb -l "${gcp_region}" gs://bosh-os-images
gsutil mb -l "${gcp_region}" gs://bosh-stemcell-triggers
gsutil iam ch allUsers:objectViewer gs://bosh-os-images
gsutil iam ch allUsers:objectViewer gs://bosh-core-stemcell
gsutil iam ch allUsers:objectViewer gs://bosh-core-stemcells-candidate
gsutil iam ch allUsers:objectViewer gs://bosh-aws-light-stemcells
gsutil iam ch allUsers:objectViewer gs://bosh-aws-light-stemcells-candidate
gsutil iam ch allUsers:objectViewer gs://bosh-gce-light-stemcells
gsutil iam ch allUsers:objectViewer gs://bosh-gce-light-stemcells-candidate
gsutil versioning set on gs://bosh-stemcell-triggers
The default-allow-internal firewall rule should allow the subnet 10.0.0.0/8
on all ports:
gcloud compute firewall-rules update default-allow-internal --source-ranges 10.0.0.0/8
Create a stemcell-builder-integration-${subnet_int} subnetworks need by BATs tests.
Each stemcell line should get its own subnet corresponding to its subnet_int equal to
the two digit release year. For example release year 2010 would have subnet_int="10".
Example per ci/pipeline-vars.yml:
---
stemcell_details:
# ... snip
subnet_int: "10" #! use last two digits of release year: ex 2010 -> 10
# ... snip
Would mean creating the following subnet in GCP:
# branch: ubuntu-${short_name}
export subnet_int="10"
gcloud compute networks subnets create --network default \
--range "10.100.${subnet_int}.0/24" "stemcell-builder-integration-${subnet_int}"
Concourse will want to publish its artifacts. Create IAM users with the appropriate policy files:
When switching from the old pipeline to the new one, don't forget to:
pipeline.yml and change the bucket from bosh-os-images-dev to
whatever the public bucket should beos-images directorynew| 日期 | 榜单 | 排名 | 周期新增 | 总 STAR |
|---|