Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: oci layering #112

Merged
merged 8 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
rename pkgs to packages
Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com>
  • Loading branch information
rakshitgondwal committed Aug 27, 2024
commit facc8c8c97761fa33178b74de4a234c8d596b07f
4 changes: 2 additions & 2 deletions cmd/init/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func generateEmptyConf(imageName string, addCommonDeps bool, commonDepsType stri
Name: imageName,
IsBase: true,
Layers: []string{
"split(pkgs.runtime)",
"split(pkgs.dev)",
"split(packages.runtime)",
"split(packages.dev)",
},
Cmd: []string{},
Entrypoint: []string{},
Expand Down
34 changes: 17 additions & 17 deletions pkg/nix/template/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ociImage_{{$artifact.Artifact}} = forEachSupportedSystem ({ pkgs, nix2containerP
{{end}}

{{ if ne ($artifact.Base) true }}
ociImage_{{$artifact.Artifact}}_app-as-dir = pkgs.runCommand "image-as-dir" { } "${inputs.self.ociImage_{{$artifact.Artifact}}.${system}.ociImage_{{$artifact.Artifact}}_app.copyTo}/bin/copy-to dir:$out";
ociImage_{{$artifact.Artifact}}_app-as-dir = pkgs.runCommand "image-as-dir" { } "${inputs.self.ociImage_{{$artifact.Artifact}}gs.${system}.ociImage_{{$artifact.Artifact}}_app.copyTo}/bin/copy-to dir:$out";
{{end}}
{{ if ($artifact.Base)}}
ociImage_{{$artifact.Artifact}}_base-as-dir = pkgs.runCommand "image-as-dir" { } "${inputs.self.ociImage_{{$artifact.Artifact}}.${system}.ociImage_{{$artifact.Artifact}}_base.copyTo}/bin/copy-to dir:$out";
Expand Down Expand Up @@ -172,25 +172,25 @@ func handleCombinedLayers(layer string, fl Flake) []string {

for _, part := range parts {
switch {
case part == "split(pkgs.runtime)":
case part == "split(packages.runtime)":
for key, value := range fl.RuntimePackages {
combinedLayer = append(combinedLayer, "nixpkgs-"+value+"-pkgs."+key)
}
case part == "split(pkgs.dev)":
case part == "split(packages.dev)":
for key, value := range fl.DevPackages {
combinedLayer = append(combinedLayer, "nixpkgs-"+value+"-pkgs."+key)
}
case part == "pkgs.runtime":
case part == "packages.runtime":
combinedLayer = append(combinedLayer, "inputs.self.runtimeEnvs.${system}.runtime")
case part == "pkgs.dev":
case part == "packages.dev":
combinedLayer = append(combinedLayer, "inputs.self.devEnvs.${system}.development")
case strings.HasPrefix(part, "pkgs.dev."):
pkgName := strings.TrimPrefix(part, "pkgs.dev.")
case strings.HasPrefix(part, "packages.dev."):
pkgName := strings.TrimPrefix(part, "packages.dev.")
if value, exists := fl.DevPackages[pkgName]; exists {
combinedLayer = append(combinedLayer, "nixpkgs-"+value+"-pkgs."+pkgName)
}
case strings.HasPrefix(part, "pkgs.runtime."):
pkgName := strings.TrimPrefix(part, "pkgs.runtime.")
case strings.HasPrefix(part, "packages.runtime."):
pkgName := strings.TrimPrefix(part, "packages.runtime.")
if value, exists := fl.RuntimePackages[pkgName]; exists {
combinedLayer = append(combinedLayer, "nixpkgs-"+value+"-pkgs."+pkgName)
}
Expand All @@ -204,25 +204,25 @@ func handleIndividualLayers(layer string, fl Flake) [][]string {
var newLayers [][]string

switch {
case layer == "split(pkgs.runtime)":
case layer == "split(packages.runtime)":
for key, value := range fl.RuntimePackages {
newLayers = append(newLayers, []string{"nixpkgs-" + value + "-pkgs." + key})
}
case layer == "split(pkgs.dev)":
case layer == "split(packages.dev)":
for key, value := range fl.DevPackages {
newLayers = append(newLayers, []string{"nixpkgs-" + value + "-pkgs." + key})
}
case layer == "pkgs.runtime":
case layer == "packages.runtime":
newLayers = append(newLayers, []string{"inputs.self.runtimeEnvs.${system}.runtime"})
case layer == "pkgs.dev":
case layer == "packages.dev":
newLayers = append(newLayers, []string{"inputs.self.devEnvs.${system}.development"})
case strings.HasPrefix(layer, "pkgs.dev."):
pkgName := strings.TrimPrefix(layer, "pkgs.dev.")
case strings.HasPrefix(layer, "packages.dev."):
pkgName := strings.TrimPrefix(layer, "packages.dev.")
if value, exists := fl.DevPackages[pkgName]; exists {
newLayers = append(newLayers, []string{"nixpkgs-" + value + "-pkgs." + pkgName})
}
case strings.HasPrefix(layer, "pkgs.runtime."):
pkgName := strings.TrimPrefix(layer, "pkgs.runtime.")
case strings.HasPrefix(layer, "packages.runtime."):
pkgName := strings.TrimPrefix(layer, "packages.runtime.")
if value, exists := fl.RuntimePackages[pkgName]; exists {
newLayers = append(newLayers, []string{"nixpkgs-" + value + "-pkgs." + pkgName})
}
Expand Down
26 changes: 13 additions & 13 deletions pkg/nix/template/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestGetReqPkgs(t *testing.T) {
}{
{
name: "Split runtime packages",
layers: []string{"split(pkgs.runtime)"},
layers: []string{"split(packages.runtime)"},
fl: Flake{
RuntimePackages: map[string]string{
"go": "d919897915f0f91216d2501b617d670deee993a0",
Expand All @@ -76,7 +76,7 @@ func TestGetReqPkgs(t *testing.T) {
},
{
name: "Split dev packages",
layers: []string{"split(pkgs.dev)"},
layers: []string{"split(packages.dev)"},
fl: Flake{
DevPackages: map[string]string{
"bash": "f2c55c8e7d3d843f75e2f18c8bf707b8a77c8a0f",
Expand All @@ -90,7 +90,7 @@ func TestGetReqPkgs(t *testing.T) {
},
{
name: "Specific dev package",
layers: []string{"pkgs.dev.bash"},
layers: []string{"packages.dev.bash"},
fl: Flake{
DevPackages: map[string]string{
"bash": "f2c55c8e7d3d843f75e2f18c8bf707b8a77c8a0f",
Expand All @@ -103,7 +103,7 @@ func TestGetReqPkgs(t *testing.T) {
},
{
name: "Specific runtime package",
layers: []string{"pkgs.runtime.go"},
layers: []string{"packages.runtime.go"},
fl: Flake{
RuntimePackages: map[string]string{
"go": "d919897915f0f91216d2501b617d670deee993a0",
Expand All @@ -116,7 +116,7 @@ func TestGetReqPkgs(t *testing.T) {
},
{
name: "Combined dev and runtime packages",
layers: []string{"pkgs.dev.go + pkgs.runtime.nginx"},
layers: []string{"packages.dev.go + packages.runtime.nginx"},
fl: Flake{
DevPackages: map[string]string{
"go": "d919897915f0f91216d2501b617d670deee993a0",
Expand All @@ -134,7 +134,7 @@ func TestGetReqPkgs(t *testing.T) {
},
{
name: "Combined dev pkg and whole runtime",
layers: []string{"pkgs.dev.go + pkgs.runtime"},
layers: []string{"packages.dev.go + packages.runtime"},
fl: Flake{
DevPackages: map[string]string{
"go": "d919897915f0f91216d2501b617d670deee993a0",
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestGetLayers(t *testing.T) {
}{
{
name: "Basic runtime and dev split",
layers: []string{"split(pkgs.runtime)", "split(pkgs.dev)"},
layers: []string{"split(packages.runtime)", "split(packages.dev)"},
fl: Flake{
DevPackages: map[string]string{
"bash": "f2c55c8e7d3d843f75e2f18c8bf707b8a77c8a0f",
Expand All @@ -193,7 +193,7 @@ func TestGetLayers(t *testing.T) {
},
{
name: "Combined dev pkg and split runtime",
layers: []string{"pkgs.dev.go + split(pkgs.runtime)"},
layers: []string{"packages.dev.go + split(packages.runtime)"},
fl: Flake{
DevPackages: map[string]string{
"go": "7445ccd775d8b892fc56448d17345443a05f7fb4",
Expand All @@ -213,7 +213,7 @@ func TestGetLayers(t *testing.T) {
},
{
name: "Single dev package",
layers: []string{"pkgs.dev.go"},
layers: []string{"packages.dev.go"},
fl: Flake{
DevPackages: map[string]string{
"go": "7445ccd775d8b892fc56448d17345443a05f7fb4",
Expand All @@ -230,7 +230,7 @@ func TestGetLayers(t *testing.T) {
},
{
name: "Combined dev and runtime packages",
layers: []string{"pkgs.dev.go + pkgs.runtime.cacert"},
layers: []string{"packages.dev.go + packages.runtime.cacert"},
fl: Flake{
DevPackages: map[string]string{
"go": "7445ccd775d8b892fc56448d17345443a05f7fb4",
Expand All @@ -250,7 +250,7 @@ func TestGetLayers(t *testing.T) {
},
{
name: "Combined dev and whole runtime",
layers: []string{"pkgs.dev.go + pkgs.runtime"},
layers: []string{"packages.dev.go + packages.runtime"},
fl: Flake{
DevPackages: map[string]string{
"go": "7445ccd775d8b892fc56448d17345443a05f7fb4",
Expand All @@ -268,7 +268,7 @@ func TestGetLayers(t *testing.T) {
},
{
name: "Split dev and runtime",
layers: []string{"split(pkgs.dev)", "split(pkgs.runtime)"},
layers: []string{"split(packages.dev)", "split(packages.runtime)"},
fl: Flake{
DevPackages: map[string]string{
"go": "7445ccd775d8b892fc56448d17345443a05f7fb4",
Expand Down Expand Up @@ -298,7 +298,7 @@ func TestGetLayers(t *testing.T) {
},
{
name: "No split, just raw layers",
layers: []string{"pkgs.dev", "pkgs.runtime"},
layers: []string{"packages.dev", "packages.runtime"},
fl: Flake{
DevPackages: map[string]string{
"bash": "f2c55c8e7d3d843f75e2f18c8bf707b8a77c8a0f",
Expand Down
Loading