Skip to content

Commit

Permalink
publish: Merge branch 'run-as-non-root'
Browse files Browse the repository at this point in the history
  • Loading branch information
pabra committed Dec 14, 2023
2 parents f497d31 + b7fc508 commit fcf9446
Show file tree
Hide file tree
Showing 18 changed files with 1,423 additions and 24 deletions.
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ RUN apk add --no-cache gettext \
ARG TZDATA_VERSION=2023c-r1
ARG AWSTATS_VERSION=7.9-r0

RUN apk add --no-cache awstats=${AWSTATS_VERSION} tzdata=${TZDATA_VERSION}
RUN apk add --no-cache awstats=${AWSTATS_VERSION} tzdata=${TZDATA_VERSION} \
&& touch /etc/awstats/awstats.conf \
&& touch /usr/local/apache2/conf/awstats_httpd.conf \
&& touch /usr/local/apache2/conf/httpd.conf \
&& chmod g+w /etc/awstats/awstats.conf \
&& chmod g+w /usr/local/apache2/conf/awstats_httpd.conf \
&& chmod g+w /usr/local/apache2/conf/httpd.conf \
&& chmod -R g+w /usr/local/apache2/logs \
&& chmod -R g+w /var/lib/awstats \
&& sed 's/^Listen 80/Listen $HTTPD_PORT/' /usr/local/apache2/conf/httpd.conf > /usr/local/apache2/conf/httpd_env.conf

COPY awstats_env.conf /etc/awstats/
COPY awstats_httpd.conf /usr/local/apache2/conf/
COPY awstats_httpd_env.conf /usr/local/apache2/conf/
COPY entrypoint.sh /usr/local/bin/

ENV AWSTATS_CONF_LOGFILE="/var/local/log/access.log"
Expand All @@ -34,6 +43,7 @@ ENV AWSTATS_CONF_SITEDOMAIN="my_website"
ENV AWSTATS_CONF_HOSTALIASES="localhost 127.0.0.1 REGEX[^.*$]"
ENV AWSTATS_CONF_INCLUDE="."
ENV AWSTATS_CONF_ALLOWFULLYEARVIEW=2
ENV HTTPD_PORT="80"

ENTRYPOINT ["entrypoint.sh"]
CMD ["httpd-foreground"]
2 changes: 1 addition & 1 deletion awstats_httpd.conf → awstats_httpd_env.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<VirtualHost *:80>
<VirtualHost *:$HTTPD_PORT>
LoadModule cgi_module modules/mod_cgi.so
LoadModule perl_module /usr/lib/apache2/mod_perl.so

Expand Down
2 changes: 2 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ if [ -x /usr/local/bin/autorun.sh ]; then
fi

envsubst </etc/awstats/awstats_env.conf >/etc/awstats/awstats.conf
envsubst </usr/local/apache2/conf/awstats_httpd_env.conf >/usr/local/apache2/conf/awstats_httpd.conf
envsubst </usr/local/apache2/conf/httpd_env.conf >/usr/local/apache2/conf/httpd.conf

exec "$@"
23 changes: 17 additions & 6 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ else
no_tty='-T'
fi

run_tests() {
export HTTPD_PORT="$1"
export USER="$2"
docker-compose -f test/docker-compose.yml up -d
docker-compose -f test/docker-compose.yml run --rm ${no_tty} awstats-test /bin/sh -c "wait4ports -t 10 tcp://awstats:$HTTPD_PORT"
docker-compose -f test/docker-compose.yml run --rm ${no_tty} awstats-test test1.sh "$HTTPD_PORT"
docker-compose -f test/docker-compose.yml exec ${no_tty} awstats awstats_updateall.pl now
docker-compose -f test/docker-compose.yml run --rm ${no_tty} awstats-test test2.sh "$HTTPD_PORT"
docker-compose -f test/docker-compose.yml exec ${no_tty} awstats awstats_updateall.pl now
docker-compose -f test/docker-compose.yml run --rm ${no_tty} awstats-test test3.sh "$HTTPD_PORT"
}

if [ "$1" != 'skip_build' ]; then
docker-compose -f test/docker-compose.yml build
fi

docker-compose -f test/docker-compose.yml up -d
docker-compose -f test/docker-compose.yml run --rm ${no_tty} awstats-test /bin/sh -c 'wait4ports -t 10 tcp://awstats:80 && test1.sh'
docker-compose -f test/docker-compose.yml exec ${no_tty} awstats awstats_updateall.pl now
docker-compose -f test/docker-compose.yml run --rm ${no_tty} awstats-test test2.sh
docker-compose -f test/docker-compose.yml exec ${no_tty} awstats awstats_updateall.pl now
docker-compose -f test/docker-compose.yml run --rm ${no_tty} awstats-test test3.sh
run_tests 80 0

cleanup

run_tests 4567 1234
3 changes: 3 additions & 0 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ services:
dockerfile: Dockerfile
image: pabra/awstats:test
container_name: awstats
user: "${USER:-0}:0"
environment:
HTTPD_PORT: ${HTTPD_PORT:-80}
networks:
- awstats-net
volumes:
Expand Down
Loading

0 comments on commit fcf9446

Please sign in to comment.