Merge pull request #63865 from dingxiangfei2009/dockertools-cross-compilation

dockerTools: use skopeo on the right platform
This commit is contained in:
Sarah Brofeldt 2019-07-31 20:11:18 +02:00 committed by GitHub
commit 19abdb765b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,37 +1,41 @@
{ {
symlinkJoin, cacert,
callPackage,
closureInfo,
coreutils, coreutils,
docker, docker,
e2fsprogs, e2fsprogs,
findutils, findutils,
go, go,
jshon,
jq, jq,
jshon,
lib, lib,
pkgs, moreutils,
pigz,
nix, nix,
runCommand, pigz,
referencesByPopularity,
rsync, rsync,
runCommand,
runtimeShell,
shadow, shadow,
skopeo,
stdenv,
storeDir ? builtins.storeDir, storeDir ? builtins.storeDir,
substituteAll,
symlinkJoin,
utillinux, utillinux,
vmTools, vmTools,
writeReferencesToFile, writeReferencesToFile,
referencesByPopularity,
writeScript, writeScript,
writeText, writeText,
closureInfo,
substituteAll,
runtimeShell
}: }:
# WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future. # WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future.
rec { rec {
examples = import ./examples.nix { examples = callPackage ./examples.nix {
inherit pkgs buildImage pullImage shadowSetup buildImageWithNixDb; inherit buildImage pullImage shadowSetup buildImageWithNixDb;
}; };
pullImage = let pullImage = let
@ -57,13 +61,13 @@ rec {
inherit imageDigest; inherit imageDigest;
imageName = finalImageName; imageName = finalImageName;
imageTag = finalImageTag; imageTag = finalImageTag;
impureEnvVars = pkgs.stdenv.lib.fetchers.proxyImpureEnvVars; impureEnvVars = stdenv.lib.fetchers.proxyImpureEnvVars;
outputHashMode = "flat"; outputHashMode = "flat";
outputHashAlgo = "sha256"; outputHashAlgo = "sha256";
outputHash = sha256; outputHash = sha256;
nativeBuildInputs = lib.singleton (pkgs.skopeo); nativeBuildInputs = lib.singleton skopeo;
SSL_CERT_FILE = "${pkgs.cacert.out}/etc/ssl/certs/ca-bundle.crt"; SSL_CERT_FILE = "${cacert.out}/etc/ssl/certs/ca-bundle.crt";
sourceURL = "docker://${imageName}@${imageDigest}"; sourceURL = "docker://${imageName}@${imageDigest}";
destNameTag = "${finalImageName}:${finalImageTag}"; destNameTag = "${finalImageName}:${finalImageTag}";
@ -156,7 +160,8 @@ rec {
postMount ? "", postMount ? "",
postUmount ? "" postUmount ? ""
}: }:
vmTools.runInLinuxVM ( let
result = vmTools.runInLinuxVM (
runCommand name { runCommand name {
preVM = vmTools.createEmptyImage { preVM = vmTools.createEmptyImage {
size = diskSize; size = diskSize;
@ -166,8 +171,6 @@ rec {
nativeBuildInputs = [ utillinux e2fsprogs jshon rsync jq ]; nativeBuildInputs = [ utillinux e2fsprogs jshon rsync jq ];
} '' } ''
rm -rf $out
mkdir disk mkdir disk
mkfs /dev/${vmTools.hd} mkfs /dev/${vmTools.hd}
mount /dev/${vmTools.hd} disk mount /dev/${vmTools.hd} disk
@ -250,6 +253,12 @@ rec {
${postUmount} ${postUmount}
''); '');
in
runCommand name {} ''
mkdir -p $out
cd ${result}
cp layer.tar json VERSION $out
'';
exportImage = { name ? fromImage.name, fromImage, fromImageName ? null, fromImageTag ? null, diskSize ? 1024 }: exportImage = { name ? fromImage.name, fromImage, fromImageName ? null, fromImageTag ? null, diskSize ? 1024 }:
runWithOverlay { runWithOverlay {
@ -489,7 +498,7 @@ rec {
(cd layer; ${extraCommandsScript}) (cd layer; ${extraCommandsScript})
echo "Packing layer..." echo "Packing layer..."
mkdir $out mkdir -p $out
tar -C layer --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" -cf $out/layer.tar . tar -C layer --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" -cf $out/layer.tar .
# Compute the tar checksum and add it to the output json. # Compute the tar checksum and add it to the output json.
@ -670,7 +679,7 @@ rec {
extraCommands; extraCommands;
}; };
result = runCommand "docker-image-${baseName}.tar.gz" { result = runCommand "docker-image-${baseName}.tar.gz" {
nativeBuildInputs = [ jshon pigz coreutils findutils jq ]; nativeBuildInputs = [ jshon pigz coreutils findutils jq moreutils ];
# Image name and tag must be lowercase # Image name and tag must be lowercase
imageName = lib.toLower name; imageName = lib.toLower name;
imageTag = if tag == null then "" else lib.toLower tag; imageTag = if tag == null then "" else lib.toLower tag;
@ -784,7 +793,7 @@ rec {
# originally this used `sed -i "1i$layerID" layer-list`, but # originally this used `sed -i "1i$layerID" layer-list`, but
# would fail if layer-list was completely empty. # would fail if layer-list was completely empty.
echo "$layerID/layer.tar" echo "$layerID/layer.tar"
) | ${pkgs.moreutils}/bin/sponge layer-list ) | sponge layer-list
# Create image json and image manifest # Create image json and image manifest
imageJson=$(cat ${baseJson} | jq ". + {\"rootfs\": {\"diff_ids\": [], \"type\": \"layers\"}}") imageJson=$(cat ${baseJson} | jq ". + {\"rootfs\": {\"diff_ids\": [], \"type\": \"layers\"}}")