Skip to content

Commit

Permalink
feat: enable local docker composer prod deployement
Browse files Browse the repository at this point in the history
CS76 committed Sep 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent a35eac3 commit edb928b
Showing 7 changed files with 258 additions and 0 deletions.
104 changes: 104 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
services:
app:
build:
context: .
dockerfile: ./resources/dc-ops/production/Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: coconut-8.3/app
container_name: coconut_app
networks:
- coconut
depends_on:
- pgsql
- redis
# - typesense
volumes:
- www-data:/var/www
pgsql:
image: "informaticsmatters/rdkit-cartridge-debian:latest"
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
environment:
PGPASSWORD: '${DB_PASSWORD:-secret}'
POSTGRES_DB: '${DB_DATABASE}'
POSTGRES_USER: '${DB_USERNAME}'
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
volumes:
- 'coconut-pgsql:/var/lib/postgresql/data'
- './docker/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql'
networks:
- coconut
healthcheck:
test:
- CMD
- pg_isready
- '-q'
- '-d'
- '${DB_DATABASE}'
- '-U'
- '${DB_USERNAME}'
retries: 3
timeout: 5s
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'coconut-redis:/data'
networks:
- coconut
healthcheck:
test:
- CMD
- redis-cli
- ping
retries: 3
timeout: 5s
nginx:
build:
context: .
dockerfile: ./resources/ops/nginx/Dockerfile
container_name: coconut_nginx
restart: unless-stopped
ports:
- 80:80
networks:
- coconut
depends_on:
- app
volumes:
- www-data:/var/www
# typesense:
# image: 'typesense/typesense:0.25.2'
# ports:
# - '${FORWARD_TYPESENSE_PORT:-8108}:8108'
# environment:
# TYPESENSE_DATA_DIR: '${TYPESENSE_DATA_DIR:-/typesense-data}'
# TYPESENSE_API_KEY: '${TYPESENSE_API_KEY:-xyz}'
# TYPESENSE_ENABLE_CORS: '${TYPESENSE_ENABLE_CORS:-true}'
# volumes:
# - 'coconut-typesense:/typesense-data'
# networks:
# - coconut
# healthcheck:
# test:
# - CMD
# - wget
# - '--no-verbose'
# - '--spider'
# - 'http://localhost:8108/health'
# retries: 5
# timeout: 7s
networks:
coconut:
driver: bridge
volumes:
coconut-pgsql:
driver: local
coconut-redis:
driver: local
www-data:
driver: local
# coconut-typesense:
# driver: local
12 changes: 12 additions & 0 deletions resources/dc-ops/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM nginx:alpine

# Remove default configuration file
RUN rm /etc/nginx/conf.d/default.conf

# Copy custom configuration file from the current directory
COPY ./resources/ops/nginx/default.conf /etc/nginx/conf.d

# Expose port 80
EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
20 changes: 20 additions & 0 deletions resources/dc-ops/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
82 changes: 82 additions & 0 deletions resources/dc-ops/production/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
FROM php:8.3-fpm

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

# Set working directory
WORKDIR /var/www

ARG POSTGRES_VERSION=15

# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
libonig-dev \
libzip-dev \
libicu-dev \
libgd-dev \
libpq-dev

RUN apt-get install -y postgresql-client-$POSTGRES_VERSION

# Install imagick
RUN apt-get update && apt-get install -y --no-install-recommends \
libmagickwand-dev && \
git clone https://github.com/Imagick/imagick.git --depth 1 /tmp/imagick && \
cd /tmp/imagick && \
phpize && \
./configure && \
make && \
make install && \
docker-php-ext-enable imagick && \
apt-get purge -y --auto-remove git && \
rm -rf /var/lib/apt/lists/* /tmp/imagick

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-configure pgsql --with-pgsql=/usr/include/postgresql/
RUN docker-php-ext-install pdo pdo_mysql pdo_pgsql pgsql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-external-gd
RUN docker-php-ext-install gd
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl

RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy existing application directory contents
COPY . /var/www

RUN composer install --optimize-autoloader --no-scripts --prefer-dist
RUN npm ci
RUN npm run build

# Copy existing application directory permissions
COPY --chown=www:www . /var/www

# Change current user to www
USER www

# Expose port 9000 and start php-fpm server
EXPOSE 9000

CMD ["php-fpm"]
5 changes: 5 additions & 0 deletions resources/dc-ops/production/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[PHP]
post_max_size = 100M
upload_max_filesize = 100M
variables_order = EGPCS
pcov.directory = .
26 changes: 26 additions & 0 deletions resources/dc-ops/production/start-container
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then
echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'."
exit 1
fi

if [ ! -z "$WWWUSER" ]; then
usermod -u $WWWUSER sail
fi

if [ ! -d /.composer ]; then
mkdir /.composer
fi

chmod -R ugo+rw /.composer

if [ $# -gt 0 ]; then
if [ "$SUPERVISOR_PHP_USER" = "root" ]; then
exec "$@"
else
exec gosu $WWWUSER "$@"
fi
else
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi
9 changes: 9 additions & 0 deletions resources/dc-ops/production/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[supervisord]
nodaemon=true

# [program:php-fpm]
# command=/usr/sbin/php-fpm8.3 -F
# autostart=true
# autorestart=true
# stderr_logfile=/var/log/supervisor/php-fpm.err.log
# stdout_logfile=/var/log/supervisor/php-fpm.out.log

0 comments on commit edb928b

Please sign in to comment.