Skip to content

Commit fb021f5

Browse files
committed
feat(dockerfile): added data structure for --mount=type=ssh
1 parent a5c09bb commit fb021f5

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

rigel/plugins/core/dockerfile/models.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,66 @@ def validate_mode(cls, value: Optional[str]) -> str:
9393

9494
return value
9595

96+
class SSH(BaseModel, extra=Extra.forbid):
97+
"""Represents an SSH agent or key to be used in the Dockerfile.
98+
99+
:type id: string
100+
:cvar id: ID of the SSH agent or key. Defaults to 'default'.
101+
:type target: string
102+
:cvar target: The path where the SSH agent socket path in the container. Defaults to /run/buildkit/ssh_agent.{N} if not set.
103+
:type required: bool
104+
:cvar required: Flag to indicate if the SSH agent or key is required. The RUN instruction errors if the SSH agent or key is unavailable. Defaults to False.
105+
:type mode: string
106+
:cvar mode: The file mode for the SSH agent socket. Defaults to 0600 (octal).
107+
:type uid: int
108+
:cvar uid: The user ID for the SSH agent socket. Defaults to 0.
109+
:type gid: int
110+
:cvar gid: The group ID for the SSH agent socket. Defaults to 0.
111+
"""
112+
# Static field - keep track for unique (DEFAULT) target names
113+
# Note: Meaningless if there is only one SSH agent per RUN instruction.
114+
# Needs implementation change if we start supporting multiple SSH agents in the same RUN instruction. Depends on how that is done.
115+
_counter: int = 0
116+
117+
# Required fields
118+
id: str = 'default'
119+
target: Optional[str] = None
120+
121+
# Optional fields
122+
# - Default values
123+
DEFAULT_REQUIRED = False
124+
DEFAULT_MODE = '0600'
125+
DEFAULT_UID = 0
126+
DEFAULT_GID = 0
127+
128+
required: bool = DEFAULT_REQUIRED
129+
mode: str = DEFAULT_MODE
130+
uid: int = DEFAULT_UID
131+
gid: int = DEFAULT_GID
132+
133+
def __init__(self, **data: Any):
134+
if not data.get('target'):
135+
data['target'] = f"/run/buildkit/ssh_agent.{SSH._counter}"
136+
SSH._counter += 1
137+
super().__init__(**data)
138+
139+
@validator('mode')
140+
def validate_mode(cls, value: Optional[str]) -> str:
141+
"""Ensure that the mode is a valid octal string and within the range of 0000 to 0777.
142+
143+
:type value: string
144+
:param value: The mode to be validated.
145+
"""
146+
try:
147+
mode = int(value, 8)
148+
except ValueError:
149+
raise InvalidValueError('mode', value)
150+
151+
if not (0 <= mode <= 0o777):
152+
raise InvalidValueError('mode', value)
153+
154+
return value
155+
96156

97157
class PluginModel(BaseModel, extra=Extra.forbid):
98158
"""A plugin that creates a ready-to-use Dockerfile for an existing ROS package.
@@ -127,6 +187,7 @@ class PluginModel(BaseModel, extra=Extra.forbid):
127187
apt: List[str] = []
128188
ignore: List[str] = []
129189
secrets: List[Secret] = []
190+
ssh: List[SSH] = []
130191

131192
entrypoint: List[str] = []
132193
env: List[Dict[str, Any]] = []

0 commit comments

Comments
 (0)