Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nlewo committed Mar 2, 2023
1 parent 0e5b565 commit 3452fa7
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 22 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 10 additions & 12 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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} \
Expand Down Expand Up @@ -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 ? {},
}:
Expand Down Expand Up @@ -344,7 +342,7 @@ let
};
}
''
${nix2containerUtil}/bin/nix2container image \
${nix2container-bin}/bin/nix2container image \
$out \
${fromImageFlag} \
${configFile} \
Expand All @@ -360,6 +358,6 @@ let
;
in
{
inherit nix2containerUtil skopeo-nix2container;
inherit nix2container-bin skopeo-nix2container;
nix2container = { inherit buildImage buildLayer pullImage; };
}
2 changes: 1 addition & 1 deletion examples/nested.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nix2container.buildImage {
deps = [pkgs.bashInteractive];
layers = [
(nix2container.buildLayer {
deps = [pkgs.readline81];
deps = [pkgs.readline];
})
];
})];
Expand Down
4 changes: 3 additions & 1 deletion examples/nix-user.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
});
}
2 changes: 2 additions & 0 deletions nix/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 3452fa7

Please sign in to comment.