From fb226c5bfebd9d62926b2bc4e164f5e89f1e8616 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 30 Aug 2022 14:13:29 +0000 Subject: [PATCH] added some files for alpine --- codepot/docker/Dockerfile.alpine | 77 ++++++++ codepot/docker/Makefile.am | 13 +- codepot/docker/Makefile.in | 12 +- codepot/docker/alpine-httpd-fg.sh | 179 ++++++++++++++++++ codepot/docker/apache2-mod-perl/APKBUILD | 54 ++++++ .../apache2-mod-perl/apache2-mod-perl.conf | 8 + 6 files changed, 335 insertions(+), 8 deletions(-) create mode 100644 codepot/docker/Dockerfile.alpine create mode 100755 codepot/docker/alpine-httpd-fg.sh create mode 100644 codepot/docker/apache2-mod-perl/APKBUILD create mode 100644 codepot/docker/apache2-mod-perl/apache2-mod-perl.conf diff --git a/codepot/docker/Dockerfile.alpine b/codepot/docker/Dockerfile.alpine new file mode 100644 index 00000000..7a5fdf0a --- /dev/null +++ b/codepot/docker/Dockerfile.alpine @@ -0,0 +1,77 @@ +ARG VROOT=/tmp/codepot-root + +### ------------------------------------------------------------------------------- + +FROM alpine:3.15 as installer + +ARG VROOT + +RUN apk add --no-cache \ + php7-dev subversion-dev make gcc musl-dev \ + apache2 apache2-dev perl-dev alpine-sdk + +COPY codepot-0.4.0.tar.gz /tmp +COPY apache2-mod-perl/APKBUILD /tmp +COPY apache2-mod-perl/apache2-mod-perl.conf /tmp + +RUN \ + cd /tmp && \ + abuild-keygen -n -a && \ + cp -pfr /root/.abuild/*.rsa.pub /etc/apk/keys/ && \ + abuild -F -d && \ + tar -zxvf codepot-0.4.0.tar.gz && \ + cd codepot-0.4.0 && \ + ./configure \ + --prefix=/usr \ + --libdir=/usr/lib64 \ + --sysconfdir=/etc \ + --with-wwwdir=/var/www/html \ + --with-cfgdir=/etc/codepot \ + --with-depotdir=/var/lib/codepot \ + --with-logdir=/var/log/codepot \ + --with-cachedir=/var/cache/codepot \ + --with-phpextdir=`php-config --extension-dir` \ + --with-phpextinidir=/etc/php7/conf.d \ + make && make install DESTDIR=${VROOT} && rm -rf ${VROOT}/var/lib/codepot/* + +RUN sed -ri -e 's|^database_hostname[[:space:]]*=[[:space:]]*"localhost"$|database_hostname = "/var/lib/codepot/codepot.db"|g' \ + -e 's|^database_driver[[:space:]]*=[[:space:]]*""$|database_driver = "sqlite"|g' \ + -e 's|^database_use_pdo[[:space:]]*=[[:space:]]*"no"$|database_use_pdo = "yes"|g' ${VROOT}/etc/codepot/codepot.ini + +RUN mkdir -p ${VROOT}/etc/apache2/conf.d && echo LoadModule dav_svn_module modules/mod_dav_svn.so > ${VROOT}/etc/apache2/conf.d/mod_dav_svn.conf + +COPY alpine-httpd-fg.sh ${VROOT}/usr/sbin/ +RUN tar -C ${VROOT} -zcvf /tmp/codepot-root.tar.gz . + + +### ------------------------------------------------------------------------------- + +FROM alpine:3.15 + +ARG VROOT + +COPY --from=installer /tmp/codepot-root.tar.gz /tmp +COPY --from=installer /root/packages/x86_64/apache2-mod-perl-2.0.12-r1.apk /tmp + +RUN \ + apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ \ + subversion apache2 libldap \ + php7-apache2 php7-gd php7-sqlite3 php7-ldap \ + php7-pdo php7-pdo_sqlite php7-pdo_mysql \ + apache2-webdav mod_dav_svn \ + perl-switch perl-config-simple perl-digest-sha1 \ + perl-dbd-sqlite perl-ldap perl-subversion perl-mail-sendmail sqlite bash && \ + apk add --allow-untrusted /tmp/apache2-mod-perl-2.0.12-r1.apk && \ + rm -rf /var/www/html && \ + tar -C / -zxvf /tmp/codepot-root.tar.gz && \ + cp -pf /etc/codepot/codepot.httpd /etc/apache2/conf.d/codepot.conf && \ + echo "PerlSwitches -Mlib=/etc/codepot/perl" >> /etc/apache2/conf.d/perl.conf && \ + sed -ri -e 's|^max_execution_time[[:space:]]*=.*$|max_execution_time = 120|g' /etc/php7/php.ini && \ + sed -ri -e 's|/var/www/localhost/htdocs|/var/www/html|g' \ + -e 's|^User apache$|User nobody|g' \ + -e 's|^Gruop apache$|Group nobody|g' \ + -e 's|^#(LoadModule rewrite_module modules/mod_rewrite.so)|\1|g' \ + -e 's|AllowOverride None|AllowOverride All|g' /etc/apache2/httpd.conf && \ + rm -rf /tmp/* + +ENTRYPOINT ["/usr/sbin/alpine-httpd-fg.sh"] diff --git a/codepot/docker/Makefile.am b/codepot/docker/Makefile.am index 7fa81f63..b53c5e7a 100644 --- a/codepot/docker/Makefile.am +++ b/codepot/docker/Makefile.am @@ -1,17 +1,22 @@ -DOCKER ?= DOCKER_BUILDKIT=1 docker +##DOCKER ?= DOCKER_BUILDKIT=1 docker +DOCKER ?= docker all: @echo "Choose one of the following targets:" - @echo " rocky ubnt" + @echo " alpine rocky ubnt" -ubnt: @srcdir@/codepot-@VERSION@.tar.gz - $(DOCKER) build -t codepot:ubnt -f @srcdir@/Dockerfile.ubnt @srcdir@ || true +alpine: @srcdir@/codepot-@VERSION@.tar.gz + $(DOCKER) build -t codepot:ubnt -f @srcdir@/Dockerfile.alpine @srcdir@ || true rm -f @srcdir@/codepot-@VERSION@.tar.gz rocky: @srcdir@/codepot-@VERSION@.tar.gz $(DOCKER) build -t codepot:rocky -f @srcdir@/Dockerfile.rocky @srcdir@ || true rm -f @srcdir@/codepot-@VERSION@.tar.gz +ubnt: @srcdir@/codepot-@VERSION@.tar.gz + $(DOCKER) build -t codepot:ubnt -f @srcdir@/Dockerfile.ubnt @srcdir@ || true + rm -f @srcdir@/codepot-@VERSION@.tar.gz + @srcdir@/codepot-@VERSION@.tar.gz: cd .. && make dist cp ../codepot-@VERSION@.tar.gz @srcdir@/ diff --git a/codepot/docker/Makefile.in b/codepot/docker/Makefile.in index e2589540..f5f873d8 100644 --- a/codepot/docker/Makefile.in +++ b/codepot/docker/Makefile.in @@ -410,20 +410,24 @@ uninstall-am: .PRECIOUS: Makefile -DOCKER ?= DOCKER_BUILDKIT=1 docker +DOCKER ?= docker all: @echo "Choose one of the following targets:" - @echo " rocky ubnt" + @echo " alpine rocky ubnt" -ubnt: @srcdir@/codepot-@VERSION@.tar.gz - $(DOCKER) build -t codepot:ubnt -f @srcdir@/Dockerfile.ubnt @srcdir@ || true +alpine: @srcdir@/codepot-@VERSION@.tar.gz + $(DOCKER) build -t codepot:ubnt -f @srcdir@/Dockerfile.alpine @srcdir@ || true rm -f @srcdir@/codepot-@VERSION@.tar.gz rocky: @srcdir@/codepot-@VERSION@.tar.gz $(DOCKER) build -t codepot:rocky -f @srcdir@/Dockerfile.rocky @srcdir@ || true rm -f @srcdir@/codepot-@VERSION@.tar.gz +ubnt: @srcdir@/codepot-@VERSION@.tar.gz + $(DOCKER) build -t codepot:ubnt -f @srcdir@/Dockerfile.ubnt @srcdir@ || true + rm -f @srcdir@/codepot-@VERSION@.tar.gz + @srcdir@/codepot-@VERSION@.tar.gz: cd .. && make dist cp ../codepot-@VERSION@.tar.gz @srcdir@/ diff --git a/codepot/docker/alpine-httpd-fg.sh b/codepot/docker/alpine-httpd-fg.sh new file mode 100755 index 00000000..c83fa84f --- /dev/null +++ b/codepot/docker/alpine-httpd-fg.sh @@ -0,0 +1,179 @@ +#!/bin/bash +set -e + +CODEPOT_CONFIG_FILE="/var/lib/codepot/codepot.ini" +HTTPD_CONFIG_FILE="/etc/apache2/httpd.conf" + +SERVICE_PORT="" +HIDE_INDEX_PAGE="" +HTTPS_REDIRECTED="" +while getopts ":hp:-:" oc +do + case "${oc}" in + -) + case "${OPTARG}" in + port) + opt=${OPTARG} + SERVICE_PORT="${!OPTIND}" + OPTIND=$(($OPTIND + 1)) + ;; + port=*) + SERVICE_PORT=${OPTARG#*=} + opt=${OPTARG%=$val} + ;; + + hide-index-page) + opt=${OPTARG} + HIDE_INDEX_PAGE="${!OPTIND}" + OPTIND=$(($OPTIND + 1)) + ;; + + hide-index-page=*) + HIDE_INDEX_PAGE=${OPTARG#*=} + opt=${OPTARG%=$val} + ;; + + https-redirected) + opt=${OPTARG} + HTTPS_REDIRECTED="${!OPTIND}" + OPTIND=$(($OPTIND + 1)) + ;; + + https-redirected=*) + HTTPS_REDIRECTED=${OPTARG#*=} + opt=${OPTARG%=$val} + ;; + + *) + echo "Warning: unknown option - $OPTARG" + ;; + esac + ;; + + h) + echo "-------------------------------------------------------------------------" + echo "This container runs a http service on port 80." + echo "Use an external reverse proxy to enable https as it doesn't" + echo "enable the HTTP service." + echo "Extra options allowed when running the container: " + echo " -h print this help message" + echo " -p number specify the port number" + echo " -port number specify the port number" + echo " -hide-index-page yes/no hide/show the index page script from the URL" + echo " -https-redirected yes/no indicate if the requets are HTTPS redirected" + echo "-------------------------------------------------------------------------" + exit 0 + ;; + p) + SERVICE_PORT=${OPTARG#*=} + opt=${OPTARG%=$val} + ;; + + *) + echo "Warning: unknown option - $OPTARG" + ;; + esac +done + +## fall back to default values if the given values are not proper +echo "${SERVICE_PORT}" | grep -q -E '^[[:digit:]]+$' || SERVICE_PORT="80" +[[ "${HIDE_INDEX_PAGE}" == "" ]] && HIDE_INDEX_PAGE="no" +[[ "${HTTPS_REDIRECTED}" == "" ]] && HTTPS_REDIRECTED="no" + + +# Note: we don't just use "apache2ctl" here because it itself is just a shell-script wrapper around apache2 which provides extra functionality like "apache2ctl start" for launching apache2 in the background. +# (also, when run as "apache2ctl ", it does not use "exec", which leaves an undesirable resident shell process) + +: "${APACHE_CONFDIR:=/etc/apache2}" +: "${APACHE_ENVVARS:=$APACHE_CONFDIR/envvars}" +if test -f "$APACHE_ENVVARS"; then + . "$APACHE_ENVVARS" +fi + +# Apache gets grumpy about PID files pre-existing +: "${APACHE_RUN_DIR:=/var/run/apache2}" +: "${APACHE_PID_FILE:=$APACHE_RUN_DIR/apache2.pid}" +rm -f "$APACHE_PID_FILE" + +# create missing directories +# (especially APACHE_RUN_DIR, APACHE_LOCK_DIR, and APACHE_LOG_DIR) +for e in "${!APACHE_@}"; do + if [[ "$e" == *_DIR ]] && [[ "${!e}" == /* ]]; then + # handle "/var/lock" being a symlink to "/run/lock", but "/run/lock" not existing beforehand, so "/var/lock/something" fails to mkdir + # mkdir: cannot create directory '/var/lock': File exists + dir="${!e}" + while [ "$dir" != "$(dirname "$dir")" ]; do + dir="$(dirname "$dir")" + if [ -d "$dir" ]; then + break + fi + absDir="$(readlink -f "$dir" 2>/dev/null || :)" + if [ -n "$absDir" ]; then + mkdir -p "$absDir" + fi + done + + mkdir -p "${!e}" + fi +done + +[ ! -d /var/lib/codepot/attachments ] && mkdir -p /var/lib/codepot/attachments +[ ! -d /var/lib/codepot/files ] && mkdir -p /var/lib/codepot/files +[ ! -d /var/lib/codepot/issuefiles ] && mkdir -p /var/lib/codepot/issuefiles +[ ! -d /var/lib/codepot/svnrepo ] && mkdir -p /var/lib/codepot/svnrepo +[ ! -d /var/lib/codepot/usericons ] && mkdir -p /var/lib/codepot/usericons +[ ! -f /var/lib/codepot/codepot.db ] && sqlite3 -init /etc/codepot/codepot.sqlite /var/lib/codepot/codepot.db "" + +mkdir -p /var/cache/codepot /var/log/codepot +chown -R nobody:nobody /var/lib/codepot /var/cache/codepot /var/log/codepot + +[ ! -f "${CODEPOT_CONFIG_FILE}" ] && cp -pf /etc/codepot/codepot.ini "${CODEPOT_CONFIG_FILE}" + +grep -F -q '' /etc/apache2/conf.d/codepot.conf || { + cat <> /etc/apache2/conf.d/codepot.conf + + SetEnv CODEPOT_CONFIG_FILE ${CODEPOT_CONFIG_FILE} + +EOF +} + +sed -r -i "s|PerlSetEnv CODEPOT_CONFIG_FILE .*\$|PerlSetEnv CODEPOT_CONFIG_FILE ${CODEPOT_CONFIG_FILE}|g" /etc/apache2/conf.d/codepot.conf + + +## change the port number as specified on the command line +echo "Configuring to listen on the port[$SERVICE_PORT] hide-index-page[$HIDE_INDEX_PAGE] https-redirected[$HTTPS_REDIRECTED]" + +sed -r -i "s|^Listen[[:space:]]+.*|Listen ${SERVICE_PORT}|g" "${HTTPD_CONFIG_FILE}" + +if [[ "${HTTPS_REDIRECTED}" =~ [Yy][Ee][Ss] ]] +then + ## The DAV COPY request contains the header 'Destination: https://' if the origin request + ## is HTTPS. This container is configured to server on HTTP only. If HTTPS is redirected + ## to HTTP, we must translate https:// to http:// in the Destination header. + ## Otherwise, the response is 502 Bad Gateway. + echo "RequestHeader edit Destination ^https: http: early" > /etc/apache2/conf.d/codepot-dav-https-redirected.conf +else + rm -f /etc/apache2/conf.d/codepot-dav-https-redirected.conf +fi + +if [[ "${HIDE_INDEX_PAGE}" =~ [Yy][Ee][Ss] ]] +then + sed -r -i 's|^index_page[[:space:]]*=.*$|index_page=""|g' "${CODEPOT_CONFIG_FILE}" + + echo 'RewriteEngine On +RewriteBase / +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ index.php/$1 [L]' > /var/www/html/.htaccess + + sed -r -i '//,/<\/Directory>/s|^[[:space:]]*AllowOverride[[:space:]]+.*$|\tAllowOverride All|g' "${HTTPD_CONFIG_FILE}" + +else + sed -r -i 's|^index_page[[:space:]]*=.*$|index_page="index.php"|g' "${CODEPOT_CONFIG_FILE}" + rm -rf /var/www/html/.htaccess + + sed -r -i '//,/<\/Directory>/s|^[[:space:]]*AllowOverride[[:space:]]+.*$|\tAllowOverride None|g' "${HTTPD_CONFIG_FILE}" +fi + +#httpd server in the foreground +exec httpd -DFOREGROUND diff --git a/codepot/docker/apache2-mod-perl/APKBUILD b/codepot/docker/apache2-mod-perl/APKBUILD new file mode 100644 index 00000000..57fada1c --- /dev/null +++ b/codepot/docker/apache2-mod-perl/APKBUILD @@ -0,0 +1,54 @@ +# Contributor: Valery Kartel +# Contributor: Matt Smith +# Maintainer: Matt Smith +pkgname=apache2-mod-perl +_pkgreal=mod_perl +pkgver=2.0.12 +pkgrel=1 +pkgdesc="Perl Module for Apache2" +url="https://perl.apache.org/" +arch="all" +license="Apache-2.0" +depends="apache2" +depends_dev="$pkgname" +makedepends="apache2-dev perl-dev apr-dev apr-util-dev" +options="!check" # fails to start test server +subpackages="$pkgname-dbg $pkgname-doc $pkgname-dev" +source="https://archive.apache.org/dist/perl/$_pkgreal-$pkgver.tar.gz + $pkgname.conf" +builddir="$srcdir/$_pkgreal-$pkgver" + +build() { + perl Makefile.PL \ + INSTALLDIRS=vendor \ + MP_APXS=/usr/bin/apxs + make +} + +check() { + make test +} + + +package() { + make DESTDIR="$pkgdir" install + find "$pkgdir" \( -name perllocal.pod -o -name .packlist \) -delete + install -Dm644 "$srcdir"/$pkgname.conf \ + "$pkgdir"/etc/apache2/conf.d/$_pkgreal.conf +} + +dev() { + default_dev + + mv "$pkgdir"/usr/bin "$subpkgdir"/usr + + mkdir -p "$subpkgdir"/usr/lib/perl5/vendor_perl/auto/Apache2 + mv "$pkgdir"/usr/lib/perl5/vendor_perl/auto/Apache2/Build \ + "$pkgdir"/usr/lib/perl5/vendor_perl/auto/Apache2/typemap \ + "$subpkgdir"/usr/lib/perl5/vendor_perl/auto/Apache2 +} + +sha512sums=" +890dca0950847e32180485cabbeffbf236af2c92c7df957a233c210022b5172957eddb1db3e9281b87cd438d2fa404a05ae99c7eda098267c68d5e9262b400b0 mod_perl-2.0.12.tar.gz +aa6acb5dc403dad0ed9761a3fb4121a4c73c247e0fce9615ff571c7071d2d1bf88fca140f304b2d559a7c153af317dddc0acbacf1ea86cb35becd757ee9a00bb apache2-mod-perl.conf +" diff --git a/codepot/docker/apache2-mod-perl/apache2-mod-perl.conf b/codepot/docker/apache2-mod-perl/apache2-mod-perl.conf new file mode 100644 index 00000000..50309e2d --- /dev/null +++ b/codepot/docker/apache2-mod-perl/apache2-mod-perl.conf @@ -0,0 +1,8 @@ +LoadModule perl_module modules/mod_perl.so + +## +## AddHandler perl-script .pl +## PerlResponseHandler ModPerl::Registry +## PerlOptions +ParseHeaders +## Options +ExecCGI +##