|
| 1 | +# Default context |
| 2 | +ARG BUILD_PKP_TOOL=omp \ |
| 3 | + BUILD_PKP_VERSION=3.3.0-21 \ |
| 4 | + BUILD_PKP_APP_PATH=/app \ |
| 5 | + BUILD_WEB_SERVER=php:8.1-apache \ |
| 6 | + BUILD_OS=alpine:3.18 \ |
| 7 | + BUILD_LABEL=notset |
| 8 | + |
| 9 | +# GET PKP CODE |
| 10 | +FROM ${BUILD_OS} AS pkp_code |
| 11 | + |
| 12 | +# Context |
| 13 | +ARG BUILD_PKP_TOOL \ |
| 14 | + BUILD_PKP_VERSION \ |
| 15 | + BUILD_PKP_APP_PATH |
| 16 | + |
| 17 | +RUN apk add --update --no-cache curl tar \ |
| 18 | + && mkdir "${BUILD_PKP_APP_PATH}" |
| 19 | + |
| 20 | +WORKDIR "/${BUILD_PKP_APP_PATH}" |
| 21 | + |
| 22 | +# ADD is supossed to download, extract and remove, but there is an issue with some docker |
| 23 | +# versions so, for compatibility, doing it manually: https://github.com/moby/moby/issues/33849 |
| 24 | +# ADD "https://pkp.sfu.ca/$BUILD_PKP_TOOL/download/$BUILD_PKP_TOOL-$BUILD_PKP_VERSION.tar.gz" "$BUILD_PKP_APP_PATH" |
| 25 | + |
| 26 | +RUN curl -Ss -O "https://pkp.sfu.ca/${BUILD_PKP_TOOL}/download/${BUILD_PKP_TOOL}-${BUILD_PKP_VERSION}.tar.gz" \ |
| 27 | + && tar --strip-components=1 -xvzf "${BUILD_PKP_TOOL}-${BUILD_PKP_VERSION}.tar.gz" -C "${BUILD_PKP_APP_PATH}" > /tmp/untar.lst |
| 28 | + |
| 29 | +RUN echo "===============================================================" \ |
| 30 | + && echo " ---> PKP application: ${PKP_TOOL}" \ |
| 31 | + && echo " ---> Version: ${BUILD_PKP_VERSION}" \ |
| 32 | + && echo "===============================================================" |
| 33 | + |
| 34 | + |
| 35 | +# GET & SET THE LAMP |
| 36 | +FROM ${BUILD_WEB_SERVER} |
| 37 | + |
| 38 | +RUN echo "===============================================================" \ |
| 39 | + && echo " ---> Web server: ${BUILD_WEB_SERVER} (over debian)" \ |
| 40 | + && echo "===============================================================" |
| 41 | + |
| 42 | +# TODO: |
| 43 | +# - Concatenate calls to reduce the layers |
| 44 | +# - Replace with PKP_variables when possible |
| 45 | +# - Remove "vim" in production image |
| 46 | +# - Ensure all required packages and php extensions |
| 47 | +# - Test with OJS, OMP and OPS. |
| 48 | +# - Redirect log output to stdout & FILE. |
| 49 | + |
| 50 | +# Context |
| 51 | +ARG BUILD_PKP_TOOL \ |
| 52 | + BUILD_PKP_VERSION \ |
| 53 | + BUILD_LABEL \ |
| 54 | + BUILD_PKP_APP_PATH |
| 55 | + |
| 56 | +LABEL maintainer="Public Knowledge Project <marc.bria@uab.es>" |
| 57 | +LABEL org.opencontainers.image.vendor="Public Knowledge Project" |
| 58 | +LABEL org.opencontainers.image.title="PKP ${BUILD_PKP_TOOL} Web Application" |
| 59 | +LABEL org.opencontainers.image.description="Runs a ${BUILD_PKP_TOOL} application over Apache" |
| 60 | +LABEL build_version="Docker for ${BUILD_PKP_TOOL} ${BUILD_PKP_VERSION} - Build-date: ${BUILD_LABEL}" |
| 61 | + |
| 62 | +# ARGs only work during building time, so they need to be exported to ENVs: |
| 63 | +ENV PKP_TOOL="${BUILD_PKP_TOOL:-ojs}" \ |
| 64 | + PKP_VERSION="${BUILD_PKP_VERSION:-3.3.0-16}" \ |
| 65 | + SERVERNAME="localhost" \ |
| 66 | + WWW_USER="www-data" \ |
| 67 | + WWW_PATH_CONF="/etc/apache2/apache2.conf" \ |
| 68 | + WWW_PATH_ROOT="/var/www" \ |
| 69 | + HTTPS="on" \ |
| 70 | + PKP_CLI_INSTALL="0" \ |
| 71 | + PKP_DB_HOST="localhost" \ |
| 72 | + PKP_DB_USER="${MYSQL_USER:-pkp}" \ |
| 73 | + PKP_DB_PASSWORD="${MYSQL_PASSWORD:-changeMe}" \ |
| 74 | + PKP_DB_NAME="${MYSQL_DATABASE:-pkp}" \ |
| 75 | + PKP_WEB_CONF="/etc/apache2/conf.d/$BUILD_PKP_TOOL.conf" \ |
| 76 | + PKP_CONF="config.inc.php" \ |
| 77 | + PKP_CMD="/usr/local/bin/${BUILD_PKP_TOOL:-ojs}-start" |
| 78 | + |
| 79 | + |
| 80 | +# Basic packages (todo: Remove what don't need to be installed) |
| 81 | +ENV PACKAGES="cron rsyslog apache2-utils ca-certificates vim" |
| 82 | + |
| 83 | +# DEV packages are not required in production images. |
| 84 | +ENV PACKAGES_DEV="zlib1g-dev libmcrypt-dev libonig-dev libpng-dev libxslt-dev libpng-dev libfreetype6-dev libjpeg62-turbo-dev libzip-dev" |
| 85 | + |
| 86 | +# PHP extensions |
| 87 | +ENV PHP_EXTENSIONS="gd gettext iconv intl mbstring mysqli pdo_mysql xml xsl zip" |
| 88 | + |
| 89 | +# Extension names as required by docker-php-ext-* helpers. Possible values are: |
| 90 | +# bcmath bz2 calendar ctype curl dba dom enchant exif ffi fileinfo filter ftp gd gettext gmp hash iconv imap intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer xml xmlreader xmlwriter xsl zend_test zip |
| 91 | + |
| 92 | + |
| 93 | +WORKDIR ${WWW_PATH_ROOT}/html |
| 94 | + |
| 95 | +# For Debian: |
| 96 | +RUN apt-get update && apt-get install -y ${PACKAGES} ${PACKAGES_DEV} |
| 97 | + |
| 98 | +# By default GD don't include jpeg and freetype support: |
| 99 | +RUN docker-php-ext-configure gd --with-freetype --with-jpeg |
| 100 | + |
| 101 | +# Installing PHP extensions: |
| 102 | +RUN docker-php-ext-install -j$(nproc) ${PHP_EXTENSIONS} |
| 103 | + |
| 104 | +# Enable installed extensions: |
| 105 | +RUN docker-php-ext-enable ${PHP_EXTENSIONS} |
| 106 | + |
| 107 | +# Enable mod_rewrite and mod_ssl |
| 108 | +RUN a2enmod rewrite ssl |
| 109 | + |
| 110 | +# Building PKP-TOOL (ie: OJS): |
| 111 | + |
| 112 | +# Get the code |
| 113 | +COPY --from=pkp_code "${BUILD_PKP_APP_PATH}" . |
| 114 | + |
| 115 | +# Create directories |
| 116 | +RUN mkdir -p /etc/ssl/apache2 "${WWW_PATH_ROOT}/files" /run/apache2 |
| 117 | +# Make php/conf.d indpendent of the php version: |
| 118 | +RUN PHP_INI_DIR=$(php --ini | grep "Configuration File (php.ini) Path" | cut -d: -f2 | xargs) \ |
| 119 | + && mkdir -p "$PHP_INI_DIR/conf.d" \ |
| 120 | + && mkdir -p "/etc/php" \ |
| 121 | + && ln -sfn "$PHP_INI_DIR/conf.d" /etc/php/conf.d |
| 122 | +# Redirect logs to stdout |
| 123 | +RUN echo "log_errors = On" >> /etc/php/conf.d/log-errors.ini \ |
| 124 | + && echo "error_log = /dev/stderr" >> /etc/php/conf.d/log-errors.ini |
| 125 | +# OJS config |
| 126 | +RUN echo "PKP_CONF: ${PKP_CONF}" |
| 127 | +RUN cp -a config.TEMPLATE.inc.php "${WWW_PATH_ROOT}/html/${PKP_CONF}" |
| 128 | +RUN chown -R ${WWW_USER}:${WWW_USER} "${WWW_PATH_ROOT}" |
| 129 | +# Prepare freefont for captcha |
| 130 | +# && ln -s /usr/share/fonts/TTF/FreeSerif.ttf /usr/share/fonts/FreeSerif.ttf \ |
| 131 | + |
| 132 | +# Prepare crontab |
| 133 | +RUN echo "0 * * * * pkp-run-scheduled" | crontab - |
| 134 | +# Prepare httpd.conf |
| 135 | +RUN sed -i -e '\#<Directory />#,\#</Directory>#d' ${WWW_PATH_CONF} |
| 136 | +RUN sed -i -e "s/^ServerSignature.*/ServerSignature Off/" ${WWW_PATH_CONF} |
| 137 | +# Clear the image (files to be deleted were in exclude.list but this is not required with multi-build). |
| 138 | +RUN rm -rf /tmp/* |
| 139 | +RUN rm -rf /root/.cache/* \ |
| 140 | +RUN apt-get clean autoclean \ |
| 141 | + && apt-get autoremove --yes |
| 142 | + |
| 143 | +# # Optional: Some folders are not required (as .git .travis.yml test .gitignore .gitmodules ...) |
| 144 | +# && find . -name ".git" -exec rm -Rf '{}' \; \ |
| 145 | +# && find . -name ".travis.yml" -exec rm -Rf '{}' \; \ |
| 146 | +# && find . -name "test" -exec rm -Rf '{}' \; \ |
| 147 | +# && find . \( -name .gitignore -o -name .gitmodules -o -name .keepme \) -exec rm -Rf '{}' \; |
| 148 | + |
| 149 | +COPY "templates/common/$BUILD_PKP_TOOL/root/" / |
| 150 | + |
| 151 | +RUN echo "${BUILD_PKP_TOOL}-${BUILD_PKP_VERSION} [build:" $(date "+%Y%m%d-%H%M%S") "]" > "${WWW_PATH_ROOT}/container.version" \ |
| 152 | + && rm -f "${BUILD_PKP_TOOL}-${BUILD_PKP_VERSION}.tar.gz" \ |
| 153 | + && cat "${WWW_PATH_ROOT}/container.version" |
| 154 | + |
| 155 | +EXPOSE 80 |
| 156 | +EXPOSE 443 |
| 157 | + |
| 158 | +VOLUME [ "${WWW_PATH_ROOT}/files", "${WWW_PATH_ROOT}/public" ] |
| 159 | + |
| 160 | +RUN chmod +x "/usr/local/bin/${BUILD_PKP_TOOL}-start" |
| 161 | + |
| 162 | +RUN echo "===============================================================" \ |
| 163 | + && echo " ---> PKP application: ${PKP_TOOL}" \ |
| 164 | + && echo " ---> Version: ${BUILD_PKP_VERSION}" \ |
| 165 | + && echo " ---> BUILD ID: $(cat ${WWW_PATH_ROOT}/container.version)" \ |
| 166 | + && echo " ---> Run: ${PKP_CMD}" \ |
| 167 | + && echo "===============================================================" |
| 168 | + |
| 169 | +CMD "${PKP_CMD}" |
0 commit comments