This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerfile.j2
More file actions
102 lines (83 loc) · 4.12 KB
/
Containerfile.j2
File metadata and controls
102 lines (83 loc) · 4.12 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
ARG BOOKLORE_VERSION=latest
ARG BASE_VERSION=15
# --- Stage 1: Upstream Linux (Source) ---
FROM --platform=linux/amd64 ghcr.io/booklore-app/booklore:${BOOKLORE_VERSION} AS upstream
# --- Stage 2: FreeBSD Builder (Patching) ---
FROM ghcr.io/daemonless/base:${BASE_VERSION} AS builder
ARG UPSTREAM_URL="https://api.github.com/repos/booklore-app/booklore/releases/latest"
COPY --from=upstream /app/app.jar /app/app.jar
COPY root/patches /patches
RUN pkg update && pkg install -y openjdk25-headless && \
VERSION=$(fetch -qo - "${UPSTREAM_URL}" | sed -n 's/.*"tag_name"[^"]*"\([^"]*\)".*/\1/p' | tr -d 'v') && \
cd /tmp && mkdir build && cd build && \
jar -xf /app/app.jar BOOT-INF/ && \
KEPUB_PKG="org/booklore/service/kobo" && \
fetch -qo KepubConversionService.java \
"https://raw.githubusercontent.com/booklore-app/booklore/v${VERSION}/booklore-api/src/main/java/${KEPUB_PKG}/KepubConversionService.java" && \
patch -p1 KepubConversionService.java /patches/freebsd-kepubify.patch && \
sed -i '' -e '/import lombok/d' -e 's/@Slf4j/@SuppressWarnings("unused")/' KepubConversionService.java && \
sed -i '' 's/public class KepubConversionService {/public class KepubConversionService { private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(KepubConversionService.class);/' KepubConversionService.java && \
CP="BOOT-INF/classes:$(find BOOT-INF/lib -name '*.jar' | tr '\n' ':')" && \
javac -proc:none -cp "$CP" -d BOOT-INF/classes KepubConversionService.java && \
jar -uf /app/app.jar -C /tmp/build \
BOOT-INF/classes/${KEPUB_PKG}/KepubConversionService.class
# --- Stage 3: Final FreeBSD Image ---
FROM ghcr.io/daemonless/base:${BASE_VERSION}
ARG FREEBSD_ARCH=amd64
ARG PACKAGES="openjdk25-jre-headless kepubify"
ARG UPSTREAM_URL="https://api.github.com/repos/booklore-app/booklore/releases/latest"
ARG UPSTREAM_JQ=".tag_name"
ARG HEALTHCHECK_ENDPOINT="http://localhost:6060/api/v1/healthcheck"
ENV HEALTHCHECK_URL="${HEALTHCHECK_ENDPOINT}"
# --- Metadata (Injected by Generator) ---
LABEL org.opencontainers.image.title="{{ title }}" \
org.opencontainers.image.description="{{ description }}" \
org.opencontainers.image.source="{{ repo_url }}" \
org.opencontainers.image.url="{{ web_url }}" \
org.opencontainers.image.documentation="https://booklore-app.github.io/booklore-docs/" \
org.opencontainers.image.licenses="AGPL-3.0" \
org.opencontainers.image.vendor="daemonless" \
org.opencontainers.image.authors="daemonless" \
io.daemonless.category="{{ category }}" \
{%- if ports %}
io.daemonless.port="{{ ports[0].port }}" \
{%- endif %}
{%- if volumes %}
io.daemonless.volumes="{{ volumes | map(attribute='path') | join(',') }}" \
{%- endif %}
io.daemonless.arch="${FREEBSD_ARCH}" \
io.daemonless.upstream-url="${UPSTREAM_URL}" \
io.daemonless.upstream-jq="${UPSTREAM_JQ}" \
io.daemonless.healthcheck-url="${HEALTHCHECK_ENDPOINT}"
# Install minimal runtime
RUN pkg update && \
pkg install -y ${PACKAGES} && \
pkg clean -ay && \
rm -rf /var/cache/pkg/* /var/db/pkg/repos/*
# Copy patched JAR from builder
COPY --from=builder /app/app.jar /app/app.jar
# Write version from upstream
RUN VERSION=$(fetch -qo - "${UPSTREAM_URL}" | sed -n 's/.*"tag_name"[^"]*"\([^"]*\)".*/\1/p' | tr -d 'v') && \
echo "$VERSION" > /app/version
# Copy service definitions and configs
COPY root/ /
# Remove build-time artifacts and obsolete services
RUN rm -rf /patches /etc/services.d/nginx /defaults
# Create directories
RUN mkdir -p /app/data /books /bookdrop /app/logs && \
chown -R bsd:bsd /app/data /books /bookdrop /app
# Make scripts executable
RUN chmod +x /etc/services.d/*/run /etc/cont-init.d/* /healthz 2>/dev/null || true
ENV BOOKLORE_PORT=6060 \
SPRING_DATASOURCE_URL="" \
SPRING_DATASOURCE_USERNAME="" \
SPRING_DATASOURCE_PASSWORD="" \
JAVA_OPTS=""
# --- Expose (Injected by Generator) ---
{%- if ports %}
EXPOSE {{ ports | map(attribute='port') | join(' ') }}
{%- endif %}
# --- Volumes (Injected by Generator) ---
{%- if volumes %}
VOLUME {{ volumes | map(attribute='path') | join(' ') }}
{%- endif %}