-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathapache_tomcat.py
More file actions
153 lines (140 loc) · 6.6 KB
/
apache_tomcat.py
File metadata and controls
153 lines (140 loc) · 6.6 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
"""Provide an Apache Tomcat container."""
import datetime
from bci_build.container_attributes import TCP
from bci_build.container_attributes import PackageType
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 ContainerFamily
from bci_build.package import OsContainer
from bci_build.package import Package
from bci_build.package import Replacement
from bci_build.package import _build_tag_prefix
from bci_build.registry import publish_registry
# last version needs to be the newest
_TOMCAT_VERSIONS: list[str] = ["9", "10.1"]
assert _TOMCAT_VERSIONS == sorted(_TOMCAT_VERSIONS, key=float)
def _get_sac_supported_until(
os_version: OsVersion, tomcat_ver: str, jre_major: int
) -> datetime.date | None:
"""Return the predicted minimum end of support date for this os/tomcat/jre combination. We pick
the minimum time that either the given tomcat or JRE is known to be supported."""
if os_version.is_tumbleweed:
return None
# Taken from https://www.suse.com/releasenotes/x86_64/SUSE-SLES/15-SP6/index.html#java-version
jre_end_support_dates: dict[int, datetime.date] = {
21: datetime.date(2031, 6, 30),
17: datetime.date(2027, 12, 31),
11: datetime.date(2026, 12, 31),
8: datetime.date(2026, 12, 31),
}
# We do not have a documented policy, for now we do 3 years from initial publishing
tomcat_end_support_dates: dict[str, datetime.date] = {
"9": datetime.date(2024 + 3, 2, 1),
"10.1": datetime.date(2024 + 3, 7, 1),
}
# If neither is specified we can not determine a minimum
if (
tomcat_end_support_dates.get(tomcat_ver) is None
and jre_end_support_dates.get(jre_major) is None
):
return None
return min(
jre_end_support_dates.get(jre_major, datetime.date.max),
tomcat_end_support_dates.get(tomcat_ver, datetime.date.max),
)
def _get_java_packages(jre_major: int) -> list[str]:
"""Determine the right java packages to install, even when using the marketing version"""
if jre_major == 8:
return ["java-1_8_0-openjdk", "java-1_8_0-openjdk-headless"]
return [f"java-{jre_major}-openjdk", f"java-{jre_major}-openjdk-headless"]
TOMCAT_CONTAINERS = [
ApplicationStackContainer(
name="apache-tomcat",
package_name=(
f"apache-tomcat-{tomcat_ver.partition('.')[0]}-image"
if os_version.is_tumbleweed
else f"sac-apache-tomcat-{tomcat_ver.partition('.')[0]}-image"
),
_publish_registry=publish_registry(os_version, app_collection=True),
pretty_name="Apache Tomcat",
custom_description=(
"The Apache Tomcat software is an open-source implementation of the Jakarta Servlet, "
"Jakarta Pages, Jakarta Expression Language, Jakarta WebSocket, Jakarta Annotations, "
"and Jakarta Authentication specifications. These specifications are part of the Jakarta EE platform"
)
+ (". It is {based_on_container}." if os_version.is_tumbleweed else "."),
os_version=os_version,
is_latest=(
(os_version in CAN_BE_LATEST_OS_VERSION)
and tomcat_ver == _TOMCAT_VERSIONS[-1]
and jre_version == 22
and os_version.is_tumbleweed
),
version="%%tomcat_version%%",
tag_version=tomcat_ver,
build_flavor=f"openjdk{jre_version}",
_min_release_counter=58 if os_version.is_sle15 else None,
supported_until=_get_sac_supported_until(
os_version=os_version, tomcat_ver=tomcat_ver, jre_major=jre_version
),
from_target_image=f"{_build_tag_prefix(os_version)}/bci-micro:{OsContainer.version_to_container_os_version(os_version)}",
package_list=[
tomcat_pkg := (
"tomcat"
if tomcat_ver == _TOMCAT_VERSIONS[0]
else f"tomcat{tomcat_ver.partition('.')[0]}"
),
Package("util-linux", PackageType.DELETE),
]
+ _get_java_packages(jre_version),
replacements_via_service=[
Replacement(
regex_in_build_description="%%tomcat_version%%", package_name=tomcat_pkg
),
],
cmd=[
f"/usr/{'libexec' if os_version in (OsVersion.TUMBLEWEED, OsVersion.SLE16_0) else 'lib'}/tomcat/server",
"start",
],
exposes_ports=[TCP(8080)],
env={
"TOMCAT_MAJOR": int(tomcat_ver.partition(".")[0]),
"TOMCAT_VERSION": "%%tomcat_version%%",
"CATALINA_HOME": (_CATALINA_HOME := "/usr/share/tomcat"),
"CATALINA_BASE": _CATALINA_HOME,
"PATH": f"{_CATALINA_HOME}/bin:$PATH",
},
custom_end=rf"""{DOCKERFILE_RUN} mkdir -p /var/log/tomcat; chown --recursive tomcat:tomcat /var/log/tomcat
{DOCKERFILE_RUN} ln -s {_CATALINA_HOME} /usr/local/tomcat
{DOCKERFILE_RUN} """
+ r"""while IFS= read -r line; do \
line=${line/org\.apache\.catalina\.core\.ContainerBase\.\[Catalina\]\.\[localhost\]\.handlers =*/org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = java.util.logging.ConsoleHandler}; \
line=${line/org\.apache\.catalina\.core\.ContainerBase\.\[Catalina\]\.\[localhost\]\.\[\/manager\]\.handlers =*/org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = java.util.logging.ConsoleHandler}; \
line=${line/org\.apache\.catalina\.core\.ContainerBase\.\[Catalina\]\.\[localhost\]\.\[\/host-manager\]\.handlers =*/org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = java.util.logging.ConsoleHandler}; \
echo "$line" >> /tmp/logging.properties; \
done < /usr/share/tomcat/conf/logging.properties; \
mv /tmp/logging.properties /usr/share/tomcat/conf/logging.properties
WORKDIR $CATALINA_HOME
""",
entrypoint_user="tomcat",
logo_url="https://tomcat.apache.org/res/images/tomcat.png",
)
for tomcat_ver, os_version, jre_version in (
("10.1", OsVersion.TUMBLEWEED, 23),
("10.1", OsVersion.TUMBLEWEED, 21),
("10.1", OsVersion.TUMBLEWEED, 17),
("9", OsVersion.TUMBLEWEED, 21),
("9", OsVersion.TUMBLEWEED, 17),
("10.1", OsVersion.SP6, 21),
("10.1", OsVersion.SP6, 17),
("10.1", OsVersion.SP6, 11),
("9", OsVersion.SP6, 21),
("9", OsVersion.SP6, 17),
("9", OsVersion.SP6, 11),
("9", OsVersion.SP6, 8),
# (10.1, OsVersion.SP7, 21),
)
]
TOMCAT_FAMILIES = ContainerFamily(TOMCAT_CONTAINERS)