mirror of
https://github.com/nlewo/nix2container.git
synced 2024-09-11 16:36:39 +03:00
Release 1.0.0
This commit is contained in:
parent
0e5b565b3a
commit
3452fa7cae
@ -1,7 +1,5 @@
|
||||
# nix2container
|
||||
|
||||
**warning: nix2container is in early development stages and interfaces are not stable**
|
||||
|
||||
nix2container provides an efficient container development workflow
|
||||
with images built by Nix: it doesn't write tarballs to the Nix store
|
||||
and allows to skip already pushed layers (without having to rebuild
|
||||
|
@ -62,6 +62,8 @@ func image(outputFilename, imageConfigPath string, fromImageFilename string, lay
|
||||
var imageConfig v1.ImageConfig
|
||||
var image types.Image
|
||||
|
||||
image.Version = types.ImageVersion
|
||||
|
||||
logrus.Infof("Getting image configuration from %s", imageConfigPath)
|
||||
imageConfigJson, err := os.ReadFile(imageConfigPath)
|
||||
if err != nil {
|
||||
|
22
default.nix
22
default.nix
@ -2,10 +2,9 @@
|
||||
let
|
||||
l = pkgs.lib // builtins;
|
||||
|
||||
nix2containerUtil = pkgs.buildGoModule rec {
|
||||
nix2container-bin = pkgs.buildGoModule rec {
|
||||
pname = "nix2container";
|
||||
version = "0.0.1";
|
||||
doCheck = false;
|
||||
version = "1.0.0";
|
||||
src = l.cleanSourceWith {
|
||||
src = ./.;
|
||||
filter = path: type:
|
||||
@ -24,20 +23,19 @@ let
|
||||
ldflags = pkgs.lib.optional pkgs.stdenv.isDarwin [
|
||||
"-X github.com/nlewo/nix2container/nix.useNixCaseHack=true"
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
skopeo-nix2container = pkgs.skopeo.overrideAttrs (old: {
|
||||
EXTRA_LDFLAGS = pkgs.lib.optionalString pkgs.stdenv.isDarwin "-X github.com/nlewo/nix2container/nix.useNixCaseHack=true";
|
||||
preBuild = let
|
||||
patch = pkgs.fetchurl {
|
||||
url = "https://github.com/Mic92/image/commit/b3cb51066518ed2c6f6c8cf0cb4ae1e84f68b5ce.patch";
|
||||
sha256 = "sha256-GkBVoXUVQbZb8/dYJAbCsUJLDAZ/ORiMg8svACAyrwk=";
|
||||
url = "https://github.com/nlewo/image/commit/c2254c998433cf02af60bf0292042bd80b96a77e.patch";
|
||||
sha256 = "sha256-dKEObfZY2fdsza/kObCLhv4l2snuzAbpDi4fGmtTPUQ=";
|
||||
|
||||
};
|
||||
in ''
|
||||
mkdir -p vendor/github.com/nlewo/nix2container/
|
||||
cp -r ${nix2containerUtil.src}/* vendor/github.com/nlewo/nix2container/
|
||||
cp -r ${nix2container-bin.src}/* vendor/github.com/nlewo/nix2container/
|
||||
cd vendor/github.com/containers/image/v5
|
||||
mkdir nix/
|
||||
touch nix/transport.go
|
||||
@ -128,7 +126,7 @@ let
|
||||
| cat # pipe through cat to force-disable progress bar
|
||||
'';
|
||||
in pkgs.runCommand "nix2container-${imageName}.json" { } ''
|
||||
${nix2containerUtil}/bin/nix2container image-from-dir $out ${dir}
|
||||
${nix2container-bin}/bin/nix2container image-from-dir $out ${dir}
|
||||
'';
|
||||
|
||||
buildLayer = {
|
||||
@ -193,7 +191,7 @@ let
|
||||
tarDirectory = l.optionalString (! reproducible) "--tar-directory $out";
|
||||
layersJSON = pkgs.runCommand "layers.json" {} ''
|
||||
mkdir $out
|
||||
${nix2containerUtil}/bin/nix2container ${subcommand} \
|
||||
${nix2container-bin}/bin/nix2container ${subcommand} \
|
||||
$out/layers.json \
|
||||
${closureGraph allDeps} \
|
||||
--max-layers ${toString maxLayers} \
|
||||
@ -280,7 +278,7 @@ let
|
||||
# controlled using nixUid/nixGid.
|
||||
nixUid ? 0,
|
||||
nixGid ? 0,
|
||||
# Deprecated: will be removed on v1
|
||||
# Deprecated: will be removed
|
||||
contents ? null,
|
||||
meta ? {},
|
||||
}:
|
||||
@ -344,7 +342,7 @@ let
|
||||
};
|
||||
}
|
||||
''
|
||||
${nix2containerUtil}/bin/nix2container image \
|
||||
${nix2container-bin}/bin/nix2container image \
|
||||
$out \
|
||||
${fromImageFlag} \
|
||||
${configFile} \
|
||||
@ -360,6 +358,6 @@ let
|
||||
;
|
||||
in
|
||||
{
|
||||
inherit nix2containerUtil skopeo-nix2container;
|
||||
inherit nix2container-bin skopeo-nix2container;
|
||||
nix2container = { inherit buildImage buildLayer pullImage; };
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ nix2container.buildImage {
|
||||
deps = [pkgs.bashInteractive];
|
||||
layers = [
|
||||
(nix2container.buildLayer {
|
||||
deps = [pkgs.readline81];
|
||||
deps = [pkgs.readline];
|
||||
})
|
||||
];
|
||||
})];
|
||||
|
@ -63,7 +63,9 @@ nix2container.buildImage {
|
||||
}];
|
||||
|
||||
config = {
|
||||
entrypoint = [ "${entrypoint}/bin/entrypoint" ];
|
||||
Entrypoint = [ "${entrypoint}/bin/entrypoint" ];
|
||||
User = "user";
|
||||
WorkingDir = "/home/user";
|
||||
Env = [
|
||||
"HOME=/home/user"
|
||||
"NIX_PAGER=cat"
|
||||
|
@ -17,11 +17,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1654807842,
|
||||
"narHash": "sha256-ADymZpr6LuTEBXcy6RtFHcUZdjKTBRTMYwu19WOx17E=",
|
||||
"lastModified": 1677612629,
|
||||
"narHash": "sha256-yC+9LfhfwOd5sXFW8TLnDmqVMNYiHXYPGy9BbdpRqfU=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "fc909087cc3386955f21b4665731dbdaceefb1d8",
|
||||
"rev": "111ca8e0378e88d9decaa1c6dd7597f35d8bc67f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
description = "nix2container";
|
||||
description = "nix2container: build container image with Nix";
|
||||
|
||||
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
@ -22,9 +22,9 @@
|
||||
in
|
||||
rec {
|
||||
packages = {
|
||||
inherit (nix2container) nix2containerUtil skopeo-nix2container nix2container;
|
||||
inherit (nix2container) nix2container-bin skopeo-nix2container nix2container;
|
||||
inherit examples tests;
|
||||
};
|
||||
defaultPackage = packages.nix2containerUtil;
|
||||
defaultPackage = packages.nix2container-bin;
|
||||
});
|
||||
}
|
||||
|
@ -119,6 +119,8 @@ func NewImageFromFile(filename string) (image types.Image, err error) {
|
||||
// the Skopeo dir transport. The directory needs to be a absolute
|
||||
// path since tarball filepaths are referenced in the image Layers.
|
||||
func NewImageFromDir(directory string) (image types.Image, err error) {
|
||||
image.Version = types.ImageVersion
|
||||
|
||||
manifestFile, err := os.Open(directory + "/manifest.json")
|
||||
if err != nil {
|
||||
return image, err
|
||||
|
@ -8,7 +8,13 @@ import (
|
||||
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
)
|
||||
|
||||
const ImageVersion = 1
|
||||
|
||||
// Image represent the JSON image file produced by nix2container. This
|
||||
// JSON file can then be used by the Skopeo Nix transport to actually
|
||||
// build the container image.
|
||||
type Image struct {
|
||||
Version int `json:"version"`
|
||||
ImageConfig v1.ImageConfig `json:"image-config"`
|
||||
Layers []Layer `json:"layers"`
|
||||
Arch string `json:"arch"`
|
||||
|
Loading…
Reference in New Issue
Block a user