Skip to content

Commit

Permalink
feat: Complete refactor of verlihub image (#321)
Browse files Browse the repository at this point in the history
* feat: Complete refactor of `verlihub` image

* fix: Remove `--init` from test CI
  • Loading branch information
MattKobayashi authored Oct 14, 2024
1 parent ff88b32 commit 59340c4
Show file tree
Hide file tree
Showing 21 changed files with 438 additions and 211 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-verlihub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
run: |
set -x
timeout --kill-after=30s --preserve-status 30s \
docker container run --attach stdout --attach stderr --init --rm ${{ needs.build-setup.outputs.repo-owner }}/${{ matrix.container }}:test
docker container run --attach stdout --attach stderr --rm ${{ needs.build-setup.outputs.repo-owner }}/${{ matrix.container }}:test
# Remove the test image
- name: Remove test image
if: ${{ !cancelled() }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/
1 change: 1 addition & 0 deletions verlihub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/secrets
180 changes: 95 additions & 85 deletions verlihub/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,93 +1,103 @@
FROM alpine:3.20.3 AS build
FROM debian:12.7-slim AS build

# Install dependencies and compile
RUN apt-get update \
&& apt-get --yes install \
git \
build-essential \
cmake \
libpcre3-dev \
libssl-dev \
libmaxminddb-dev \
libicu-dev \
gettext \
libasprintf-dev \
mariadb-server \
libmariadb-dev \
mariadb-client \
libmariadb-dev-compat \
&& git clone https://github.com/Verlihub/verlihub.git \
&& cd verlihub/ \
&& git checkout 1.5.0.0 \
&& mkdir -p build \
&& cd build/ \
&& cmake -DWITH_PLUGINS=OFF .. \
&& make

FROM debian:12.7-slim
WORKDIR /opt/verlihub/

# Install s6-overlay installation dependencies
RUN apt-get update \
&& apt-get --yes install \
xz-utils

# Add s6-overlay
WORKDIR /tmp
ENV S6_OVERLAY_VERSION=3.2.0.2
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz.sha256 /tmp
RUN echo "$(cat s6-overlay-noarch.tar.xz.sha256)" | sha256sum -c - \
&& tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz /tmp
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz.sha256 /tmp
RUN echo "$(cat s6-overlay-x86_64.tar.xz.sha256)" | sha256sum -c - \
&& tar -C / -Jxpf /tmp/s6-overlay-x86_64.tar.xz
COPY s6-rc.d/ /etc/s6-overlay/s6-rc.d/

ENV SOURCE_FILE=verlihub.tar.gz \
SOURCE_URL=https://github.com/Verlihub/verlihub/archive/baa5f6ca57742f08bab1ab577e0d58119f7e07f7.tar.gz \
SOURCE_SHA1SUM=13cd61773642af497c941804f091200fcce0db88

# Download source file, extract and compile
WORKDIR /verlihub/
RUN apk --no-cache add bash build-base cmake gettext gettext-dev icu-dev libmaxminddb-dev mariadb-dev openssl-dev pcre-dev \
&& apk --no-cache add libexecinfo-dev --repository=https://dl-cdn.alpinelinux.org/alpine/v3.16/main/ \
&& wget -O "$SOURCE_FILE" "$SOURCE_URL" \
&& echo "${SOURCE_SHA1SUM} ${SOURCE_FILE}" | sha1sum -c - \
&& tar -xz --strip-components=1 --file="$SOURCE_FILE" \
&& mkdir build \
&& cd build \
&& cmake .. \
&& make \
# Install runtime dependencies
RUN apt-get --yes install \
libpcre3-dev \
libssl3 \
libmaxminddb-dev \
libicu-dev \
libasprintf-dev \
mariadb-client \
libmariadb-dev \
libmariadb-dev-compat

# Copy files from build image
COPY --from=build /verlihub/ /verlihub/

# Run make install
RUN apt-get --yes install build-essential cmake \
&& cd /verlihub/build/ \
&& make install \
&& rm -R /verlihub/*

# Copy compiled files to final image
FROM alpine:3.20.3
&& mkdir -p /opt/verlihub/sql/ \
&& cp /verlihub/share/sql/default_reglist.sql /opt/verlihub/sql/ \
&& rm -r /verlihub/

# Remove build dependencies
RUN apt-get --yes purge \
build-essential \
cmake \
libpcre3-dev \
libmaxminddb-dev \
libicu-dev \
libasprintf-dev \
libmariadb-dev \
libmariadb-dev-compat \
xz-utils \
&& apt-get --yes autoremove \
&& apt-get --yes clean

# Install runtime dependencies
RUN apk --no-cache add bash icu-data-full mariadb-connector-c mysql-client ncurses \
&& adduser -Su 1000 verlihub

# Copy /usr/bin/
COPY --from=build \
/usr/bin/msgmerge \
/usr/bin/

# Copy /usr/local/bin/
COPY --from=build \
/usr/local/bin/verlihub* \
/usr/local/bin/vh* \
/usr/local/bin/

# Copy /usr/local/include/
COPY --from=build \
/usr/local/include/verlihub/ \
/usr/local/include/verlihub/

# Copy /lib/
COPY --from=build \
/lib/ld-musl-x86_64.so* \
/lib/libssl.so* \
/lib/libz.so* \
/lib/

# Copy /usr/lib/
COPY --from=build \
/usr/lib/libasprintf.so* \
/usr/lib/libcrypto.so* \
/usr/lib/libexecinfo.so* \
/usr/lib/libgcc_s.so* \
/usr/lib/libicudata.so* \
/usr/lib/libicui18n.so* \
/usr/lib/libicuuc.so* \
/usr/lib/libintl.so* \
/usr/lib/libmaxminddb.so* \
/usr/lib/libpcre.so* \
/usr/lib/libstdc++.so* \
/usr/lib/

COPY --from=build \
/usr/local/lib/libplug_pi.so \
/usr/local/lib/libverlihub.so \
/usr/local/lib/libvhapi.so \
/usr/local/lib/

# Copy /usr/local/share/locale/
COPY --from=build \
/usr/local/share/locale/ \
/usr/local/share/locale/

# Copy share
COPY --from=build \
/usr/local/share/verlihub/ \
/usr/local/share/verlihub/

# Copy entrypoint.sh to image
WORKDIR /verlihub/
COPY entrypoint.sh .

# Change to non-root user
USER verlihub
RUN apt-get --yes install \
libpcre3 \
libmaxminddb0 \
libicu72 \
libasprintf0v5 \
libmariadb3 \
pip \
&& pip3 install --break-system-packages mysql-connector-python \
&& useradd --system --base-dir /opt verlihub \
&& mkdir -p /opt/verlihub/.config/verlihub/ \
&& chown -R verlihub:verlihub /opt/verlihub/

# Copy files to image
COPY --chmod=700 --chown=verlihub:verlihub scripts/setup.py /opt/verlihub/scripts/setup.py

# Set entrypoint
ENTRYPOINT ["/verlihub/entrypoint.sh"]
CMD ["--install"]
ENTRYPOINT ["/init"]

LABEL org.opencontainers.image.authors="MattKobayashi <matthew@kobayashi.au>"
93 changes: 93 additions & 0 deletions verlihub/Dockerfile-alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
FROM alpine:3.20.3 AS build

ENV SOURCE_FILE=verlihub.tar.gz \
SOURCE_URL=https://github.com/Verlihub/verlihub/archive/baa5f6ca57742f08bab1ab577e0d58119f7e07f7.tar.gz \
SOURCE_SHA1SUM=13cd61773642af497c941804f091200fcce0db88

# Download source file, extract and compile
WORKDIR /verlihub/
RUN apk --no-cache add bash build-base cmake gettext gettext-dev icu-dev libmaxminddb-dev mariadb-dev openssl-dev pcre-dev \
&& apk --no-cache add libexecinfo-dev --repository=https://dl-cdn.alpinelinux.org/alpine/v3.16/main/ \
&& wget -O "$SOURCE_FILE" "$SOURCE_URL" \
&& echo "${SOURCE_SHA1SUM} ${SOURCE_FILE}" | sha1sum -c - \
&& tar -xz --strip-components=1 --file="$SOURCE_FILE" \
&& mkdir build \
&& cd build \
&& cmake .. \
&& make \
&& make install \
&& rm -R /verlihub/*

# Copy compiled files to final image
FROM alpine:3.20.3

# Install runtime dependencies
RUN apk --no-cache add bash icu-data-full mariadb-connector-c mysql-client ncurses \
&& adduser -Su 1000 verlihub

# Copy /usr/bin/
COPY --from=build \
/usr/bin/msgmerge \
/usr/bin/

# Copy /usr/local/bin/
COPY --from=build \
/usr/local/bin/verlihub* \
/usr/local/bin/vh* \
/usr/local/bin/

# Copy /usr/local/include/
COPY --from=build \
/usr/local/include/verlihub/ \
/usr/local/include/verlihub/

# Copy /lib/
COPY --from=build \
/lib/ld-musl-x86_64.so* \
/lib/libssl.so* \
/lib/libz.so* \
/lib/

# Copy /usr/lib/
COPY --from=build \
/usr/lib/libasprintf.so* \
/usr/lib/libcrypto.so* \
/usr/lib/libexecinfo.so* \
/usr/lib/libgcc_s.so* \
/usr/lib/libicudata.so* \
/usr/lib/libicui18n.so* \
/usr/lib/libicuuc.so* \
/usr/lib/libintl.so* \
/usr/lib/libmaxminddb.so* \
/usr/lib/libpcre.so* \
/usr/lib/libstdc++.so* \
/usr/lib/

COPY --from=build \
/usr/local/lib/libplug_pi.so \
/usr/local/lib/libverlihub.so \
/usr/local/lib/libvhapi.so \
/usr/local/lib/

# Copy /usr/local/share/locale/
COPY --from=build \
/usr/local/share/locale/ \
/usr/local/share/locale/

# Copy share
COPY --from=build \
/usr/local/share/verlihub/ \
/usr/local/share/verlihub/

# Copy entrypoint.sh to image
WORKDIR /verlihub/
COPY entrypoint.sh .

# Change to non-root user
USER verlihub

# Set entrypoint
ENTRYPOINT ["/verlihub/entrypoint.sh"]
CMD ["--install"]

LABEL org.opencontainers.image.authors="MattKobayashi <matthew@kobayashi.au>"
82 changes: 0 additions & 82 deletions verlihub/Dockerfile-debian

This file was deleted.

Loading

0 comments on commit 59340c4

Please sign in to comment.