-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support MAC and IP address on service
- Loading branch information
Showing
5 changed files
with
282 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
version: '3.7' | ||
name: "myproject" | ||
services: | ||
teddycloud: | ||
container_name: container | ||
mac_address: 10:50:02:01:00:02 | ||
dns: 192.168.8.1 | ||
hostname: tc | ||
image: ghcr.io/container/container:latest | ||
ports: | ||
- 80:80 | ||
- 443:443 | ||
volumes: | ||
- /opt/container/certs:/container/certs | ||
restart: unless-stopped | ||
networks: | ||
homenet: | ||
ipv4_address: 192.168.8.10 | ||
|
||
networks: | ||
homenet: | ||
driver: macvlan | ||
driver_opts: | ||
parent: enp2s0 | ||
ipam: | ||
config: | ||
- subnet: 192.168.8.0/24 | ||
gateway: 192.168.8.1 | ||
|
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,76 @@ | ||
{ pkgs, lib, ... }: | ||
|
||
{ | ||
# Runtime | ||
virtualisation.docker = { | ||
enable = true; | ||
autoPrune.enable = true; | ||
}; | ||
virtualisation.oci-containers.backend = "docker"; | ||
|
||
# Containers | ||
virtualisation.oci-containers.containers."container" = { | ||
image = "ghcr.io/container/container:latest"; | ||
volumes = [ | ||
"/opt/container/certs:/container/certs:rw" | ||
]; | ||
ports = [ | ||
"80:80/tcp" | ||
"443:443/tcp" | ||
]; | ||
log-driver = "journald"; | ||
autoStart = false; | ||
extraOptions = [ | ||
"--dns=192.168.8.1" | ||
"--hostname=tc" | ||
"--ip=192.168.8.10" | ||
"--mac-address=10:50:02:01:00:02" | ||
"--network-alias=teddycloud" | ||
"--network=myproject-homenet" | ||
]; | ||
}; | ||
systemd.services."docker-container" = { | ||
serviceConfig = { | ||
Restart = lib.mkOverride 500 "always"; | ||
RestartMaxDelaySec = lib.mkOverride 500 "1m"; | ||
RestartSec = lib.mkOverride 500 "100ms"; | ||
RestartSteps = lib.mkOverride 500 9; | ||
}; | ||
after = [ | ||
"docker-network-myproject-homenet.service" | ||
]; | ||
requires = [ | ||
"docker-network-myproject-homenet.service" | ||
]; | ||
partOf = [ | ||
"docker-compose-myproject-root.target" | ||
]; | ||
wantedBy = [ | ||
"docker-compose-myproject-root.target" | ||
]; | ||
}; | ||
|
||
# Networks | ||
systemd.services."docker-network-myproject-homenet" = { | ||
path = [ pkgs.docker ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
ExecStop = "${pkgs.docker}/bin/docker network rm -f myproject-homenet"; | ||
}; | ||
script = '' | ||
docker network inspect myproject-homenet || docker network create myproject-homenet | ||
''; | ||
partOf = [ "docker-compose-myproject-root.target" ]; | ||
wantedBy = [ "docker-compose-myproject-root.target" ]; | ||
}; | ||
|
||
# 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-myproject-root" = { | ||
unitConfig = { | ||
Description = "Root target generated by compose2nix."; | ||
}; | ||
}; | ||
} |
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,78 @@ | ||
{ pkgs, lib, ... }: | ||
|
||
{ | ||
# Runtime | ||
virtualisation.podman = { | ||
enable = true; | ||
autoPrune.enable = true; | ||
dockerCompat = true; | ||
defaultNetwork.settings = { | ||
# Required for container networking to be able to use names. | ||
dns_enabled = true; | ||
}; | ||
}; | ||
virtualisation.oci-containers.backend = "podman"; | ||
|
||
# Containers | ||
virtualisation.oci-containers.containers."container" = { | ||
image = "ghcr.io/container/container:latest"; | ||
volumes = [ | ||
"/opt/container/certs:/container/certs:rw" | ||
]; | ||
ports = [ | ||
"80:80/tcp" | ||
"443:443/tcp" | ||
]; | ||
log-driver = "journald"; | ||
autoStart = false; | ||
extraOptions = [ | ||
"--dns=192.168.8.1" | ||
"--hostname=tc" | ||
"--ip=192.168.8.10" | ||
"--mac-address=10:50:02:01:00:02" | ||
"--network-alias=teddycloud" | ||
"--network=myproject-homenet" | ||
]; | ||
}; | ||
systemd.services."podman-container" = { | ||
serviceConfig = { | ||
Restart = lib.mkOverride 500 "always"; | ||
}; | ||
after = [ | ||
"podman-network-myproject-homenet.service" | ||
]; | ||
requires = [ | ||
"podman-network-myproject-homenet.service" | ||
]; | ||
partOf = [ | ||
"podman-compose-myproject-root.target" | ||
]; | ||
wantedBy = [ | ||
"podman-compose-myproject-root.target" | ||
]; | ||
}; | ||
|
||
# Networks | ||
systemd.services."podman-network-myproject-homenet" = { | ||
path = [ pkgs.podman ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
ExecStop = "${pkgs.podman}/bin/podman network rm -f myproject-homenet"; | ||
}; | ||
script = '' | ||
podman network inspect myproject-homenet || podman network create myproject-homenet --opt isolate=true | ||
''; | ||
partOf = [ "podman-compose-myproject-root.target" ]; | ||
wantedBy = [ "podman-compose-myproject-root.target" ]; | ||
}; | ||
|
||
# Root service | ||
# When started, this will automatically create all resources and start | ||
# the containers. When stopped, this will teardown all resources. | ||
systemd.targets."podman-compose-myproject-root" = { | ||
unitConfig = { | ||
Description = "Root target generated by compose2nix."; | ||
}; | ||
}; | ||
} |