-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial support for Compose Build spec
The idea is we generate a systemd (one-shot) service per build that users can run _manually_ to build the container and add it to the runtime's image store. An alternative considered is a one-shot service that automatically runs prior to the service. However, this would result in a _new_ build on every restart of the root target (or system), which would implicitly result in an update of the container. Similar to the Compose CLI, we can put this logic behind a `--build` flag, but this means that users would need to regenerate their Nix config after the build completes to disable/remove this service. For now, we do not support Git repo build contexts (i.e., pull from repo before building).
- Loading branch information
Showing
8 changed files
with
337 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
systemd.services."{{.Runtime}}-build-{{.ServiceName}}" = { | ||
{{- /* TODO: Support Git repo as a build source. */}} | ||
path = [ pkgs.{{.Runtime}} pkgs.git ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
}; | ||
script = '' | ||
cd {{.Context}} | ||
{{escapeIndentedNixString .Command}} | ||
''; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Adapted from: https://github.com/ente-io/ente/blob/main/server/compose.yaml | ||
services: | ||
museum: | ||
build: | ||
context: . | ||
args: | ||
GIT_COMMIT: development-cluster | ||
ports: | ||
- 8080:8080 # API | ||
- 2112:2112 # Prometheus metrics | ||
environment: | ||
# Pass-in the config to connect to the DB and MinIO | ||
ENTE_CREDENTIALS_FILE: /credentials.yaml | ||
volumes: | ||
- custom-logs:/var/logs | ||
- ./museum.yaml:/museum.yaml:ro | ||
- ./scripts/compose/credentials.yaml:/credentials.yaml:ro | ||
- ./data:/data:ro | ||
networks: | ||
- internal | ||
|
||
volumes: | ||
custom-logs: | ||
|
||
networks: | ||
internal: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ pkgs, lib, ... }: | ||
|
||
{ | ||
# Runtime | ||
virtualisation.docker = { | ||
enable = true; | ||
autoPrune.enable = true; | ||
}; | ||
virtualisation.oci-containers.backend = "docker"; | ||
|
||
# Containers | ||
virtualisation.oci-containers.containers."test-museum" = { | ||
image = ""; | ||
environment = { | ||
"ENTE_CREDENTIALS_FILE" = "/credentials.yaml"; | ||
}; | ||
volumes = [ | ||
"/some/path/data:/data:ro" | ||
"/some/path/museum.yaml:/museum.yaml:ro" | ||
"/some/path/scripts/compose/credentials.yaml:/credentials.yaml:ro" | ||
"test_custom-logs:/var/logs:rw" | ||
]; | ||
ports = [ | ||
"8080:8080/tcp" | ||
"2112:2112/tcp" | ||
]; | ||
log-driver = "journald"; | ||
autoStart = false; | ||
extraOptions = [ | ||
"--network-alias=museum" | ||
"--network=test_internal" | ||
]; | ||
}; | ||
systemd.services."docker-test-museum" = { | ||
serviceConfig = { | ||
Restart = lib.mkOverride 90 "no"; | ||
}; | ||
after = [ | ||
"docker-network-test_internal.service" | ||
"docker-volume-test_custom-logs.service" | ||
]; | ||
requires = [ | ||
"docker-network-test_internal.service" | ||
"docker-volume-test_custom-logs.service" | ||
]; | ||
}; | ||
|
||
# Networks | ||
systemd.services."docker-network-test_internal" = { | ||
path = [ pkgs.docker ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
ExecStop = "docker network rm -f test_internal"; | ||
}; | ||
script = '' | ||
docker network inspect test_internal || docker network create test_internal | ||
''; | ||
partOf = [ "docker-compose-test-root.target" ]; | ||
wantedBy = [ "docker-compose-test-root.target" ]; | ||
}; | ||
|
||
# Volumes | ||
systemd.services."docker-volume-test_custom-logs" = { | ||
path = [ pkgs.docker ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
}; | ||
script = '' | ||
docker volume inspect test_custom-logs || docker volume create test_custom-logs | ||
''; | ||
partOf = [ "docker-compose-test-root.target" ]; | ||
wantedBy = [ "docker-compose-test-root.target" ]; | ||
}; | ||
|
||
# Builds | ||
# | ||
# NOTE: These must be run manually before running any containers that require | ||
# them to be present in the image store. | ||
systemd.services."docker-build-museum" = { | ||
path = [ pkgs.docker pkgs.git ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
}; | ||
script = '' | ||
cd /some/path | ||
docker build --build-arg GIT_COMMIT=development-cluster -f Dockerfile . | ||
''; | ||
}; | ||
|
||
# Root service | ||
# When started, this will automatically create all resources and start | ||
# the containers. When stopped, this will teardown all resources. | ||
systemd.targets."docker-compose-test-root" = { | ||
unitConfig = { | ||
Description = "Root target generated by compose2nix."; | ||
}; | ||
}; | ||
} |
Oops, something went wrong.