Skip to content

Commit

Permalink
Merge pull request #711 from noaccOS/chore/containers-interfaces-update
Browse files Browse the repository at this point in the history
chore(containers): support the latest version of the interfaces
  • Loading branch information
davidebriani authored Nov 13, 2024
2 parents 51efbc3 + 08171a3 commit 17aa717
Show file tree
Hide file tree
Showing 22 changed files with 756 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ defmodule Edgehog.Astarte.Device.CreateContainerRequest.RequestData do
:imageId,
:image,
:networkIds,
:volumeIds,
:hostname,
:restartPolicy,
:env,
:binds,
:networks,
:volumeIds,
:networkMode,
:portBindings,
:privileged
]
Expand All @@ -43,13 +43,13 @@ defmodule Edgehog.Astarte.Device.CreateContainerRequest.RequestData do
id: String.t(),
imageId: String.t(),
image: String.t(),
networkIds: list(String.t()),
volumeIds: list(String.t()),
hostname: String.t(),
restartPolicy: String.t(),
env: list(tuple()),
binds: list(String.t()),
networks: list(String.t()),
networkIds: list(String.t()),
networkMode: String.t(),
portBindings: list(String.t()),
privileged: String.t()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule Edgehog.Astarte.Device.CreateNetworkRequest do
client,
device_id,
@interface,
"/container",
"/network",
request_data
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ defmodule Edgehog.Astarte.Device.CreateNetworkRequest.RequestData do
defstruct [
:id,
:driver,
:checkDuplicate,
:internal,
:enableIpv6
:enableIpv6,
:options
]

@type t() :: %__MODULE__{
id: String.t(),
driver: String.t(),
checkDuplicate: boolean(),
internal: boolean(),
enableIpv6: boolean()
enableIpv6: boolean(),
options: [String.t()]
}
end
26 changes: 24 additions & 2 deletions backend/lib/edgehog/containers/container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,24 @@ defmodule Edgehog.Containers.Container do
defaults [
:read,
:destroy,
create: [:port_bindings, :restart_policy, :hostname, :env, :privileged, :image_id],
update: [:port_bindings, :restart_policy, :hostname, :env, :privileged, :image_id]
create: [
:port_bindings,
:restart_policy,
:hostname,
:network_mode,
:env,
:privileged,
:image_id
],
update: [
:port_bindings,
:restart_policy,
:hostname,
:network_mode,
:env,
:privileged,
:image_id
]
]

create :create_with_nested do
Expand Down Expand Up @@ -84,6 +100,12 @@ defmodule Edgehog.Containers.Container do
public? true
end

attribute :network_mode, :string do
default "bridge"
public? true
allow_nil? false
end

timestamps()
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Edgehog.Containers.ManualActions.SendDeploymentCommand do
@impl Ash.Resource.ManualUpdate
def update(changeset, opts, context) do
deployment = changeset.data
{:ok, command} = Keyword.pop!(opts, :command)
command = Keyword.fetch!(opts, :command)
%{tenant: tenant} = context

with {:ok, deployment} <- Ash.load(deployment, [:device, :release]),
Expand Down
10 changes: 5 additions & 5 deletions backend/lib/edgehog/containers/network.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Edgehog.Containers.Network do
end

actions do
defaults [:read, :destroy, create: [:driver, :check_duplicate, :internal, :enable_ipv6]]
defaults [:read, :destroy, create: [:driver, :internal, :enable_ipv6, :options]]
end

attributes do
Expand All @@ -41,21 +41,21 @@ defmodule Edgehog.Containers.Network do
public? true
end

attribute :check_duplicate, :boolean do
attribute :internal, :boolean do
default false
allow_nil? false
public? true
end

attribute :internal, :boolean do
attribute :enable_ipv6, :boolean do
default false
allow_nil? false
public? true
end

attribute :enable_ipv6, :boolean do
default false
attribute :options, {:array, :string} do
allow_nil? false
default []
public? true
end

Expand Down
1 change: 1 addition & 0 deletions backend/lib/edgehog/containers/types/deployment_status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule Edgehog.Containers.Types.DeploymentStatus do
@moduledoc false
use Ash.Type.Enum,
values: [
deleting: "The deployment is being deleted",
error: "The deployment process entered an error state.",
started: "The deployment is running.",
starting: "The deployment is starting.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ defmodule Edgehog.Devices.Device.ManualActions.SendCreateContainer do
id: container.id,
imageId: container.image_id,
image: image.reference,
networkIds: [],
volumeIds: [],
hostname: container.hostname,
restartPolicy: restart_policy,
env: env_encoding,
binds: [],
networks: Enum.map(container.networks, & &1.id),
networkIds: Enum.map(container.networks, & &1.id),
networkMode: container.network_mode,
portBindings: container.port_bindings,
privileged: container.privileged
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ defmodule Edgehog.Devices.Device.ManualActions.SendCreateNetwork do
data = %RequestData{
id: network.id,
driver: network.driver,
checkDuplicate: network.check_duplicate,
internal: network.internal,
enableIpv6: network.enable_ipv6
enableIpv6: network.enable_ipv6,
options: network.options
}

with :ok <-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Create Container Request id",
"doc": "Unique id for the container."
},
Expand All @@ -19,6 +20,7 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Container image id",
"doc": "The id of the image to use when creating the container."
},
Expand All @@ -27,6 +29,7 @@
"type": "stringarray",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Container network ids",
"doc": "The ids of the network to connect with the container."
},
Expand All @@ -35,6 +38,7 @@
"type": "stringarray",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Container volume ids",
"doc": "The ids of the volumes to mount on the container."
},
Expand All @@ -43,6 +47,7 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Container image",
"doc": "TODO: this will be remove (by only sending the image_id), when it will be supported on the device."
},
Expand All @@ -51,6 +56,7 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Container hostname",
"doc": "The hostname to use for the container, as a valid RFC 1123 hostname."
},
Expand All @@ -59,6 +65,7 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Container restart policy",
"doc": "The behavior to apply when the container exits. Possible values are: ['', 'no', 'always' 'unless-stopped', 'on-failure']"
},
Expand All @@ -67,6 +74,7 @@
"type": "stringarray",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Container environment",
"doc": "Array of KEY=value environment variables"
},
Expand All @@ -75,22 +83,25 @@
"type": "stringarray",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Container binds",
"doc": "Array of binds"
"doc": "A list of volume bindings for this container. Each volume binding is a string in one of these forms: host-src:container-dest[:options], or volume-name:container-dest[:options]. The container-dest must be an absolute path."
},
{
"endpoint": "/container/networks",
"type": "stringarray",
"endpoint": "/container/networkMode",
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"description": "Network configuration name",
"doc": "Name or id of an existing container network, inside the container runtime, to connect to."
"reliability": "guaranteed",
"description": "Network mode used for this container.",
"doc": "Supported standard values are: bridge, host, none, and container:<name|id>. Any other value is taken as a custom network's name to which this container should connect to. If you are using a different container engine than docker, there could be other values."
},
{
"endpoint": "/container/portBindings",
"type": "stringarray",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Container port bindings",
"doc": "Array of ip:[host_port:]container_port[/protocol] | [hostPort:]containerPort[/protocol]. Protocol is TCP by default"
},
Expand All @@ -99,6 +110,7 @@
"type": "boolean",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Run privileged",
"doc": "Runs the exec process with extended privileges."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Create Deployment Request id",
"doc": "Unique id for the deployment."
},
Expand All @@ -19,6 +20,7 @@
"type": "stringarray",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Deployment containers",
"doc": "Containers used by the deployment."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 600,
"reliability": "guaranteed",
"description": "Create Image Request id",
"doc": "Unique id for the container image."
},
Expand All @@ -21,6 +22,7 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 600,
"reliability": "guaranteed",
"description": "Image reference to be pulled",
"doc": "Name of the image to pull. It should be in the form [regitry-host[:port]/][image-repo/]image-name[:(tag|digest)]"
},
Expand All @@ -29,6 +31,7 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 600,
"reliability": "guaranteed",
"description": "Image registry authentication header",
"doc": "Optional base64url-encoded JSON for the auth configuration to the registry. An empty string means the image is public and doesn't require authentication. See https://docs.docker.com/reference/api/engine/version/v1.43/#section/Authentication for more information."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Create Network Request id",
"doc": "Unique id for the container network."
},
Expand All @@ -19,22 +20,16 @@
"type": "string",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"description": "Network dirver",
"reliability": "guaranteed",
"description": "Network driver",
"doc": "Name of the network driver plugin to use."
},
{
"endpoint": "/network/checkDuplicate",
"type": "boolean",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"description": "Check duplicate networks",
"doc": "Check for networks with duplicate names."
},
{
"endpoint": "/network/internal",
"type": "boolean",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Internal network",
"doc": "Restrict external access to the network."
},
Expand All @@ -43,8 +38,18 @@
"type": "boolean",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Enable IPv6",
"doc": "Enable IPv6 on the network."
},
{
"endpoint": "/network/options",
"type": "stringarray",
"database_retention_policy": "use_ttl",
"database_retention_ttl": 31556952,
"reliability": "guaranteed",
"description": "Network driver options",
"doc": "An array of key=value options to set for the driver."
}
]
}
Loading

0 comments on commit 17aa717

Please sign in to comment.