Skip to content

Commit

Permalink
feat: Allow for container to be run in non-interactive (remote) mode (#…
Browse files Browse the repository at this point in the history
…47)

* feat: Allow for container to be run in non-interactive (remote) mode 
* feat: Upgrade unoserver to 2.0.1 (unoserver version is now set explicitly)
* feat: Change to official Eclipse Temurin alpine image
* feat: Upgrade to Java 21
* feat: Upgrade to alpine 3.19.1
  • Loading branch information
jimisola authored Feb 11, 2024
1 parent 1f522ad commit 08e0828
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 125 deletions.
23 changes: 10 additions & 13 deletions .github/workflows/docker-publish..yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ name: Publish Docker Image to GHCR
# documentation.

on:
workflow_dispatch:
release:
types:
- created
push:
branches:
- main
# Publish semver tags as releases.
tags:
- "v*.*.*"
pull_request:
branches:
- main


env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
Expand All @@ -40,10 +37,10 @@ jobs:
- name: Setup Docker buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226

# Login against a Docker registry except on PR
# Login against a Docker registry only when tag "vM.M.P"
# https://github.com/docker/login-action
- name: Login to image registry ${{ env.REGISTRY }}
if: github.ref_type == 'tag'
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ${{ env.REGISTRY }}
Expand Down Expand Up @@ -72,7 +69,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.ref_type == 'tag' }}
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
Expand All @@ -81,7 +78,7 @@ jobs:
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.ref_type == 'tag'
if: startsWith(github.ref, 'refs/tags/v')
uses: sigstore/cosign-installer@main
with:
cosign-release: 'v1.13.1'
Expand All @@ -92,7 +89,7 @@ jobs:
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: github.ref_type == 'tag'
if: startsWith(github.ref, 'refs/tags/v')
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
Expand Down
24 changes: 8 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM alpine:3.18.5
FROM eclipse-temurin:21.0.2_13-jdk-alpine

ARG BUILD_CONTEXT="build-context"
ARG UID=worker
ARG GID=worker
ARG VERSION_UNOSERVER=2.0.1

LABEL org.opencontainers.image.title="unoserver-docker"
LABEL org.opencontainers.image.description="Custom Docker Image that contains unoserver, LibreOffice and major set of fonts for file format conversions"
Expand Down Expand Up @@ -36,23 +37,14 @@ RUN apk add --no-cache \
fontconfig && \
fc-cache -f

RUN rm $(which wget) && \
rm -rf /var/cache/apk/* /tmp/*

# renovate: datasource=repology depName=temurin-17-jdk versioning=loose
ARG VERSION_ADOPTIUM_TEMURIN="17.0.7_p7-r0"

# install Eclipse Temurin JDK
RUN curl https://packages.adoptium.net/artifactory/api/security/keypair/public/repositories/apk -o /etc/apk/keys/adoptium.rsa.pub && \
echo 'https://packages.adoptium.net/artifactory/apk/alpine/main' >> /etc/apk/repositories && \
apk update && apk add temurin-17-jdk=${VERSION_ADOPTIUM_TEMURIN}
RUN rm -rf /var/cache/apk/* /tmp/*

# https://github.com/unoconv/unoserver/
RUN pip install -U unoserver
RUN pip install --break-system-packages -U unoserver==${VERSION_UNOSERVER}

# setup supervisor
COPY --chown=${UID}:${GID} ${BUILD_CONTEXT}/supervisor /
RUN chmod +x /config/entrypoint.sh && \
COPY --chown=${UID}:${GID} ${BUILD_CONTEXT} /
RUN chmod +x entrypoint.sh && \
# mkdir -p /var/log/supervisor && \
# chown ${UID}:${GID} /var/log/supervisor && \
# mkdir -p /var/run && \
Expand All @@ -64,5 +56,5 @@ WORKDIR /home/worker
ENV HOME="/home/worker"

VOLUME ["/data"]

ENTRYPOINT ["/config/entrypoint.sh"]
EXPOSE 2003
ENTRYPOINT ["/entrypoint.sh"]
85 changes: 85 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
= Unoserver Docker Image

Docker image for unoserver

== The environment

This Docker image uses Alpine Linux as a base image and provides:

* link:https://www.libreoffice.org/[LibreOffice]
* link:https://github.com/unoconv/unoserver[unoserver]

* Fonts (Alpine packages)
- font-noto
- font-noto-cjk
- font-noto-extra
- terminus-font
- ttf-font-awesome
- ttf-dejavu
- ttf-freefont
- ttf-hack
- ttf-inconsolata
- ttf-liberation
- ttf-mononoki
- ttf-opensans

== How to use it

=== In interactive mode

Just run:

[source,bash]
----
docker run -it -v <your directory>:/data/ ghcr.io/unoconv/unoserver-docker
----

After you start the container, you can use link:https://github.com/unoconv/unoserver#unoconvert[unoconvert] command to convert documents using LibreOffice.

or to convert directly using unoconvert:

[source,bash]
----
docker run -it -v <your directory>:/data/ ghcr.io/unoconv/unoserver-docker unoconvert /data/document.docx /data/document.pdf
----

Docker maps your directory with /data directory in the container.

You might need to add the option `:z` or `:Z` like `<your directory>:/data/:z` or `<your directory>:/data/:Z` if you are using SELinux. See link:https://docs.docker.com/storage/bind-mounts/#configure-the-selinux-label[Docker docs] or link:https://docs.podman.io/en/latest/markdown/podman-run.1.html#volume-v-source-volume-host-dir-container-dir-options[Podman docs].


=== In non-interactive (remote) mode

[source,bash]
----
docker run -p 2003:2003 ghcr.io/unoconv/unoserver-docker unoconvert /data/document.docx /data/document.pdf
----

After you start the container, you can use link:https://github.com/unoconv/unoserver#unoconvert[unoconvert] command to convert documents using LibreOffice.

NOTE: You must use `--host-location` otherwise unoconvert will default to local although running unoserver in a container should be handled as remote.

[source,bash]
----
unoconvert --host-location remote example.docx x2.pdfdocker
----
== FAQ

Q. Why do I get an error during when converting is writing/exporting to file?

A. It's very likely that you haven't given the container write permission to the mounted data directory. See: link:https://github.com/unoconv/unoserver-docker/issues/44[Issue #44]

== How to contribute / do it yourself?

=== Requirements

You need the following tools:

* A bash compliant command line
* Docker installed and in your path

=== How to build

----
docker build .
----
61 changes: 0 additions & 61 deletions README.md

This file was deleted.

45 changes: 45 additions & 0 deletions build-context/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
set -e -u

# Function to wait for unoserver to start
wait_for_unoserver() {
echo "Waiting for unoserver to start on port 2003..."
while ! netstat -tln | grep -q 2003; do
sleep 1
done
echo "unoserver started."
}

export PS1='\u@\h:\w\$ '

echo "using: $(libreoffice --version)"

# if tty then assume that container is interactive
if [ ! -t 0 ]; then
echo "Running unoserver-docker in non-interactive."
echo "For interactive mode use '-it', e.g. 'docker run -v /tmp:/data -it unoserver/unoserver-docker'."

unoserver --interface 0.0.0.0
# # run supervisord in foreground
# supervisord -c "$SUPERVISOR_NON_INTERACTIVE_CONF"
else
echo "Running unoserver-docker in interactive mode."
echo "For non-interactive mode omit '-it', e.g. 'docker run -p 2003:2003 unoserver/unoserver-docker'."

# default parameters for supervisord
export SUPERVISOR_INTERACTIVE_CONF='/supervisor/conf/interactive/supervisord.conf'
export UNIX_HTTP_SERVER_PASSWORD=${UNIX_HTTP_SERVER_PASSWORD:-$(cat /proc/sys/kernel/random/uuid)}

# run supervisord as detached
supervisord -c "$SUPERVISOR_INTERACTIVE_CONF"

# wait until unoserver started and listens on port 2002.
wait_for_unoserver

# if commands have been passed to container run them and exit, else start bash
if [[ $# -gt 0 ]]; then
eval "$@"
else
/bin/bash
fi
fi
35 changes: 0 additions & 35 deletions build-context/supervisor/config/entrypoint.sh

This file was deleted.

0 comments on commit 08e0828

Please sign in to comment.