Adaptations for the new baseimage version 4.

This commit is contained in:
Jocelyn Le Sage 2022-10-07 09:37:43 -04:00
parent 1b36ec0101
commit 32b23d080a
14 changed files with 52 additions and 149 deletions

View File

@ -13,20 +13,18 @@ RUN gcc -static -o membarrier_check membarrier_check.c
RUN strip membarrier_check RUN strip membarrier_check
# Pull base image. # Pull base image.
FROM jlesage/baseimage-gui:alpine-3.15-v3.5.8 FROM jlesage/baseimage-gui:alpine-3.16-v4.0.1
# Docker image version is provided via build arg. # Docker image version is provided via build arg.
ARG DOCKER_IMAGE_VERSION=unknown ARG DOCKER_IMAGE_VERSION=
# Define software versions. # Define software versions.
ARG FIREFOX_VERSION=94.0-r0 ARG FIREFOX_VERSION=101.0.1-r0
ARG YAD_VERSION=7.3
ARG JSONLZ4_VERSION=c4305b8 ARG JSONLZ4_VERSION=c4305b8
ARG LZ4_VERSION=1.8.1.2 ARG LZ4_VERSION=1.8.1.2
#ARG PROFILE_CLEANER_VERSION=2.36 #ARG PROFILE_CLEANER_VERSION=2.36
# Define software download URLs. # Define software download URLs.
ARG YAD_URL=https://github.com/v1cont/yad/releases/download/v${YAD_VERSION}/yad-${YAD_VERSION}.tar.xz
ARG JSONLZ4_URL=https://github.com/avih/dejsonlz4/archive/${JSONLZ4_VERSION}.tar.gz ARG JSONLZ4_URL=https://github.com/avih/dejsonlz4/archive/${JSONLZ4_VERSION}.tar.gz
ARG LZ4_URL=https://github.com/lz4/lz4/archive/v${LZ4_VERSION}.tar.gz ARG LZ4_URL=https://github.com/lz4/lz4/archive/v${LZ4_VERSION}.tar.gz
#ARG PROFILE_CLEANER_URL=https://github.com/graysky2/profile-cleaner/raw/v${PROFILE_CLEANER_VERSION}/common/profile-cleaner.in #ARG PROFILE_CLEANER_URL=https://github.com/graysky2/profile-cleaner/raw/v${PROFILE_CLEANER_VERSION}/common/profile-cleaner.in
@ -64,49 +62,13 @@ RUN \
# --upgrade firefox=${FIREFOX_VERSION} # --upgrade firefox=${FIREFOX_VERSION}
add-pkg firefox=${FIREFOX_VERSION} add-pkg firefox=${FIREFOX_VERSION}
# Install YAD.
# NOTE: YAD is compiled manually because the version on the Alpine repository
# pulls too much dependencies.
RUN \
# Install packages needed by the build.
add-pkg --virtual build-dependencies \
build-base \
curl \
intltool \
gtk+3.0-dev \
&& \
# Set same default compilation flags as abuild.
export CFLAGS="-Os -fomit-frame-pointer" && \
export CXXFLAGS="$CFLAGS" && \
export CPPFLAGS="$CFLAGS" && \
export LDFLAGS="-Wl,--as-needed" && \
# Download.
mkdir yad && \
echo "Downloading YAD package..." && \
curl -# -L ${YAD_URL} | tar xJ --strip 1 -C yad && \
# Compile.
cd yad && \
./configure \
--prefix=/usr \
--enable-standalone \
--disable-icon-browser \
--disable-html \
--disable-pfd \
&& \
make && make install && \
strip /usr/bin/yad && \
cd .. && \
# Cleanup.
del-pkg build-dependencies && \
rm -rf /tmp/* /tmp/.[!.]*
# Install extra packages. # Install extra packages.
RUN \ RUN \
add-pkg \ add-pkg \
desktop-file-utils \ # Icons used by folder/file selection window (when saving as).
adwaita-icon-theme \ gnome-icon-theme \
# A font is needed.
ttf-dejavu \ ttf-dejavu \
ffmpeg-libs \
# The following package is used to send key presses to the X process. # The following package is used to send key presses to the X process.
xdotool xdotool
@ -141,15 +103,6 @@ RUN \
sed-patch 's|LOG_FILES=|LOG_FILES=/config/log/firefox/error.log|' /etc/logmonitor/logmonitor.conf && \ sed-patch 's|LOG_FILES=|LOG_FILES=/config/log/firefox/error.log|' /etc/logmonitor/logmonitor.conf && \
sed-patch 's|STATUS_FILES=|STATUS_FILES=/tmp/.firefox_shm_check,/tmp/.firefox_membarrier_check|' /etc/logmonitor/logmonitor.conf sed-patch 's|STATUS_FILES=|STATUS_FILES=/tmp/.firefox_shm_check,/tmp/.firefox_membarrier_check|' /etc/logmonitor/logmonitor.conf
# Adjust the openbox config.
RUN \
# Maximize only the main window.
sed-patch 's/<application type="normal">/<application type="normal" title="Mozilla Firefox">/' \
/etc/xdg/openbox/rc.xml && \
# Make sure the main window is always in the background.
sed-patch '/<application type="normal" title="Mozilla Firefox">/a \ <layer>below</layer>' \
/etc/xdg/openbox/rc.xml
# Generate and install favicons. # Generate and install favicons.
RUN \ RUN \
APP_ICON_URL=https://github.com/jlesage/docker-templates/raw/master/jlesage/images/firefox-icon.png && \ APP_ICON_URL=https://github.com/jlesage/docker-templates/raw/master/jlesage/images/firefox-icon.png && \
@ -159,8 +112,12 @@ RUN \
COPY rootfs/ / COPY rootfs/ /
COPY --from=membarrier /tmp/membarrier_check /usr/bin/ COPY --from=membarrier /tmp/membarrier_check /usr/bin/
# Set environment variables. # Set internal environment variables.
ENV APP_NAME="Firefox" RUN \
set-cont-env APP_NAME "Firefox" && \
set-cont-env APP_VERSION "$FIREFOX_VERSION" && \
set-cont-env DOCKER_IMAGE_VERSION "$DOCKER_IMAGE_VERSION" && \
true
# Define mountable directories. # Define mountable directories.
VOLUME ["/config"] VOLUME ["/config"]
@ -169,6 +126,6 @@ VOLUME ["/config"]
LABEL \ LABEL \
org.label-schema.name="firefox" \ org.label-schema.name="firefox" \
org.label-schema.description="Docker container for Firefox" \ org.label-schema.description="Docker container for Firefox" \
org.label-schema.version="$DOCKER_IMAGE_VERSION" \ org.label-schema.version="${DOCKER_IMAGE_VERSION:-unknown}" \
org.label-schema.vcs-url="https://github.com/jlesage/docker-firefox" \ org.label-schema.vcs-url="https://github.com/jlesage/docker-firefox" \
org.label-schema.schema-version="1.0" org.label-schema.schema-version="1.0"

View File

@ -1,22 +1,18 @@
#!/usr/bin/with-contenv sh #!/bin/sh
set -e # Exit immediately if a command exits with a non-zero status. set -e # Exit immediately if a command exits with a non-zero status.
set -u # Treat unset variables as an error. set -u # Treat unset variables as an error.
log() {
echo "[cont-init.d] $(basename $0): $*"
}
SND_DEV="/dev/snd" SND_DEV="/dev/snd"
if [ ! -d "$SND_DEV" ]; then if [ ! -d "$SND_DEV" ]; then
log "sound not supported: device $SND_DEV not exposed to the container." echo "sound not supported: device $SND_DEV not exposed to the container."
exit 0 exit 0
fi fi
# Save the associated group. # Save the associated group.
SND_GRP="$(find "$SND_DEV" -maxdepth 1 -not -type d -exec stat -c "%g" {} \; | sort -u | tail -n1)" SND_GRP="$(find "$SND_DEV" -maxdepth 1 -not -type d -exec stat -c "%g" {} \; | sort -u | tail -n1)"
log "sound device group $SND_GRP." echo "sound device group $SND_GRP."
if [ -f /var/run/s6/container_environment/SUP_GROUP_IDS ]; then if [ -f /var/run/s6/container_environment/SUP_GROUP_IDS ]; then
echo -n "," >> /var/run/s6/container_environment/SUP_GROUP_IDS echo -n "," >> /var/run/s6/container_environment/SUP_GROUP_IDS
fi fi

View File

@ -1,15 +1,11 @@
#!/usr/bin/with-contenv sh #!/bin/sh
set -e set -e
log() {
echo "[cont-init.d] $(basename $0): $*"
}
PREF_FILE="${1:-/config/profile/prefs.js}" PREF_FILE="${1:-/config/profile/prefs.js}"
if [ -z "$PREF_FILE" ]; then if [ -z "$PREF_FILE" ]; then
log "ERROR: Preference file not set." echo "ERROR: Preference file not set."
exit 1 exit 1
fi fi
@ -22,7 +18,7 @@ do
EVAL="$(echo "$ENV" | cut -d '=' -f2-)" EVAL="$(echo "$ENV" | cut -d '=' -f2-)"
if [ -z "$EVAL" ]; then if [ -z "$EVAL" ]; then
log "Skipping environment variable '$ENAME': no value set." echo "Skipping environment variable '$ENAME': no value set."
continue continue
fi fi
@ -36,13 +32,13 @@ do
fi fi
if [ "$PVAL" = "UNSET" ]; then if [ "$PVAL" = "UNSET" ]; then
log "Removing preference '$PNAME'..." echo "Removing preference '$PNAME'..."
sed -i "/user_pref(\"$PNAME\",.*);/d" "$PREF_FILE" sed -i "/user_pref(\"$PNAME\",.*);/d" "$PREF_FILE"
elif grep -q "user_pref(\"$PNAME\"," "$PREF_FILE"; then elif grep -q "user_pref(\"$PNAME\"," "$PREF_FILE"; then
log "Setting preference '$PNAME'..." echo "Setting preference '$PNAME'..."
sed -i "s/user_pref(\"$PNAME\",.*);/user_pref(\"$PNAME\", $PVAL);/" "$PREF_FILE" sed -i "s/user_pref(\"$PNAME\",.*);/user_pref(\"$PNAME\", $PVAL);/" "$PREF_FILE"
else else
log "Setting new preference '$PNAME'..." echo "Setting new preference '$PNAME'..."
echo "user_pref(\"$PNAME\", $PVAL);" >> "$PREF_FILE" echo "user_pref(\"$PNAME\", $PVAL);" >> "$PREF_FILE"
fi fi
done done

View File

@ -1,19 +1,15 @@
#!/usr/bin/with-contenv sh #!/bin/sh
set -e # Exit immediately if a command exits with a non-zero status. set -e # Exit immediately if a command exits with a non-zero status.
set -u # Treat unset variables as an error. set -u # Treat unset variables as an error.
log() {
echo "[cont-init.d] $(basename $0): $*"
}
# Make sure some directories are created. # Make sure some directories are created.
mkdir -p /config/downloads mkdir -p /config/downloads
mkdir -p /config/log/firefox mkdir -p /config/log/firefox
# Generate machine id. # Generate machine id.
if [ ! -f /etc/machine-id ]; then if [ ! -f /etc/machine-id ]; then
log "generating machine-id..." echo "generating machine-id..."
cat /proc/sys/kernel/random/uuid | tr -d '-' > /etc/machine-id cat /proc/sys/kernel/random/uuid | tr -d '-' > /etc/machine-id
fi fi
@ -24,12 +20,14 @@ if [ "$SHM_SIZE_MB" -eq 64 ]; then
else else
echo 'SHM_CHECK_PASS' > /tmp/.firefox_shm_check echo 'SHM_CHECK_PASS' > /tmp/.firefox_shm_check
fi fi
chown $USER_ID:$GROUP_ID /tmp/.firefox_shm_check
if /usr/bin/membarrier_check 2>/dev/null; then if /usr/bin/membarrier_check 2>/dev/null; then
echo 'MEMBARRIER_CHECK_PASS' > /tmp/.firefox_membarrier_check echo 'MEMBARRIER_CHECK_PASS' > /tmp/.firefox_membarrier_check
else else
echo 'MEMBARRIER_CHECK_FAIL' > /tmp/.firefox_membarrier_check echo 'MEMBARRIER_CHECK_FAIL' > /tmp/.firefox_membarrier_check
fi fi
chown $USER_ID:$GROUP_ID /tmp/.firefox_membarrier_check
# Clean/optimize Firefox databases. # Clean/optimize Firefox databases.
#if [ -d /config/.mozilla/firefox ] && [ -d /config/profile ]; then #if [ -d /config/.mozilla/firefox ] && [ -d /config/profile ]; then
@ -53,7 +51,7 @@ if [ -n "$(ls /config/profile/sessionstore-backups/*.jsonlz4 2>/dev/null)" ]; th
if ! diff "$WORKDIR"/json "$WORKDIR"/json.orig >/dev/null; then if ! diff "$WORKDIR"/json "$WORKDIR"/json.orig >/dev/null; then
jsonlz4 "$WORKDIR"/json "$WORKDIR"/jsonlz4 jsonlz4 "$WORKDIR"/json "$WORKDIR"/jsonlz4
mv "$WORKDIR"/jsonlz4 "$FILE" mv "$WORKDIR"/jsonlz4 "$FILE"
log "fixed display size in $FILE." echo "fixed display size in $FILE."
fi fi
rm -r "$WORKDIR" rm -r "$WORKDIR"

View File

@ -0,0 +1,2 @@
<Type>normal</Type>
<Name>^Navigator</Name>

View File

@ -1,2 +1,2 @@
#!/usr/bin/with-contenv sh #!/bin/sh
echo "$APP_NAME is likely to crash because it requires the membarrier system call. See the documentation of this Docker container to find out how this system call can be allowed." echo "$APP_NAME is likely to crash because it requires the membarrier system call. See the documentation of this Docker container to find out how this system call can be allowed."

View File

@ -1,2 +1,2 @@
#!/usr/bin/with-contenv sh #!/bin/sh
echo "$APP_NAME requires the membarrier system call." echo "$APP_NAME requires the membarrier system call."

View File

@ -1,2 +1,2 @@
#!/usr/bin/with-contenv sh #!/bin/sh
echo "$APP_NAME is likely to crash because of the lack of shared memory. Size of shared memory needs to be increased. See the documentation of the Docker container to find out how this can be done." echo "$APP_NAME is likely to crash because of the lack of shared memory. Size of shared memory needs to be increased. See the documentation of the Docker container to find out how this can be done."

View File

@ -1,2 +1,2 @@
#!/usr/bin/with-contenv sh #!/bin/sh
echo "$APP_NAME lacks of shared memory." echo "$APP_NAME lacks of shared memory."

View File

@ -1,2 +1,2 @@
#!/usr/bin/with-contenv sh #!/bin/sh
echo "A $APP_NAME tab crashed because of the lack of shared memory. Size of shared memory needs to be increased. See the documentation of this Docker container to find out how this can be done." echo "A $APP_NAME tab crashed because of the lack of shared memory. Size of shared memory needs to be increased. See the documentation of this Docker container to find out how this can be done."

View File

@ -1,2 +1,2 @@
#!/usr/bin/with-contenv sh #!/bin/sh
echo "$APP_NAME lacks of shared memory." echo "$APP_NAME lacks of shared memory."

14
rootfs/etc/services.d/app/kill Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
#
# When receiving SIGTERM, Firefox doesn't qui immediately and instead ask for
# confirmation. Instead, terminate Firefox by sending the CTRL+q key presses.
#
set -e # Exit immediately if a command exits with a non-zero status.
set -u # Treat unset variables as an error.
xdotool key "Escape"
xdotool key "ctrl+q"
# vim:ft=sh:ts=4:sw=4:et:sts=4

View File

@ -1,9 +1,9 @@
#!/usr/bin/with-contenv sh #!/bin/sh
set -e # Exit immediately if a command exits with a non-zero status. set -e # Exit immediately if a command exits with a non-zero status.
set -u # Treat unset variables as an error. set -u # Treat unset variables as an error.
export HOME=/config export HOME=/config
mkdir -p /config/profile mkdir -p /config/profile
firefox --version /usr/bin/firefox --version
exec /usr/bin/firefox_wrapper --profile /config/profile --setDefaultBrowser >> /config/log/firefox/output.log 2>> /config/log/firefox/error.log exec /usr/bin/firefox --profile /config/profile --setDefaultBrowser >> /config/log/firefox/output.log 2>> /config/log/firefox/error.log

View File

@ -1,60 +0,0 @@
#!/bin/sh
#
# This small wrapper is used to gracefully terminate Firefox. It prevents
# the application to receive termination signals directly. Instead, the wrapper
# traps signals and send CTRL+q key presses to Firefox.
#
FF_PID=0
# Gracefully terminate Firefox. This function is called when this script
# receives a termination signal (SIGKILL, SIGINT or SIGQUIT).
kill_firefox() {
# Gracefully close Firefox.
echo "Terminating Firefox..."
xdotool key "Escape"
xdotool key "ctrl+q"
# And wait for its termination.
if [ "$FF_PID" -ne 0 ]; then
wait $FF_PID
exit $?
fi
}
trap 'kill_firefox' TERM INT QUIT
# This function is called when this script exits. It makes sure that Firefox is
# fully closed by waiting for all its processes to terminate.
exit_wrapper() {
echo "Waiting for Firefox to completely terminate..."
TIMEOUT=10
while firefox_running && [ "$TIMEOUT" -gt 0 ]; do
TIMEOUT="$(expr "$TIMEOUT" - 1)"
sleep 1
done
if [ "$TIMEOUT" -gt 0 ]; then
echo "Firefox terminated."
else
echo "WARNING: Firefox still not terminated."
fi
}
trap 'exit_wrapper' EXIT
firefox_running() {
ps | grep -v grep | grep -q '/usr/lib/firefox'
}
# Make sure to terminate any existing instance.
if firefox_running; then
kill_firefox
fi
# Start Firefox in background.
/usr/bin/firefox "$@" &
# And wait for its termination.
FF_PID=$!
wait $FF_PID
exit $?