diff --git a/frontend/deb/pkg.go b/frontend/deb/pkg.go index 6c2671ecd..2378a0afd 100644 --- a/frontend/deb/pkg.go +++ b/frontend/deb/pkg.go @@ -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 { diff --git a/frontend/deb/template_rules.go b/frontend/deb/template_rules.go index 4a901d0a4..87ba73ecf 100644 --- a/frontend/deb/template_rules.go +++ b/frontend/deb/template_rules.go @@ -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") } diff --git a/frontend/ubuntu/bionic.go b/frontend/ubuntu/bionic.go new file mode 100644 index 000000000..5ec5ba67f --- /dev/null +++ b/frontend/ubuntu/bionic.go @@ -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, + } +) diff --git a/frontend/ubuntu/common.go b/frontend/ubuntu/common.go index d3254703c..e594b0cbc 100644 --- a/frontend/ubuntu/common.go +++ b/frontend/ubuntu/common.go @@ -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 } ) diff --git a/frontend/ubuntu/focal.go b/frontend/ubuntu/focal.go new file mode 100644 index 000000000..554ad830f --- /dev/null +++ b/frontend/ubuntu/focal.go @@ -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, + } +) diff --git a/frontend/ubuntu/noble.go b/frontend/ubuntu/noble.go new file mode 100644 index 000000000..97f3ba8c7 --- /dev/null +++ b/frontend/ubuntu/noble.go @@ -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, + } +) diff --git a/frontend/windows/handler.go b/frontend/windows/handler.go index 5ec62a58e..01a7102e5 100644 --- a/frontend/windows/handler.go +++ b/frontend/windows/handler.go @@ -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" @@ -40,7 +39,7 @@ var ( "zip", "aptitude", "dpkg-dev", - "debhelper-compat=" + deb.DebHelperCompat, + "debhelper", }, } ) diff --git a/test/azlinux_test.go b/test/azlinux_test.go index 9c0019e4c..0b00445e8 100644 --- a/test/azlinux_test.go +++ b/test/azlinux_test.go @@ -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 { @@ -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() @@ -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{ diff --git a/test/ubuntu_test.go b/test/ubuntu_test.go index 7332131db..294545eec 100644 --- a/test/ubuntu_test.go +++ b/test/ubuntu_test.go @@ -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", @@ -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 { @@ -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"))) +} diff --git a/website/docs/targets.md b/website/docs/targets.md index cf58fda5d..bf0b63eee 100644 --- a/website/docs/targets.md +++ b/website/docs/targets.md @@ -11,7 +11,8 @@ 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. @@ -19,9 +20,21 @@ azlinux3/rpm/debug/buildroot Outputs an rpm buildroot suitable for passing t 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. @@ -29,11 +42,34 @@ mariner2/rpm/debug/buildroot Outputs an rpm buildroot suitable for passing t 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=` flag is set, the list of targets will be filtered based +on ``. + +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.