Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR-5649 - Distinguish build and target components #160

Merged
merged 8 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ubuntu-image (3.0+23.04ubuntu1) UNRELEASED; urgency=medium
* Add a make-dirs manual customization option to create directories in the rootfs
* use eatmydata to speed up debootstrap
* Make sure we unmount/detach everything if the update_bootloader state is failing
* Enable distinguish build and target components/pockets

[ Alfonso Sanchez-Beato ]
* Update to latest snapd, adapting to changes in layouts code.
Expand Down
17 changes: 16 additions & 1 deletion internal/imagedefinition/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The following specification defines what is supported in the YAML:
# archive-tasks, or tarball.
rootfs:
# Components are a list of apt sources, such as main,
# universe, and restricted. Defaults to "release".
# universe, and restricted. Defaults to "main,restricted".
components: (optional)
- <string>
- <string>
Expand Down Expand Up @@ -128,7 +128,22 @@ The following specification defines what is supported in the YAML:
# ubuntu-image supports building automatically with some
# customizations to the image. Note that if customization
# is specified, at least one of the subkeys should be used
# This is only supported for classic image building
customization: (optional)
# Components are a list of apt sources, such as main,
# universe, and restricted. Defaults to "main, restricted, universe".
# These are used in the resulting img, not to build it.
components: (optional)
- <string>
- <string>
# Ubuntu offers several pockets, which often imply the
# inclusion of other pockets. The release pocket only
# includes itself. The security pocket includes itself
# and the release pocket. Updates includes updates,
# security, and release. Proposed includes all pockets.
# Defaults to "release".
# This value is in the resulting img, not to build it.
pocket: release | security | updates | proposed (optional)
# Used only for installer images
installer: (optional)
preseeds: (optional)
Expand Down
92 changes: 47 additions & 45 deletions internal/imagedefinition/image_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Gadget struct {

// Rootfs defines the rootfs section of the image definition file
type Rootfs struct {
Components []string `yaml:"components" json:"Components,omitempty"`
Components []string `yaml:"components" json:"Components,omitempty" default:"main,restricted"`
Archive string `yaml:"archive" json:"Archive" default:"ubuntu"`
Flavor string `yaml:"flavor" json:"Flavor" default:"ubuntu"`
Mirror string `yaml:"mirror" json:"Mirror" default:"http://archive.ubuntu.com/ubuntu/"`
Expand Down Expand Up @@ -70,6 +70,8 @@ type Tarball struct {
// The extra_step_prebuilt_rootfs struct tag denotes that an extra state will
// need to be added for image builds with prebuilt root filesystems.
type Customization struct {
Components []string `yaml:"components" json:"Components,omitempty" default:"main,restricted,universe"`
Pocket string `yaml:"pocket" json:"Pocket" jsonschema:"enum=release,enum=Release,enum=updates,enum=Updates,enum=security,enum=Security,enum=proposed,enum=Proposed" default:"release"`
Installer *Installer `yaml:"installer" json:"Installer,omitempty"`
CloudInit *CloudInit `yaml:"cloud-init" json:"CloudInit,omitempty"`
ExtraPPAs []*PPA `yaml:"extra-ppas" json:"ExtraPPAs,omitempty" extra_step_prebuilt_rootfs:"add_extra_ppas"`
Expand Down Expand Up @@ -312,50 +314,50 @@ func (imageDef ImageDefinition) securityMirror() string {
return imageDef.Rootfs.Mirror
}

// GeneratePocketList returns a slice of strings that need to be added to
// /etc/apt/sources.list in the chroot based on the value of "pocket"
// in the rootfs section of the image definition
func (imageDef ImageDefinition) GeneratePocketList() []string {
pocketMap := map[string][]string{
"release": {},
"security": {
fmt.Sprintf("deb %s %s-security %s\n",
imageDef.securityMirror(),
imageDef.Series,
strings.Join(imageDef.Rootfs.Components, " "),
),
},
"updates": {
fmt.Sprintf("deb %s %s-updates %s\n",
imageDef.Rootfs.Mirror,
imageDef.Series,
strings.Join(imageDef.Rootfs.Components, " "),
),
fmt.Sprintf("deb %s %s-security %s\n",
imageDef.securityMirror(),
imageDef.Series,
strings.Join(imageDef.Rootfs.Components, " "),
),
},
"proposed": {
fmt.Sprintf("deb %s %s-updates %s\n",
imageDef.Rootfs.Mirror,
imageDef.Series,
strings.Join(imageDef.Rootfs.Components, " "),
),
fmt.Sprintf("deb %s %s-security %s\n",
imageDef.securityMirror(),
imageDef.Series,
strings.Join(imageDef.Rootfs.Components, " "),
),
fmt.Sprintf("deb %s %s-proposed %s\n",
imageDef.Rootfs.Mirror,
imageDef.Series,
strings.Join(imageDef.Rootfs.Components, " "),
),
},
func generatePocketList(series string, components []string, mirror string, securityMirror string, pocket string) []string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes this is much better.

baseList := fmt.Sprintf("deb %%s %s%%s %s\n", series, strings.Join(components, " "))

releaseList := fmt.Sprintf(baseList, mirror, "")
securityList := fmt.Sprintf(baseList, securityMirror, "-security")
updatesList := fmt.Sprintf(baseList, mirror, "-updates")
proposedList := fmt.Sprintf(baseList, mirror, "-proposed")

pocketList := make([]string, 0)

switch pocket {
case "release":
pocketList = append(pocketList, releaseList)
case "security":
pocketList = append(pocketList, releaseList, securityList)
case "updates":
pocketList = append(pocketList, releaseList, securityList, updatesList)
case "proposed":
pocketList = append(pocketList, releaseList, securityList, updatesList, proposedList)
}

// Schema validation has already confirmed the Pocket is a valid value
return pocketMap[strings.ToLower(imageDef.Rootfs.Pocket)]
return pocketList
}

// BuildPocketList returns a slice of strings that need to be added to
// /etc/apt/sources.list in the chroot to build the image, based on the value of "pocket"
// in the rootfs section of the image definition
func (imageDef ImageDefinition) BuildPocketList() []string {
return generatePocketList(
imageDef.Series,
imageDef.Rootfs.Components,
imageDef.Rootfs.Mirror,
imageDef.securityMirror(),
strings.ToLower(imageDef.Rootfs.Pocket))
}

// TargetPocketList returns a slice of strings that need to be added to
// /etc/apt/sources.list in the chroot for the target image, based on the value of "pocket"
// in the customization section of the image definition
func (imageDef ImageDefinition) TargetPocketList() []string {
return generatePocketList(
imageDef.Series,
imageDef.Customization.Components,
imageDef.Rootfs.Mirror,
imageDef.securityMirror(),
strings.ToLower(imageDef.Customization.Pocket))
}
Loading
Loading