Skip to content

Commit

Permalink
Add support for more Ubuntu verisons
Browse files Browse the repository at this point in the history
Adds 18.04, 20.04, and 24.04 (in addition to 22.04 which was already
there).

For tests, given that Ubuntu <= 20.04 have a "golang" package that is
too old to run the tests, I added a way to override the package name
used in the test.

Another minor modification due to Bionic not supporting
`execute_after_dh_fixperms`.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed Nov 20, 2024
1 parent 61d40ce commit 0d20ee8
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 12 deletions.
2 changes: 1 addition & 1 deletion frontend/deb/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
// Unique name that would not normally be in the spec
// This will get used to create the source tar for go module deps
gomodsName = "xxxdalecGomodsInternal"
DebHelperCompat = "13"
DebHelperCompat = "11"
)

func mountSources(sources map[string]llb.State, dir string, mod func(string) string) llb.RunOption {
Expand Down
7 changes: 6 additions & 1 deletion frontend/deb/template_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ func (w *rulesWrapper) OverridePerms() fmt.Stringer {
}

if fixPerms {
b.WriteString("execute_after_dh_fixperms:\n")
// Normally this should be `execute_aftr_dh_fixperms`, howwever this doesn't
// work on UBuntu 18.04.
// Instead we need to override dh_fixperms and run it ourselves and then
// our extra script.
b.WriteString("override_dh_fixperms:\n")
b.WriteString("\tdh_fixperms\n")
b.WriteString("\tdebian/dalec/fix_perms.sh\n\n")
}

Expand Down
25 changes: 25 additions & 0 deletions frontend/ubuntu/bionic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ubuntu

import (
"github.com/Azure/dalec/frontend/deb/distro"
)

const (
BionicDefaultTargetKey = "bionic"
BionicAptCachePrefix = "bionic"
BionicWorkerContextName = "dalec-bionic-worker"

bionicRef = "mcr.microsoft.com/mirror/docker/library/ubuntu:bionic"
bionicVersionID = "ubuntu18.04"
)

var (
BionicConfig = &distro.Config{
ImageRef: bionicRef,
AptCachePrefix: BionicAptCachePrefix,
VersionID: bionicVersionID,
ContextRef: BionicWorkerContextName,
DefaultOutputImage: bionicRef,
BuilderPackages: basePackages,
}
)
5 changes: 4 additions & 1 deletion frontend/ubuntu/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ var (
}

targets = map[string]gwclient.BuildFunc{
JammyDefaultTargetKey: JammyConfig.Handle, // 22.04
BionicDefaultTargetKey: BionicConfig.Handle, // 18.04
FocalDefaultTargetKey: FocalConfig.Handle, // 20.04
JammyDefaultTargetKey: JammyConfig.Handle, // 22.04
NobleDefaultTargetKey: NobleConfig.Handle, // 24.04
}
)

Expand Down
25 changes: 25 additions & 0 deletions frontend/ubuntu/focal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ubuntu

import (
"github.com/Azure/dalec/frontend/deb/distro"
)

const (
FocalDefaultTargetKey = "focal"
FocalAptCachePrefix = "focal"
FocalWorkerContextName = "dalec-focal-worker"

focalRef = "mcr.microsoft.com/mirror/docker/library/ubuntu:focal"
focalVersionID = "ubuntu20.04"
)

var (
FocalConfig = &distro.Config{
ImageRef: focalRef,
AptCachePrefix: FocalAptCachePrefix,
VersionID: focalVersionID,
ContextRef: FocalWorkerContextName,
DefaultOutputImage: focalRef,
BuilderPackages: basePackages,
}
)
25 changes: 25 additions & 0 deletions frontend/ubuntu/noble.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ubuntu

import (
"github.com/Azure/dalec/frontend/deb/distro"
)

const (
NobleDefaultTargetKey = "noble"
NobleAptCachePrefix = "noble"
NobleWorkerContextName = "dalec-noble-worker"

nobleRef = "mcr.microsoft.com/mirror/docker/library/ubuntu:noble"
nobleVersionID = "ubuntu24.04"
)

var (
NobleConfig = &distro.Config{
ImageRef: nobleRef,
AptCachePrefix: NobleAptCachePrefix,
VersionID: nobleVersionID,
ContextRef: NobleWorkerContextName,
DefaultOutputImage: nobleRef,
BuilderPackages: basePackages,
}
)
3 changes: 1 addition & 2 deletions frontend/windows/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/Azure/dalec"
"github.com/Azure/dalec/frontend"
"github.com/Azure/dalec/frontend/deb"
"github.com/Azure/dalec/frontend/deb/distro"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/client/llb/sourceresolver"
Expand Down Expand Up @@ -40,7 +39,7 @@ var (
"zip",
"aptitude",
"dpkg-dev",
"debhelper-compat=" + deb.DebHelperCompat,
"debhelper",
},
}
)
Expand Down
16 changes: 13 additions & 3 deletions test/azlinux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ type targetConfig struct {
// Given a spec, list all files (including the full path) that are expected
// to be sent to be signed.
ListExpectedSignFiles func(*dalec.Spec, ocispecs.Platform) []string

// PackageOverrides is useful for replacing packages used in tests (such as `golang`)
// with alternative ones.
PackageOverrides map[string]string
}

type testLinuxConfig struct {
Expand All @@ -243,6 +247,14 @@ type OSRelease struct {
VersionID string
}

func (cfg *testLinuxConfig) GetPackage(name string) string {
updated := cfg.Target.PackageOverrides[name]
if updated != "" {
return updated
}
return name
}

func testLinuxDistro(ctx context.Context, t *testing.T, testConfig testLinuxConfig) {
t.Run("Fail when non-zero exit code during build", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -875,9 +887,7 @@ Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/boot
},
Dependencies: &dalec.PackageDependencies{
Build: map[string]dalec.PackageConstraints{
// TODO: This works at least for now, but is distro specific and
// could break on new distros (though that is still unlikely).
"golang": {},
testConfig.GetPackage("golang"): {},
},
},
Build: dalec.ArtifactBuild{
Expand Down
40 changes: 38 additions & 2 deletions test/ubuntu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ var (
}
)

func debLinuxTestConfigFor(targetKey string, cfg *distro.Config) testLinuxConfig {
return testLinuxConfig{
func withPackageOverride(oldPkg, newPkg string) func(cfg *testLinuxConfig) {
return func(cfg *testLinuxConfig) {
if cfg.Target.PackageOverrides == nil {
cfg.Target.PackageOverrides = make(map[string]string)
}

cfg.Target.PackageOverrides[oldPkg] = newPkg
}
}

func debLinuxTestConfigFor(targetKey string, cfg *distro.Config, opts ...func(*testLinuxConfig)) testLinuxConfig {
tlc := testLinuxConfig{
Target: targetConfig{
Container: targetKey + "/testing/container",
Package: targetKey + "/deb",
Expand All @@ -49,6 +59,11 @@ func debLinuxTestConfigFor(targetKey string, cfg *distro.Config) testLinuxConfig
Constraints: debConstraintsSymbols,
},
}

for _, o := range opts {
o(&tlc)
}
return tlc
}

func ubuntuCreateRepo(cfg *distro.Config) func(pkg llb.State, opts ...llb.StateOption) llb.StateOption {
Expand Down Expand Up @@ -139,3 +154,24 @@ func TestJammy(t *testing.T) {
ctx := startTestSpan(baseCtx, t)
testLinuxDistro(ctx, t, debLinuxTestConfigFor(ubuntu.JammyDefaultTargetKey, ubuntu.JammyConfig))
}

func TestNoble(t *testing.T) {
t.Parallel()

ctx := startTestSpan(baseCtx, t)
testLinuxDistro(ctx, t, debLinuxTestConfigFor(ubuntu.NobleDefaultTargetKey, ubuntu.NobleConfig))
}

func TestFocal(t *testing.T) {
t.Parallel()

ctx := startTestSpan(baseCtx, t)
testLinuxDistro(ctx, t, debLinuxTestConfigFor(ubuntu.FocalDefaultTargetKey, ubuntu.FocalConfig, withPackageOverride("golang", "golang-1.22")))
}

func TestBionic(t *testing.T) {
t.Parallel()

ctx := startTestSpan(baseCtx, t)
testLinuxDistro(ctx, t, debLinuxTestConfigFor(ubuntu.BionicDefaultTargetKey, ubuntu.BionicConfig, withPackageOverride("golang", "golang-1.18")))
}
40 changes: 38 additions & 2 deletions website/docs/targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,65 @@ Many components, such as package dependencies and base images, are specific to a
To print a list of available build targets:

```shell
GET DESCRIPTION
$ docker buildx build --call targets --build-arg ghcr.io/azure/dalec/frontend:latest - <<< "null"
TARGET DESCRIPTION
azlinux3/container (default) Builds a container image for
azlinux3/container/depsonly Builds a container image with only the runtime dependencies installed.
azlinux3/rpm Builds an rpm and src.rpm.
azlinux3/rpm/debug/buildroot Outputs an rpm buildroot suitable for passing to rpmbuild.
azlinux3/rpm/debug/sources Outputs all the sources specified in the spec file in the format given to rpmbuild.
azlinux3/rpm/debug/spec Outputs the generated RPM spec file
azlinux3/worker Builds the base worker image responsible for building the rpm
bionic/deb (default) Builds a deb package.
bionic/dsc Builds a Debian source package.
bionic/testing/container Builds a container image for testing purposes only.
bionic/worker Builds the worker image.
debug/gomods Outputs all the gomodule dependencies for the spec
debug/resolve Outputs the resolved dalec spec file with build args applied.
debug/sources Outputs all sources from a dalec spec file.
focal/deb (default) Builds a deb package.
focal/dsc Builds a Debian source package.
focal/testing/container Builds a container image for testing purposes only.
focal/worker Builds the worker image.
jammy/deb (default) Builds a deb package.
jammy/dsc Builds a Debian source package.
jammy/testing/container Builds a container image for testing purposes only.
jammy/worker Builds the worker image.
mariner2/container (default) Builds a container image for
mariner2/container/depsonly Builds a container image with only the runtime dependencies installed.
mariner2/rpm Builds an rpm and src.rpm.
mariner2/rpm/debug/buildroot Outputs an rpm buildroot suitable for passing to rpmbuild.
mariner2/rpm/debug/sources Outputs all the sources specified in the spec file in the format given to rpmbuild.
mariner2/rpm/debug/spec Outputs the generated RPM spec file
mariner2/worker Builds the base worker image responsible for building the rpm
noble/deb (default) Builds a deb package.
noble/dsc Builds a Debian source package.
noble/testing/container Builds a container image for testing purposes only.
noble/worker Builds the worker image.
windowscross/container (default) Builds binaries and installs them into a Windows base image
windowscross/worker Builds the base worker image responsible for building the rpm
windowscross/worker Builds the base worker image responsible for building the package
windowscross/zip Builds binaries combined into a zip file
```

:::note
The above command is passing in a "null" value as the build spec and telling
buildkit to use the latest dalec version.
This output can change depending on version or spec you provide.
:::

To check the targets available for a specific spec you can just add `--call targets`
to your normal `docker build` command:

```shell
$ docker buildx build --call targets -f ./path/to/spec .
```

If the `--target=<val>` flag is set, the list of targets will be filtered based
on `<val>`.

Likewise if the spec file contains items in the `targets` section then the list
of available targets will be filtered to just the targets in the spec.

## Dependencies

Instead of specifying a package dependency at the root of the spec, you can specify it under a target.
Expand Down

0 comments on commit 0d20ee8

Please sign in to comment.