diff --git a/gitea/CHANGELOG.md b/gitea/CHANGELOG.md index 9d8161ee2..5a98a3eb9 100644 --- a/gitea/CHANGELOG.md +++ b/gitea/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.17.2.1 (26-09-2022) +- fixed error with ssl + ## 1.17.2 (07-09-2022) - Update to version 1.17.2 from go-gitea/gitea diff --git a/gitea/Dockerfile b/gitea/Dockerfile index 985a2b5fe..2dab99601 100644 --- a/gitea/Dockerfile +++ b/gitea/Dockerfile @@ -26,22 +26,52 @@ FROM ${BUILD_FROM} ENV S6_CMD_WAIT_FOR_SERVICES=1 \ S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \ S6_SERVICES_GRACETIME=0 + +USER root ################## # 3 Install apps # ################## +# Add rootfs +COPY rootfs/ / + +# Corrects permissions for s6 v3 +RUN if [ -d /etc/cont-init.d ]; then chmod -R 755 /etc/cont-init.d; fi && \ + if [ -d /etc/services.d ]; then chmod -R 755 /etc/services.d; fi && \ + if [ -f /entrypoint.sh ]; then chmod 755 /entrypoint.sh; fi + +# Modules +ARG MODULES="00-banner.sh" + +# Automatic modules download +RUN if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi \ + && if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi \ + && apt-get update && apt-get install -yqq --no-install-recommends ca-certificates || apk add --no-cache ca-certificates >/dev/null || true \ + && mkdir -p /etc/cont-init.d \ + && for scripts in $MODULES; do echo "$scripts" && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /etc/cont-init.d/"$scripts" && [ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] || (echo "script failed to install $scripts" && exit 1); done \ + && chmod -R 755 /etc/cont-init.d || printf '%s\n' "${MODULES}" >/MODULESFILE + +# Manual apps +ENV PACKAGES="" + +# Automatic apps & bashio +RUN if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi \ + && if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi \ + && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/automatic_packages.sh" --output /automatic_packages.sh \ + && chmod 777 /automatic_packages.sh \ + && eval /./automatic_packages.sh "${PACKAGES:-}" \ + && rm /automatic_packages.sh || (printf '%s\n' "${PACKAGES:-}" > /ENVFILE; \ + if [ -f /etc/s6-overlay/s6-rc.d/init-migrations/run ]; then chmod +x /etc/cont-init.d/00-aaa_dockerfile_backup.sh && sed -i "1a /./etc/cont-init.d/00-aaa_dockerfile_backup.sh" /etc/s6-overlay/s6-rc.d/init-migrations/run;fi) + EXPOSE 22 3000 ################ # 4 Entrypoint # ################ -#RUN chmod 777 /entrypoint.sh -#WORKDIR / -#ENTRYPOINT [ "/usr/bin/env" ] -#CMD [ "/entrypoint.sh" ] -#SHELL ["/bin/bash", "-o", "pipefail", "-c"] +RUN chmod 777 /entrypoint.sh +ENTRYPOINT [ "/entrypoint.sh" ] ############ # 5 Labels # @@ -71,4 +101,4 @@ LABEL \ org.opencontainers.image.documentation="https://github.com/${BUILD_REPOSITORY}/blob/main/README.md" \ org.opencontainers.image.created=${BUILD_DATE} \ org.opencontainers.image.revision=${BUILD_REF} \ - org.opencontainers.image.version=${BUILD_VERSION} \ No newline at end of file + org.opencontainers.image.version=${BUILD_VERSION} diff --git a/gitea/README.md b/gitea/README.md index 53c1fc08b..12d7311b5 100644 --- a/gitea/README.md +++ b/gitea/README.md @@ -25,6 +25,10 @@ This addon is based on the [docker image](https://hub.docker.com/r/gitea/gitea). ```yaml certfile: fullchain.pem #ssl certificate, must be located in /ssl keyfile: privkey.pem #sslkeyfile, must be located in /ssl +ssl: should the app use https or not +APP_NAME: name of the app +DOMAIN: domain to be reached # default : homeassistant.local +ROOT_URL: customize root_url, should not be needed unless specific needs ``` Webui can be found at `:port`. diff --git a/gitea/config.json b/gitea/config.json index 6cb635402..1560d815d 100644 --- a/gitea/config.json +++ b/gitea/config.json @@ -9,13 +9,15 @@ "init": false, "map": [ "share:rw", - "ssl:ro" + "ssl:rw" ], "name": "Gitea", "options": { "certfile": "fullchain.pem", "keyfile": "privkey.pem", - "ssl": false + "ssl": false, + "APP_NAME": "Gitea for Homeassistant", + "DOMAIN": "homeassistant.local" }, "ports": { "22/tcp": 2222, @@ -23,15 +25,18 @@ }, "ports_description": { "22/tcp": "Ssh", - "3000/tcp": "Http web interface" + "3000/tcp": "Web interface" }, "schema": { "certfile": "str", "keyfile": "str", - "ssl": "bool" + "ssl": "bool", + "APP_NAME": "str?", + "DOMAIN": "str", + "ROOT_URL": "str?" }, "slug": "gitea", "url": "https://github.com/alexbelgium/hassio-addons/tree/master/gitea", - "version": "1.17.2", + "version": "1.17.2.1", "webui": "[PROTO:ssl]://[HOST]:[PORT:3000]" } diff --git a/gitea/rootfs/entrypoint.sh b/gitea/rootfs/entrypoint.sh new file mode 100644 index 000000000..85d8a9212 --- /dev/null +++ b/gitea/rootfs/entrypoint.sh @@ -0,0 +1,27 @@ +#!/bin/bash +echo "Starting..." + +############################ +# Backup Dockerfile Script # +############################ + +if [ -f /etc/cont-init.d/00-aaa_dockerfile_backup.sh ]; then + chown "$(id -u)":"$(id -g)" /etc/cont-init.d/00-aaa_dockerfile_backup.sh + chmod +x /etc/cont-init.d/00-aaa_dockerfile_backup.sh + /./etc/cont-init.d/00-aaa_dockerfile_backup.sh + rm /etc/cont-init.d/00-aaa_dockerfile_backup.sh +fi + +#################### +# Starting scripts # +#################### + +for SCRIPTS in /etc/cont-init.d/*; do + [ -e "$SCRIPTS" ] || continue + echo "$SCRIPTS: executing" + chown "$(id -u)":"$(id -g)" "$SCRIPTS" + chmod a+x "$SCRIPTS" + # Change shebang if no s6 supervision + sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' "$SCRIPTS" + /."$SCRIPTS" || echo "$SCRIPTS: exiting $?" +done diff --git a/gitea/rootfs/etc/cont-init.d/00-aaa_dockerfile_backup.sh b/gitea/rootfs/etc/cont-init.d/00-aaa_dockerfile_backup.sh new file mode 100644 index 000000000..b983e4efc --- /dev/null +++ b/gitea/rootfs/etc/cont-init.d/00-aaa_dockerfile_backup.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# If dockerfile failed install manually + +############################## +# Automatic modules download # +############################## +if [ -e "/MODULESFILE" ]; then + MODULES=$(/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi \ + && if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi \ + && apt-get update && apt-get install -yqq --no-install-recommends ca-certificates || apk add --no-cache ca-certificates >/dev/null || true \ + && mkdir -p /etc/cont-init.d \ + && for scripts in $MODULES; do echo "$scripts" && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /etc/cont-init.d/"$scripts" && [ "$(sed -n '/\/bin/p;q' /etc/cont-init.d/"$scripts")" != "" ] || (echo "script failed to install $scripts" && exit 1); done \ + && chmod -R 755 /etc/cont-init.d +fi + +####################### +# Automatic installer # +####################### +if [ -e "/ENVFILE" ]; then + PACKAGES=$(/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi \ + && if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi \ + && curl -f -L -s -S "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/automatic_packages.sh" --output /automatic_packages.sh \ + && chmod 777 /automatic_packages.sh \ + && eval /./automatic_packages.sh "${PACKAGES:-}" \ + && rm /automatic_packages.sh +fi + +if [ -e "/MODULESFILE" ] && [ ! -f /entrypoint.sh ]; then + for scripts in $MODULES; do + echo "$scripts : executing" + chown "$(id -u)":"$(id -g)" /etc/cont-init.d/"$scripts" + chmod a+x /etc/cont-init.d/"$scripts" + /./etc/cont-init.d/"$scripts" || echo "/etc/cont-init.d/$scripts: exiting $?" + rm /etc/cont-init.d/"$scripts" + done | tac +fi + +####################### +# Correct permissions # +####################### +[ -d /etc/services.d ] && chmod -R 777 /etc/services.d +[ -d /etc/cont-init.d ] && chmod -R 777 /etc/cont-init.d diff --git a/gitea/rootfs/etc/cont-init.d/99-run.sh b/gitea/rootfs/etc/cont-init.d/99-run.sh new file mode 100644 index 000000000..be1738d01 --- /dev/null +++ b/gitea/rootfs/etc/cont-init.d/99-run.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bashio +# shellcheck shell=bash + +for file in /data/gitea/conf/app.ini /etc/templates/app.ini; do + +if [ ! -f "$file" ]; then +continue +fi + +############## +# ADAPT PORT # +############## + +sed -i "/HTTP_PORT/d" "$file" +sed -i "/server/a HTTP_PORT=$(bashio::addon.port 3000)" "$file" + +############## +# SSL CONFIG # +############## + +# Clean values +sed -i "/PROTOCOL/d" "$file" +sed -i "/CERT_FILE/d" "$file" +sed -i "/KEY_FILE/d" "$file" + +# Add ssl +bashio::config.require.ssl +if bashio::config.true 'ssl'; then +bashio::log.info "ssl is enabled" +sed -i "/server/a PROTOCOL=https" "$file" +sed -i "/server/a CERT_FILE=/ssl/$(bashio::config 'certfile')" "$file" +sed -i "/server/a KEY_FILE=/ssl/$(bashio::config 'keyfile')" "$file" +chmod 744 /ssl/* +else +sed -i "/server/a PROTOCOL=http" "$file" +fi + +done + +#################### +# ADAPT PARAMETERS # +#################### + +for param in APP_NAME DOMAIN ROOT_URL; do + # Remove parameter + sed -i "/$param/d" "$file" + + # Define parameter + if bashio::config.has_value "$param"; then + echo "parameter set : $param=$(bashio::config '$param')" + sed -i "/server/a $param=$(bashio::config '$param')" "$file" + fi + + # Allow at setup + sed -i "1a $param = $(bashio::config '$param')" /etc/s6/gitea/setup + +done + +############## +# LAUNCH APP # +############## + +bashio::log.info "Please wait while the app is loading !" + +/./usr/bin/entrypoint