lol

Merge pull request #201902 from ck3mp3r/dockertools-architecture-in-config-200725

Adding ability to set image architecture when creating OCI images using DockerTools

authored by

Robert Hensing and committed by
GitHub
470e6fd1 3071eef9

+43 -8
+4
doc/builders/images/dockertools.section.md
··· 62 62 63 63 - `config` is used to specify the configuration of the containers that will be started off the built image in Docker. The available options are listed in the [Docker Image Specification v1.2.0](https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions). 64 64 65 + - `architecture` is _optional_ and used to specify the image architecture, this is useful for multi-architecture builds that don't need cross compiling. If not specified it will default to `hostPlatform`. 66 + 65 67 - `diskSize` is used to specify the disk size of the VM used to build the image in megabytes. By default it's 1024 MiB. 66 68 67 69 - `buildVMMemorySize` is used to specify the memory size of the VM to build the image in megabytes. By default it's 512 MiB. ··· 140 142 *Default:* `[]` 141 143 142 144 `config` _optional_ 145 + 146 + `architecture` is _optional_ and used to specify the image architecture, this is useful for multi-architecture builds that don't need cross compiling. If not specified it will default to `hostPlatform`. 143 147 144 148 : Run-time configuration of the container. A full list of the options are available at in the [Docker Image Specification v1.2.0](https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions). 145 149
+14
nixos/tests/docker-tools.nix
··· 419 419 "docker rmi layered-image-with-path", 420 420 ) 421 421 422 + with subtest("Ensure correct architecture is present in manifests."): 423 + docker.succeed(""" 424 + docker load --input='${examples.build-image-with-architecture}' 425 + docker inspect build-image-with-architecture \ 426 + | ${pkgs.jq}/bin/jq -er '.[] | select(.Architecture=="arm64").Architecture' 427 + docker rmi build-image-with-architecture 428 + """) 429 + docker.succeed(""" 430 + ${examples.layered-image-with-architecture} | docker load 431 + docker inspect layered-image-with-architecture \ 432 + | ${pkgs.jq}/bin/jq -er '.[] | select(.Architecture=="arm64").Architecture' 433 + docker rmi layered-image-with-architecture 434 + """) 435 + 422 436 with subtest("etc"): 423 437 docker.succeed("${examples.etc} | docker load") 424 438 docker.succeed("docker run --rm etc | grep localhost")
+9 -7
pkgs/build-support/docker/default.nix
··· 74 74 # Reference: https://github.com/opencontainers/image-spec/blob/master/config.md#properties 75 75 # For the mapping from Nixpkgs system parameters to GOARCH, we can reuse the 76 76 # mapping from the go package. 77 - defaultArch = go.GOARCH; 77 + defaultArchitecture = go.GOARCH; 78 78 79 79 in 80 80 rec { ··· 101 101 , imageDigest 102 102 , sha256 103 103 , os ? "linux" 104 - , arch ? defaultArch 105 - 104 + , # Image architecture, defaults to the architecture of the `hostPlatform` when unset 105 + arch ? defaultArchitecture 106 106 # This is used to set name to the pulled image 107 107 , finalImageName ? imageName 108 108 # This used to set a tag to the pulled image ··· 514 514 keepContentsDirlinks ? false 515 515 , # Docker config; e.g. what command to run on the container. 516 516 config ? null 517 + , # Image architecture, defaults to the architecture of the `hostPlatform` when unset 518 + architecture ? defaultArchitecture 517 519 , # Optional bash script to run on the files prior to fixturizing the layer. 518 520 extraCommands ? "" 519 521 , uid ? 0 ··· 546 548 baseJson = 547 549 let 548 550 pure = writeText "${baseName}-config.json" (builtins.toJSON { 549 - inherit created config; 550 - architecture = defaultArch; 551 + inherit created config architecture; 551 552 preferLocalBuild = true; 552 553 os = "linux"; 553 554 }); ··· 838 839 contents ? [ ] 839 840 , # Docker config; e.g. what command to run on the container. 840 841 config ? { } 842 + , # Image architecture, defaults to the architecture of the `hostPlatform` when unset 843 + architecture ? defaultArchitecture 841 844 , # Time of creation of the image. Passing "now" will make the 842 845 # created date be the time of building. 843 846 created ? "1970-01-01T00:00:01Z" ··· 869 872 870 873 streamScript = writePython3 "stream" { } ./stream_layered_image.py; 871 874 baseJson = writeText "${baseName}-base.json" (builtins.toJSON { 872 - inherit config; 873 - architecture = defaultArch; 875 + inherit config architecture; 874 876 os = "linux"; 875 877 }); 876 878
+16 -1
pkgs/build-support/docker/examples.nix
··· 92 92 ]; 93 93 94 94 extraCommands = '' 95 - mkdir -p tmp 95 + mkdir -p tmp/nginx_client_body 96 96 97 97 # nginx still tries to read this directory even if error_log 98 98 # directive is specifying another file :/ ··· 697 697 layered-image-with-path = pkgs.dockerTools.streamLayeredImage { 698 698 name = "layered-image-with-path"; 699 699 tag = "latest"; 700 + contents = [ pkgs.bashInteractive ./test-dummy ]; 701 + }; 702 + 703 + build-image-with-architecture = buildImage { 704 + name = "build-image-with-architecture"; 705 + tag = "latest"; 706 + architecture = "arm64"; 707 + # Not recommended. Use `buildEnv` between copy and packages to avoid file duplication. 708 + copyToRoot = [ pkgs.bashInteractive ./test-dummy ]; 709 + }; 710 + 711 + layered-image-with-architecture = pkgs.dockerTools.streamLayeredImage { 712 + name = "layered-image-with-architecture"; 713 + tag = "latest"; 714 + architecture = "arm64"; 700 715 contents = [ pkgs.bashInteractive ./test-dummy ]; 701 716 }; 702 717