-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathmariadb.py
More file actions
182 lines (160 loc) · 6.61 KB
/
mariadb.py
File metadata and controls
182 lines (160 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
"""Container definition for the MariaDB database server and client."""
import re
from pathlib import Path
from bci_build.container_attributes import TCP
from bci_build.container_attributes import Arch
from bci_build.container_attributes import BuildType
from bci_build.container_attributes import SupportLevel
from bci_build.os_version import CAN_BE_LATEST_OS_VERSION
from bci_build.os_version import OsVersion
from bci_build.package import DOCKERFILE_RUN
from bci_build.package import ApplicationStackContainer
from bci_build.package import generate_disk_size_constraints
from bci_build.package.helpers import generate_from_image_tag
from bci_build.package.helpers import generate_package_version_check
from bci_build.package.versions import get_pkg_version
from bci_build.replacement import Replacement
from bci_build.util import ParseVersion
_MARIADB_IDEXEC = b"""#!/bin/bash
u=$1
shift
if ! id -u "$u" > /dev/null 2>&1; then
echo "Invalid user: $u"
exit 1
fi
exec setpriv --pdeathsig=keep --reuid="$u" --regid="$u" --clear-groups -- "$@"
"""
MARIADB_CONTAINERS = []
MARIADB_CLIENT_CONTAINERS = []
for os_version in (
OsVersion.SP6,
OsVersion.SP7,
OsVersion.SL16_0,
OsVersion.TUMBLEWEED,
):
mariadb_version = get_pkg_version("mariadb", os_version)
pkg_prefix = ""
if os_version.is_sle15:
pkg_prefix = "rmt-"
docker_entrypoint = (
Path(__file__).parent / "mariadb" / str(mariadb_version) / "entrypoint.sh"
).read_text()
# Patch up the version number to be the exact x.y.z version that we ship
# using the replace_using_pkg_version service
# Although the current version is not checking the patch level, this might
# change in the future
_MARIADB_VERSION_PLACEHOLDER = "%%mariadb_version%%"
docker_entrypoint = re.sub(
f'echo -n "{mariadb_version}.*-MariaDB"',
f'echo -n "{_MARIADB_VERSION_PLACEHOLDER}-MariaDB"',
docker_entrypoint,
)
_ENTRYPOINT_FNAME = "docker-entrypoint.sh"
healthcheck = (
Path(__file__).parent / "mariadb" / str(mariadb_version) / "healthcheck.sh"
).read_bytes()
MARIADB_CONTAINERS.append(
ApplicationStackContainer(
name="mariadb",
package_name=f"{pkg_prefix}mariadb-image",
version=_MARIADB_VERSION_PLACEHOLDER,
tag_version=mariadb_version,
exclusive_arch=[Arch.AARCH64, Arch.PPC64LE, Arch.S390X, Arch.X86_64],
os_version=os_version,
is_latest=os_version in CAN_BE_LATEST_OS_VERSION,
version_in_uid=False,
pretty_name="MariaDB Server",
from_target_image=generate_from_image_tag(os_version, "bci-micro"),
build_stage_custom_end=generate_package_version_check(
"mariadb", mariadb_version, use_target=True
),
replacements_via_service=[
Replacement(
regex_in_build_description=_MARIADB_VERSION_PLACEHOLDER,
package_name="mariadb",
file_name=_ENTRYPOINT_FNAME,
parse_version=ParseVersion.PATCH,
),
Replacement(
regex_in_build_description=_MARIADB_VERSION_PLACEHOLDER,
package_name="mariadb",
),
],
package_list=[
"coreutils",
"findutils",
"gawk",
"mariadb",
"mariadb-tools",
"openssl",
"sed",
"timezone",
"util-linux",
"zstd",
],
entrypoint=[_ENTRYPOINT_FNAME],
license="GPL-2.0-only",
extra_files={
_ENTRYPOINT_FNAME: docker_entrypoint,
"LICENSE": (
Path(__file__).parent / "mariadb" / str(mariadb_version) / "LICENSE"
).read_bytes(),
"healthcheck.sh": healthcheck,
"idexec": _MARIADB_IDEXEC,
"_constraints": generate_disk_size_constraints(11),
},
support_level=SupportLevel.L3,
build_recipe_type=BuildType.DOCKER,
cmd=["mariadbd"],
volumes=["/var/lib/mysql"],
exposes_ports=[TCP(3306)],
custom_end=rf"""{DOCKERFILE_RUN} mkdir /docker-entrypoint-initdb.d
# docker-entrypoint from https://github.com/MariaDB/mariadb-docker.git
COPY {_ENTRYPOINT_FNAME} /usr/local/bin/
{DOCKERFILE_RUN} chmod 755 /usr/local/bin/{_ENTRYPOINT_FNAME}
{DOCKERFILE_RUN} ln -s usr/local/bin/{_ENTRYPOINT_FNAME} / # backwards compat
# healthcheck from https://github.com/MariaDB/mariadb-docker.git
COPY healthcheck.sh /usr/local/bin/
{DOCKERFILE_RUN} chmod 755 /usr/local/bin/healthcheck.sh
COPY idexec /usr/local/bin/idexec
{DOCKERFILE_RUN} chmod 755 /usr/local/bin/idexec
# replace gosu calls with idexec
{DOCKERFILE_RUN} sed -i 's/exec gosu /exec idexec /g' /usr/local/bin/{_ENTRYPOINT_FNAME}
{DOCKERFILE_RUN} sed -i 's/exec gosu /exec idexec /g' /usr/local/bin/healthcheck.sh
{DOCKERFILE_RUN} sed -i -e 's,$(pwgen .*),$(openssl rand -base64 36),' /usr/local/bin/{_ENTRYPOINT_FNAME}
# Ensure all logs goes to stdout
{DOCKERFILE_RUN} sed -i 's/^log/#log/g' /etc/my.cnf
# Disable binding to localhost only, doesn't make sense in a container
{DOCKERFILE_RUN} sed -i -e 's|^\(bind-address.*\)|#\1|g' /etc/my.cnf
{DOCKERFILE_RUN} install -d -m 0755 -o mysql -g mysql /run/mysql
{DOCKERFILE_RUN} install -d -m 0700 -o mysql -g root /var/lib/mysql
""",
)
)
MARIADB_CLIENT_CONTAINERS.append(
ApplicationStackContainer(
name="mariadb-client",
package_name=f"{pkg_prefix}mariadb-client-image",
exclusive_arch=[Arch.AARCH64, Arch.PPC64LE, Arch.S390X, Arch.X86_64],
os_version=os_version,
is_latest=os_version in CAN_BE_LATEST_OS_VERSION,
version_in_uid=False,
version=_MARIADB_VERSION_PLACEHOLDER,
from_target_image=generate_from_image_tag(os_version, "bci-micro"),
build_stage_custom_end=generate_package_version_check(
"mariadb-client", mariadb_version, use_target=True
),
tag_version=mariadb_version,
pretty_name="MariaDB Client",
support_level=SupportLevel.L3,
package_list=["mariadb-client"],
build_recipe_type=BuildType.DOCKER,
cmd=["mariadb"],
replacements_via_service=[
Replacement(
regex_in_build_description=_MARIADB_VERSION_PLACEHOLDER,
package_name="mariadb-client",
),
],
)
)