Skip to content

Commit 41bba80

Browse files
committed
Add prod and dev modes
1 parent 79c2ad2 commit 41bba80

9 files changed

+169
-63
lines changed

.env

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ MARIADB_ROOT_PASSWORD=example
22
MARIADB_DATABASE=yetiforce
33
MARIADB_USER=yeti
44
MARIADB_PASSWORD=yeti
5+
HOSTNAME=yeti
6+
TLS_EMAIL=internal

README.md

+48-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
1-
# docker
1+
# YetiForceCRM Docker
2+
23
Official YetiForce Docker image
4+
5+
## Instructions
6+
7+
### Production
8+
9+
To start YetiForce in a production configuration:
10+
1. In the `.env` file set the `HOSTNAME` to the where you will be running YetiForce and set `TLS_EMAIL` to your email address. Those settings will make sure that your website has a proper TLS certificate.
11+
2. Download the YetiForce code: `git submodule update --init`.
12+
3. Run `docker compose up -d`.
13+
4. Go to `https://HOSTNAME` and go through the installation process. For your database settings, enter:
14+
- Address: db
15+
- Port: 3306
16+
- Username: yeti
17+
- Password: yeti
18+
- Database name: yetiforce
19+
20+
### Development
21+
22+
This image can also work in development mode. This mode is designed for actively making changes in YF itself. As such, it includes the following changes:
23+
- YetiForce is run from the `./YetiForceCRM` directory
24+
- MariaDB is available on `localhost:3306`
25+
- PHP has a development configuration
26+
27+
This means that you will be able to make changes in `./YetiForceCRM`, see them reflected in your browser, and commit them normally.
28+
29+
To run in this mode:
30+
1. Add a line with `127.0.0.1 yeti` to `/etc/hosts` on Unix or `C:\Windows\System32\drivers\etc\hosts` on Windows.
31+
2. Download the YetiForce code: `git submodule update --init`.
32+
3. Install YetiForce dependencies:
33+
```shell
34+
cd ./YetiForceCRM
35+
install -m755 -d YetiForceCRM/config/Modules
36+
yarn install --modules-folder "./public_html/libraries" --ignore-optional --production=true
37+
cd public_html/src
38+
yarn install --ignore-optional --production=true
39+
cd ../..
40+
composer --no-interaction install --no-dev
41+
cd ..
42+
```
43+
4. Start the server with `docker compose -f docker-compose.yaml -f docker-compose.dev.yaml up -d`
44+
4. Go to `https://HOSTNAME` and go through the installation process. For your database settings, enter:
45+
- Address: db
46+
- Port: 3306
47+
- Username: yeti
48+
- Password: yeti
49+
- Database name: yetiforce

caddy/Caddyfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
auto_https disable_redirects
3+
}
4+
5+
{$HOSTNAME}:443 {
6+
tls {$TLS_EMAIL}
7+
reverse_proxy nginx:80
8+
}
9+
10+
{$HOSTNAME}:80 {
11+
reverse_proxy nginx:80
12+
}

docker-compose.dev.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: yetiforce-dev
2+
version: '3'
3+
services:
4+
db:
5+
ports:
6+
- 3306:3306
7+
php:
8+
build:
9+
target: php-dev
10+
volumes:
11+
- type: bind
12+
source: ./YetiForceCRM
13+
target: /var/www/html
14+
15+
volumes:
16+
crm_data: null

docker-compose.yaml

+38-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,53 @@
1+
name: yetiforce
12
version: '3'
23
services:
4+
caddy:
5+
hostname: ${HOSTNAME}
6+
image: caddy:2.6
7+
depends_on:
8+
- nginx
9+
env_file:
10+
- .env
11+
restart: on-failure
12+
ports:
13+
- "80:80"
14+
- "443:443"
15+
- "443:443/udp"
16+
volumes:
17+
- ./caddy/Caddyfile:/etc/caddy/Caddyfile
18+
- caddy_data:/data
19+
- caddy_config:/config
320
db:
421
build:
522
context: .
623
dockerfile: ./mariadb/Dockerfile
724
env_file:
825
- .env
26+
restart: on-failure
927
volumes:
1028
- type: volume
1129
source: db_data
1230
target: /var/lib/mysql
13-
ports:
14-
- 3306:3306
15-
nginx:
16-
hostname: yeti
31+
php:
1732
build:
1833
context: .
1934
dockerfile: ./php/Dockerfile
20-
target: nginx
35+
target: php-prod
36+
restart: on-failure
2137
volumes:
2238
- type: volume
2339
source: crm_data
2440
target: /var/www/html
25-
ports:
26-
- 80:80
41+
nginx:
42+
build:
43+
context: .
44+
dockerfile: ./nginx/Dockerfile
45+
target: nginx
46+
depends_on:
47+
- php
48+
restart: on-failure
49+
volumes_from:
50+
- php:rw
2751
cron:
2852
build:
2953
context: ./cron
@@ -32,14 +56,12 @@ services:
3256
condition: on-failure
3357
delay: 60s
3458
volumes_from:
35-
- nginx:ro
36-
php:
37-
build:
38-
context: .
39-
dockerfile: ./php/Dockerfile
40-
target: php-prod
41-
volumes_from:
42-
- nginx:rw
59+
- php:ro
60+
depends_on:
61+
- nginx
62+
4363
volumes:
4464
crm_data:
45-
db_data:
65+
db_data:
66+
caddy_data:
67+
caddy_config:

nginx/Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM nginx:stable AS nginx
2+
3+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
4+
5+
RUN apt-get update && \
6+
apt-get install --no-install-recommends -y \
7+
nginx-extras \
8+
&& apt-get clean \
9+
&& rm -rf /etc/nginx/conf.d/* /etc/nginx/sites-enabled/* /var/lib/apt/lists/*
10+
11+
COPY ./YetiForceCRM/tests/setup/nginx/yetiforce.conf /etc/nginx/yetiforce.conf
12+
COPY ./nginx/docker.conf /etc/nginx/conf.d/default.conf

php/Dockerfile

+31-45
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,30 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
1212
libpng-dev \
1313
libxml2-dev \
1414
libzip-dev \
15+
unixodbc-dev \
1516
zlib1g-dev \
1617
&& docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
1718
&& docker-php-ext-install -j8 imap pdo_mysql curl gd xml zip soap iconv intl bcmath sockets exif ldap opcache \
18-
&& apt-get clean
19+
&& apt-get clean \
20+
&& printf "\n" | pecl install imagick \
21+
&& docker-php-ext-enable imagick \
22+
&& printf "\n" | pecl install apcu \
23+
&& docker-php-ext-enable apcu \
24+
&& pecl install pdo_sqlsrv \
25+
&& docker-php-ext-enable pdo_sqlsrv \
26+
&& pecl cache-clear \
27+
&& rm -rf /tmp/pear
1928

20-
WORKDIR /opt
29+
FROM node:18-alpine AS build-yarn
2130

22-
# docker-php-ext-* does not work with the imagick extension; it must be compiled manually
23-
RUN curl -sL https://github.com/Imagick/imagick/archive/refs/tags/3.7.0.tar.gz -o imagick.tar.gz \
24-
&& tar -xzf imagick.tar.gz \
25-
&& cd imagick-3.7.0 \
26-
&& phpize \
27-
&& ./configure \
28-
&& make \
29-
&& make install \
30-
&& docker-php-ext-enable imagick \
31-
&& cd .. \
32-
&& rm -rf imagick.tar.gz imagick-3.7.0
31+
RUN apk add --no-cache git
3332

34-
FROM php-base AS php-prod
33+
COPY ./YetiForceCRM /opt/YetiForceCRM
34+
WORKDIR /opt/YetiForceCRM
35+
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn rm .git && yarn install --modules-folder "./public_html/libraries" --ignore-optional --production=true
36+
WORKDIR /opt/YetiForceCRM/public_html/src
37+
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --ignore-optional --production=true
3538

36-
RUN cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
37-
COPY ./YetiForceCRM/tests/setup/php/prod.ini /usr/local/etc/php/conf.d
38-
COPY ./php/docker-config.ini /usr/local/etc/php/conf.d
3939

4040
FROM php-base AS build-composer
4141

@@ -45,38 +45,24 @@ RUN php -r "copy('https://raw.githubusercontent.com/composer/getcomposer.org/705
4545
&& php -r "unlink('composer-setup.php');" \
4646
&& mv composer.phar /usr/local/bin/composer
4747

48-
COPY ./YetiForceCRM /opt/YetiForceCRM
48+
COPY --from=build-yarn /opt/YetiForceCRM /opt/YetiForceCRM
4949
WORKDIR /opt/YetiForceCRM
5050
RUN --mount=type=cache,target=/root/.composer/cache composer --no-interaction install --no-dev
5151

52-
FROM node:18-alpine AS build-yarn
53-
54-
RUN apk add --no-cache git
55-
56-
COPY --from=build-composer /opt/YetiForceCRM /opt/YetiForceCRM
57-
WORKDIR /opt/YetiForceCRM
58-
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn rm .git && yarn install --modules-folder "./public_html/libraries" --ignore-optional --production=true
59-
WORKDIR /opt/YetiForceCRM/public_html/src
60-
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --ignore-optional --production=true
61-
62-
FROM scratch AS app-data
63-
64-
COPY --from=build-yarn /opt/YetiForceCRM /var/www/html
65-
66-
FROM nginx:stable AS nginx
52+
FROM php-base AS php-prod
6753

68-
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
54+
RUN cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
55+
COPY ./YetiForceCRM/tests/setup/php/prod.ini /usr/local/etc/php/conf.d
56+
COPY ./php/docker-config.ini /usr/local/etc/php/conf.d
57+
COPY ./php/fpm.conf /usr/local/etc/php-fpm.d/zzz-docker.conf
6958

70-
RUN apt-get update && \
71-
apt-get install --no-install-recommends -y \
72-
nginx-extras \
73-
&& apt-get clean \
74-
&& rm -rf /etc/nginx/conf.d/* /etc/nginx/sites-enabled/* /var/lib/apt/lists/*
59+
WORKDIR /var/www/html
60+
COPY --from=build-composer --chown=www-data:www-data --chmod=644 /opt/YetiForceCRM/ /var/www/html
61+
RUN install -owww-data -gwww-data -m755 -d config/Modules && find . -type d -exec chown www-data:www-data -- {} \+ && find . -type d -exec chmod 755 -- {} \+
7562

76-
COPY ./YetiForceCRM/tests/setup/nginx/yetiforce.conf /etc/nginx/yetiforce.conf
77-
COPY ./nginx/docker.conf /etc/nginx/conf.d/default.conf
63+
FROM php-base AS php-dev
7864

79-
WORKDIR /var/www/html
80-
# fixme - 666 and 777 are not secure
81-
COPY --from=build-yarn --chown=www-data:www-data --chmod=666 /opt/YetiForceCRM/ /var/www/html
82-
RUN install -owww-data -gwww-data -m777 -d config/Modules && find . -type d -exec chown www-data:www-data -- {} \+ && find . -type d -exec chmod 755 -- {} \+
65+
RUN cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
66+
COPY ./YetiForceCRM/tests/setup/php/dev.ini /usr/local/etc/php/conf.d
67+
COPY ./php/docker-config.ini /usr/local/etc/php/conf.d
68+
COPY ./php/fpm.conf /usr/local/etc/php-fpm.d/zzz-docker.conf

php/docker-config.ini

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
open_basedir="/var/www/html"
21
session.cookie_samesite="Strict"

php/fpm.conf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[www]
2+
3+
env[PROVIDER] = docker
4+
php_admin_value[error_log] = /var/log/php/fpm_yfprod_error.log
5+
php_admin_value[open_basedir] = /var/www/html/:/tmp/:/var/tmp/:/etc/nginx/ssl/:/etc/ssl/:/usr/bin/gpg:/usr/bin/gpg-agent:/usr/bin/gpgconf
6+
clear_env = no
7+
request_terminate_timeout = 600
8+
pm.process_idle_timeout = 600s;
9+
pm.max_requests = 5000
10+
catch_workers_output = yes

0 commit comments

Comments
 (0)