File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,6 @@ class ParseVersion(enum.StrEnum):
8282 PATCH_UPDATE = enum .auto ()
8383 OFFSET = enum .auto ()
8484
85-
8685@dataclass
8786class StableUser :
8887 """Data class that stores information about stable user and group
@@ -97,7 +96,8 @@ class StableUser:
9796 group_name : str
9897 # id of the group
9998 group_id : int
100-
99+ # boolean flag that checks if user needs to be created
100+ user_create : bool = False
101101
102102@dataclass
103103class Replacement :
Original file line number Diff line number Diff line change 44from bci_build .os_version import ALL_NONBASE_OS_VERSIONS
55from bci_build .os_version import CAN_BE_LATEST_OS_VERSION
66from bci_build .package import ApplicationStackContainer
7+ from bci_build .package import StableUser
78from bci_build .package import ParseVersion
89from bci_build .package import Replacement
910from bci_build .package .helpers import generate_from_image_tag
3940 ),
4041 ],
4142 license = "GPL-2.0-only" ,
43+
4244 package_list = [
4345 "git-core" ,
4446 "openssh-clients" ,
47+ "shadow"
4548 ],
4649 build_stage_custom_end = generate_package_version_check (
4750 "git-core" , git_version , ParseVersion .MINOR , use_target = True
4851 ),
52+ user_chown = StableUser (
53+ user_id = 1000 ,
54+ user_name = "git" ,
55+ group_id = 1000 ,
56+ group_name = "git" ,
57+ user_create = True
58+ ),
4959 )
5060 for os_version in ALL_NONBASE_OS_VERSIONS
5161]
Original file line number Diff line number Diff line change 5555 {% endif -%} zypper -n {%- if image.from_target_image %} --installroot /target --gpg-auto-import-keys {%- endif %} install {% if image.no_recommends %}--no-recommends {% endif %}{{ image.packages }}{%- if image.packages_to_delete %}; \\
5656 zypper -n {%- if image.from_target_image %} --installroot /target {%- endif %} remove {{ image.packages_to_delete }}{%- endif %}
5757{%- endif %}
58- {%- if image.user_chown %}
58+ {%- if image.user_chown and not image.user_chown.user_create %}
5959# changing user id and group id created by package installation to stable values
6060{{ DOCKERFILE_RUN }} \\
6161 {% if image.from_target_image %}chroot /target {% endif %}chown -R --from={{ image.user_chown.user_name }}:{{ image.user_chown.group_name }} {{ image.user_chown.user_id }}:{{ image.user_chown.group_id }} /; \\
6262 groupmod {% if image.from_target_image %}-R /target {% endif %}-g {{ image.user_chown.group_id }} {{ image.user_chown.group_name }}; \\
6363 usermod {% if image.from_target_image %}-R /target {% endif %}-u {{ image.user_chown.user_id }} {{ image.user_chown.user_name }}
6464{%- endif %}
65+ {%- if image.user_chown and image.user_chown.user_create%}
66+ # create the user and group with the given ids
67+ {{ DOCKERFILE_RUN }} \\
68+ groupadd {% if image.from_target_image %}-R /target {% endif %}-g {{ image.user_chown.group_id }} -r {{ image.user_chown.group_name }}; \\
69+ useradd {% if image.from_target_image %}-R /target {% endif %}-u {{ image.user_chown.user_id }} -g {{ image.user_chown.group_id }} -m -r -s /bin/bash {{ image.user_chown.user_name }}
70+ {%- endif %}
6571{%- if image.build_stage_custom_end %}
6672{{ image.build_stage_custom_end }}
6773{%- endif %}
You can’t perform that action at this time.
0 commit comments