1
0
Fork 0
mirror of synced 2024-05-20 12:42:39 +12:00

introduce multi-stage build

This commit is contained in:
Mostafa Hussein 2019-10-06 02:09:19 +02:00
parent c6f6cdca0a
commit 4d84d337b1
8 changed files with 121 additions and 90 deletions

View file

@ -15,7 +15,6 @@ services:
- docker
before_install:
- composer update --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts
- sudo service mysql stop
#- mkdir -p tests/resources/storage/db
#- cp -r tests/resources/mock/db tests/resources/storage/db
@ -26,4 +25,4 @@ install:
script:
- docker ps
- vendor/bin/phpunit --configuration phpunit.xml
- docker-compose -f tests/resources/docker-compose.yml exec appwrite ./vendor/bin/phpunit --configuration phpunit.xml

View file

@ -100,8 +100,6 @@ git clone git@github.com:[YOUR_FORK_HERE]/appwrite.git
cd appwrite
composer update --ignore-platform-reqs --optimize-autoloader --no-dev --no-plugins --no-scripts
npm install
docker-compose up -d

View file

@ -1,66 +1,97 @@
FROM ubuntu:18.04 AS builder
LABEL maintainer="team@appwrite.io"
ARG TESTING=false
ENV TZ=Asia/Tel_Aviv \
DEBIAN_FRONTEND=noninteractive \
PHP_VERSION=7.3 \
PHP_REDIS_VERSION=3.1.2
RUN \
apt-get update && \
apt-get install -y --no-install-recommends --no-install-suggests ca-certificates software-properties-common wget curl git openssl && \
LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php && \
apt-get update && \
apt-get install -y --no-install-recommends --no-install-suggests make php$PHP_VERSION php$PHP_VERSION-dev zip unzip php$PHP_VERSION-zip && \
# redis php extension
wget -q https://github.com/phpredis/phpredis/archive/$PHP_REDIS_VERSION.tar.gz && \
tar -xf $PHP_REDIS_VERSION.tar.gz && \
cd phpredis-$PHP_REDIS_VERSION && \
phpize$PHP_VERSION && \
./configure && \
make && \
# composer
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
WORKDIR /usr/local/src/
# Updating PHP dependencies and auto-loading...
ENV TESTING=$TESTING
COPY composer.* /usr/local/src/
RUN composer update --ignore-platform-reqs --optimize-autoloader \
--no-plugins --no-scripts --prefer-dist \
`if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi`
FROM ubuntu:18.04
LABEL maintainer="team@appwrite.io"
ENV TZ=Asia/Tel_Aviv
ENV _APP_ENV production
ENV _APP_HOME https://appwrite.io
ENV _APP_EDITION community
ENV _APP_OPTIONS_ABUSE enabled
ENV _APP_OPENSSL_KEY_V1 your-secret-key
ENV _APP_REDIS_HOST redis
ENV _APP_REDIS_PORT 6379
ENV _APP_DB_HOST mariadb
ENV _APP_DB_PORT 3306
ENV _APP_DB_USER root
ENV _APP_DB_PASS password
ENV _APP_DB_SCHEMA appwrite
ENV _APP_INFLUXDB_HOST influxdb
ENV _APP_INFLUXDB_PORT 8086
ENV _APP_STATSD_HOST telegraf
ENV _APP_STATSD_PORT 8125
ENV _APP_SMTP_HOST smtp
ENV _APP_SMTP_PORT 25
ENV TZ=Asia/Tel_Aviv \
DEBIAN_FRONTEND=noninteractive \
PHP_VERSION=7.3 \
_APP_ENV=production \
_APP_HOME=https://appwrite.io \
_APP_EDITION=community \
_APP_OPTIONS_ABUSE=enabled \
_APP_OPENSSL_KEY_V1=your-secret-key \
_APP_REDIS_HOST=redis \
_APP_REDIS_PORT=6379 \
_APP_DB_HOST=mariadb \
_APP_DB_PORT=3306 \
_APP_DB_USER=root \
_APP_DB_PASS=password \
_APP_DB_SCHEMA=appwrite \
_APP_INFLUXDB_HOST=influxdb \
_APP_INFLUXDB_PORT=8086 \
_APP_STATSD_HOST=telegraf \
_APP_STATSD_PORT=8125 \
_APP_SMTP_HOST=smtp \
_APP_SMTP_PORT=25
#ENV _APP_SMTP_SECURE ''
#ENV _APP_SMTP_USERNAME ''
#ENV _APP_SMTP_PASSWORD ''
COPY --from=builder /phpredis-3.1.2/modules/redis.so /usr/lib/php/20180731/
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN \
apt-get update --fix-missing && \
apt-get install -y software-properties-common && \
apt-get update && \
apt-get install -y --no-install-recommends --no-install-suggests wget curl ca-certificates software-properties-common openssl gnupg && \
LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php && \
apt-get update --fix-missing && \
apt-get install -y htop supervisor openssl wget php7.3 php7.3-fpm php7.3-mysqlnd php7.3-curl php7.3-imagick php7.3-mbstring php7.3-dom php7.3-dev webp && \
apt-get update && \
apt-get install -y --no-install-recommends --no-install-suggests htop supervisor php$PHP_VERSION php$PHP_VERSION-fpm \
php$PHP_VERSION-mysqlnd php$PHP_VERSION-curl php$PHP_VERSION-imagick php$PHP_VERSION-mbstring php$PHP_VERSION-dom webp && \
# nginx
echo "deb http://nginx.org/packages/mainline/ubuntu/ wily nginx" >> /etc/apt/sources.list.d/nginx.list && \
echo "deb-src http://nginx.org/packages/mainline/ubuntu/ wily nginx" >> /etc/apt/sources.list.d/nginx.list && \
echo "deb http://nginx.org/packages/mainline/ubuntu/ bionic nginx" >> /etc/apt/sources.list.d/nginx.list && \
wget -q http://nginx.org/keys/nginx_signing.key && \
apt-key add nginx_signing.key && \
apt-get update --fix-missing && \
apt-get install -y nginx && \
apt-get update && \
apt-get install -y --no-install-recommends --no-install-suggests nginx && \
# redis php extension
wget -q https://github.com/phpredis/phpredis/archive/3.1.2.tar.gz && \
tar -xf 3.1.2.tar.gz && \
cd phpredis-3.1.2 && \
phpize7.3 && \
./configure && \
make && make install && \
echo extension=redis.so >> /etc/php/7.3/fpm/conf.d/redis.ini && \
echo extension=redis.so >> /etc/php/7.3/cli/conf.d/redis.ini && \
echo extension=redis.so >> /etc/php/$PHP_VERSION/fpm/conf.d/redis.ini && \
echo extension=redis.so >> /etc/php/$PHP_VERSION/cli/conf.d/redis.ini && \
# composer
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer && \
# cleanup
cd ../ && \
rm -rf phpredis-3.1.2 && \
rm -rf 3.1.2.tar.gz && \
apt-get purge -y --auto-remove php7.3-dev && \
apt-get purge -y --auto-remove software-properties-common && \
apt-get purge -y --auto-remove software-properties-common gnupg curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Set upload limit
RUN echo "upload_max_filesize = 4M" > /etc/php/7.3/fpm/conf.d/appwrite.ini
RUN echo "upload_max_filesize = 4M" > /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini
# nginx conf (with ssl certificates)
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
@ -71,23 +102,24 @@ COPY ./docker/ssl/nginx.key /etc/nginx/ssl/nginx.key
RUN mkdir -p /var/run/php
COPY ./docker/www.conf /etc/php/7.3/fpm/pool.d/www.conf
# add PHP files
COPY ./app /usr/share/nginx/html/app
COPY ./public /usr/share/nginx/html/public
COPY ./src /usr/share/nginx/html/src
COPY --from=builder /usr/local/src/vendor /usr/share/nginx/html/vendor
RUN mkdir -p /storage/uploads && \
mkdir -p /storage/cache && \
chown -Rf www-data.www-data /storage/uploads && chmod -Rf 0755 /storage/uploads && \
chown -Rf www-data.www-data /storage/cache && chmod -Rf 0755 /storage/cache
# supervisord conf
COPY ./docker/supervisord.conf /etc/supervisord.conf
COPY ./docker/entrypoint.sh /entrypoint.sh
RUN chmod 775 /entrypoint.sh
# add PHP files
COPY ./app /usr/share/nginx/html/app
COPY ./public /usr/share/nginx/html/public
COPY ./src /usr/share/nginx/html/src
COPY ./vendor /usr/share/nginx/html/vendor
WORKDIR /storage/uploads
RUN chown -Rf www-data.www-data /storage/uploads && chmod -Rf 0755 /storage/uploads
WORKDIR /storage/cache
RUN chown -Rf www-data.www-data /storage/cache && chmod -Rf 0755 /storage/cache
EXPOSE 80
WORKDIR /usr/share/nginx/html
CMD ["/bin/bash", "/entrypoint.sh"]

View file

@ -17,10 +17,6 @@ echo "Setting Version #"
echo -e "<?php\n\nconst VERSION = '$1';\n\nreturn VERSION;" > app/config/version.php
echo 'Updating PHP dependencies and auto-loading...'
composer update --ignore-platform-reqs --optimize-autoloader --no-dev --no-plugins --no-scripts --prefer-dist
echo 'Starting build...'
docker build -t appwrite/appwrite:"$1" .

View file

@ -8,7 +8,6 @@ services:
- ./app:/usr/share/nginx/html/app
- ./public:/usr/share/nginx/html/public
- ./src:/usr/share/nginx/html/src
- ./vendor:/usr/share/nginx/html/vendor
- ./docker/nginx.conf:/etc/nginx/nginx.conf:rw
- ./storage/uploads:/storage/uploads:rw
- ./storage/cache:/storage/cache:rw

View file

@ -1,5 +1,7 @@
#!/bin/bash
export PHP_VERSION=$PHP_VERSION
chown -Rf www-data.www-data /usr/share/nginx/html/
# Function to update the fpm configuration to make the service environment variables available
@ -10,12 +12,12 @@ function setEnvironmentVariable() {
fi
# Check whether variable already exists
if grep -q $1 /etc/php/7.3/fpm/pool.d/www.conf; then
if grep -q $1 /etc/php/$PHP_VERSION/fpm/pool.d/www.conf; then
# Reset variable
sed -i "s/^env\[$1.*/env[$1] = $2/g" /etc/php/7.3/fpm/pool.d/www.conf
sed -i "s/^env\[$1.*/env[$1] = $2/g" /etc/php/$PHP_VERSION/fpm/pool.d/www.conf
else
# Add variable
echo "env[$1] = $2" >> /etc/php/7.3/fpm/pool.d/www.conf
echo "env[$1] = $2" >> /etc/php/$PHP_VERSION/fpm/pool.d/www.conf
fi
}
@ -26,8 +28,8 @@ for _curVar in `env | grep _APP_ | awk -F = '{print $1}'`;do
setEnvironmentVariable ${_curVar} ${!_curVar}
done
echo newrelic.license = \"$_APP_NEWRELIC_KEY\" > /etc/php/7.3/fpm/conf.d/newrelic.ini
echo newrelic.license = \"$_APP_NEWRELIC_KEY\" > /etc/php/7.3/cli/conf.d/newrelic.ini
echo newrelic.license = \"$_APP_NEWRELIC_KEY\" > /etc/php/$PHP_VERSION/fpm/conf.d/newrelic.ini
echo newrelic.license = \"$_APP_NEWRELIC_KEY\" > /etc/php/$PHP_VERSION/cli/conf.d/newrelic.ini
# Start supervisord and services
/usr/bin/supervisord -n -c /etc/supervisord.conf
/usr/bin/supervisord -n -c /etc/supervisord.conf

View file

@ -2,8 +2,9 @@
file=/tmp/supervisor.sock ; (the path to the socket file)
[supervisord]
; logfile=/tmp/supervisord.log ; (main log file;default.conf $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default.conf 50MB)
;logfile=/tmp/supervisord.log ; (main log file;default.conf $CWD/supervisord.log)
logfile=/dev/null
logfile_maxbytes=0 ; (max main logfile bytes b4 rotation;default.conf 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default.conf 10)
loglevel=info ; (log level;default.conf info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default.conf supervisord.pid)
@ -22,28 +23,28 @@ supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
[program:php7-fpm]
command=php-fpm7.3 -F
command=php-fpm%(ENV_PHP_VERSION)s -F
autostart=true
autorestart=true
priority=5
stdout_events_enabled=true
stderr_events_enabled=true
startretries=10
#stdout_logfile=/dev/stdout
#stdout_logfile_maxbytes=0
;stdout_logfile=/dev/stdout
;stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes = 0
[program:nginx]
command=service nginx start
command=nginx
autostart=true
autorestart=true
priority=10
stdout_events_enabled=true
stderr_events_enabled=true
startretries=10
#stdout_logfile=/dev/stdout
#stdout_logfile_maxbytes=0
;stdout_logfile=/dev/stdout
;stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes = 0
@ -57,8 +58,8 @@ stdout_events_enabled=true
stderr_events_enabled=true
stopsignal=QUIT
startretries=10
#stdout_logfile=/dev/stdout
#stdout_logfile_maxbytes=0
;stdout_logfile=/dev/stdout
;stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes = 0
@ -72,8 +73,8 @@ stdout_events_enabled=true
stderr_events_enabled=true
stopsignal=QUIT
startretries=10
#stdout_logfile=/dev/stdout
#stdout_logfile_maxbytes=0
;stdout_logfile=/dev/stdout
;stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes = 0
@ -87,8 +88,8 @@ stdout_events_enabled=true
stderr_events_enabled=true
stopsignal=QUIT
startretries=10
#stdout_logfile=/dev/stdout
#stdout_logfile_maxbytes=0
;stdout_logfile=/dev/stdout
;stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes = 0
@ -102,8 +103,8 @@ stdout_events_enabled=true
stderr_events_enabled=true
stopsignal=QUIT
startretries=10
#stdout_logfile=/dev/stdout
#stdout_logfile_maxbytes=0
;stdout_logfile=/dev/stdout
;stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes = 0
@ -117,7 +118,7 @@ stdout_events_enabled=true
stderr_events_enabled=true
stopsignal=QUIT
startretries=10
#stdout_logfile=/dev/stdout
#stdout_logfile_maxbytes=0
;stdout_logfile=/dev/stdout
;stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes = 0
stderr_logfile_maxbytes = 0

View file

@ -2,13 +2,17 @@ version: '3'
services:
appwrite:
build: ../../
build:
context: ../../
args:
- TESTING=true
restart: unless-stopped
volumes:
- ./../../phpunit.xml:/usr/share/nginx/html/phpunit.xml
- ./../../tests:/usr/share/nginx/html/tests
- ./../../app:/usr/share/nginx/html/app
- ./../../public:/usr/share/nginx/html/public
- ./../../src:/usr/share/nginx/html/src
- ./../../vendor:/usr/share/nginx/html/vendor
- ./../../docker/nginx.conf:/etc/nginx/nginx.conf:rw
- ./../../storage/uploads:/storage/uploads:rw
- ./../../storage/cache:/storage/cache:rw
@ -78,4 +82,4 @@ services:
telegraf:
image: appwrite/telegraf:1.0.0
ports:
- "8125:8125/udp"
- "8125:8125/udp"