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