Skip to content

Commit

Permalink
Use shadowing script for docker (#17846)
Browse files Browse the repository at this point in the history
Too many docker users are caught out by the default location for the
app.ini file being environment dependent so that when they docker exec
into the container the gitea commands do not work properly and require
additional -c arguments to correctly pick up the configuration.

This PR simply shadows the gitea binary using variants of the FHS
compatible script to make the command gitea have the default locations
by default.

Fix #14468
Reference #17497
Reference #12082
Reference #8941
... amongst others ...
Replace #17501

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath authored Dec 1, 2021
1 parent 042cac5 commit 7d0629a
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ CMD ["/bin/s6-svscan", "/etc/s6"]
COPY docker/root /
COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
COPY --from=build-env /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
RUN chmod 755 /usr/bin/entrypoint /app/gitea/gitea /usr/local/bin/environment-to-ini
RUN chmod 755 /usr/bin/entrypoint /app/gitea/gitea /usr/local/bin/gitea /usr/local/bin/environment-to-ini
RUN chmod 755 /etc/s6/gitea/* /etc/s6/openssh/* /etc/s6/.s6-svscan/*
RUN ln -s /app/gitea/gitea /usr/local/bin/gitea
4 changes: 2 additions & 2 deletions Dockerfile.rootless
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ RUN mkdir -p /var/lib/gitea /etc/gitea
RUN chown git:git /var/lib/gitea /etc/gitea

COPY docker/rootless /
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/gitea /usr/local/bin/gitea
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh /usr/local/bin/docker-setup.sh /usr/local/bin/gitea /usr/local/bin/environment-to-ini
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh /usr/local/bin/docker-setup.sh /app/gitea/gitea /usr/local/bin/gitea /usr/local/bin/environment-to-ini

#git:git
USER 1000:1000
Expand Down
10 changes: 5 additions & 5 deletions contrib/fhs-compliant-script/gitea
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

########################################################################
# This script some defaults for gitea to run in a FHS compliant manner #
########################################################################
#############################################################################
# This script sets some defaults for gitea to run in a FHS compliant manner #
#############################################################################

# It assumes that you place this script as gitea in /usr/bin
#
Expand Down Expand Up @@ -36,7 +36,7 @@ if [ -z "$APP_INI_SET" ]; then
CONF_ARG="-c \"$APP_INI\""
fi

# Provide FHS compliant defaults to
exec -a "$0" GITEA_WORK_DIR="${GITEA_WORK_DIR:-$WORK_DIR}" "$GITEA" $CONF_ARG "$@"
# Provide FHS compliant defaults
GITEA_WORK_DIR="${GITEA_WORK_DIR:-$WORK_DIR}" exec -a "$0" "$GITEA" $CONF_ARG "$@"


2 changes: 1 addition & 1 deletion docker/root/etc/s6/gitea/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
[[ -f ./setup ]] && source ./setup

pushd /app/gitea >/dev/null
exec su-exec $USER /app/gitea/gitea web
exec su-exec $USER /usr/local/bin/gitea web
popd
17 changes: 17 additions & 0 deletions docker/root/usr/local/bin/gitea
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

###############################################################
# This script sets defaults for gitea to run in the container #
###############################################################

# It assumes that you place this script as gitea in /usr/local/bin
#
# And place the original in /usr/lib/gitea with working files in /data/gitea
GITEA="/app/gitea/gitea"
WORK_DIR="/app/gitea"
CUSTOM_PATH="/data/gitea"

# Provide docker defaults
GITEA_WORK_DIR="${GITEA_WORK_DIR:-$WORK_DIR}" GITEA_CUSTOM="${GITEA_CUSTOM:-$CUSTOM_PATH}" exec -a "$0" "$GITEA" $CONF_ARG "$@"


42 changes: 42 additions & 0 deletions docker/rootless/usr/local/bin/gitea
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

###############################################################
# This script sets defaults for gitea to run in the container #
###############################################################

# It assumes that you place this script as gitea in /usr/local/bin
#
# And place the original in /usr/lib/gitea with working files in /data/gitea
GITEA="/app/gitea/gitea"
WORK_DIR="/var/lib/gitea"
APP_INI="/etc/gitea/app.ini"

APP_INI_SET=""
for i in "$@"; do
case "$i" in
"-c")
APP_INI_SET=1
;;
"-c="*)
APP_INI_SET=1
;;
"--config")
APP_INI_SET=1
;;
"--config="*)
APP_INI_SET=1
;;
*)
;;
esac
done

if [ -z "$APP_INI_SET" ]; then
CONF_ARG="-c \"$APP_INI\""
fi


# Provide docker defaults
GITEA_WORK_DIR="${GITEA_WORK_DIR:-$WORK_DIR}" exec -a "$0" "$GITEA" $CONF_ARG "$@"


0 comments on commit 7d0629a

Please sign in to comment.