Skip to content

Commit dfbd2ef

Browse files
Merge pull request #8 from uasoft-indonesia/task/docker-file-config
Docker file config
2 parents b18ed38 + 5cae5a7 commit dfbd2ef

File tree

9 files changed

+328
-2
lines changed

9 files changed

+328
-2
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ yarn-error.log
1414
/.vscode
1515
storage/api-docs
1616

17-
# JS third party & generated
17+
/badaso
18+
19+
# JS third party & generated
1820
/node_modules
1921
/public/js/*
2022

@@ -24,4 +26,4 @@ storage/api-docs
2426
# Package manager history (you can delete it for your own project)
2527
yarn.lock
2628
package-lock.json
27-
composer.lock
29+
composer.lock

Dockerfile

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# reference from https://github.com/jabardigitalservice/docker-phpfpm-nginx
2+
FROM alpine:latest
3+
4+
ADD https://packages.whatwedo.ch/php-alpine.rsa.pub /etc/apk/keys/php-alpine.rsa.pub
5+
RUN apk --update-cache add ca-certificates
6+
7+
# Install packages
8+
RUN apk --no-cache add php8 php8-fpm php8-opcache php8-openssl php8-curl \
9+
nginx supervisor curl php8-json php8-phar php8-iconv \
10+
php8-exif php8-sodium php8-pdo php8-mbstring php8-dom \
11+
php8-zip php8-mysqli php8-sqlite3 php8-session php8-bcmath \
12+
php8-common php8-gd php8-intl php8-fileinfo php8-pdo_mysql \
13+
php8-tokenizer php8-xml php8-xmlwriter php8-simplexml \
14+
php8-ctype php8-xmlreader nodejs npm
15+
16+
RUN ln -s /usr/bin/php8 /usr/bin/php
17+
18+
# install composer
19+
RUN curl -s https://getcomposer.org/installer | php
20+
RUN mv composer.phar /usr/local/bin/composer
21+
22+
# Configure nginx
23+
COPY docker/config/nginx.conf /etc/nginx/nginx.conf
24+
25+
# Configure PHP
26+
RUN mkdir -p /run/php/
27+
RUN touch /run/php/php8.0-fpm.pid
28+
29+
# Configure PHP-FPM
30+
COPY docker/config/fpm-pool.conf /etc/php8/php-fpm.d/www.conf
31+
COPY docker/config/php.ini /etc/php8/conf.d/custom.ini
32+
33+
# Configure supervisord
34+
COPY docker/config/supervisord.conf /etc/supervisord.conf
35+
36+
# Setup document root
37+
RUN mkdir -p /var/www/badaso
38+
39+
# Add application
40+
WORKDIR /var/www/badaso
41+
COPY --chown=nobody . /var/www/badaso/
42+
# COPY .env.example .env
43+
44+
RUN composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
45+
46+
RUN chmod -R 755 /var/www/badaso/storage
47+
RUN chmod -R 755 /var/www/badaso/public
48+
49+
RUN composer dump-autoload
50+
51+
RUN php artisan key:generate
52+
RUN php artisan config:clear
53+
RUN php artisan cache:clear
54+
RUN php artisan view:clear
55+
RUN php artisan route:clear
56+
RUN php artisan stroage:link
57+
RUN php artisan badaso:setup
58+
59+
RUN npm install -g yarn
60+
RUN yarn && yarn prod
61+
62+
RUN chown -R nobody.nobody /var/www/badaso && \
63+
chown -R nobody.nobody /run && \
64+
chown -R nobody.nobody /var/lib/nginx && \
65+
chown -R nobody.nobody /var/log/nginx
66+
67+
# Switch to use a non-root user from here on
68+
USER nobody
69+
# USER root
70+
71+
# Expose the port nginx is reachable on
72+
EXPOSE 8080
73+
EXPOSE 443
74+
75+
# Let supervisord start nginx & php-fpm
76+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
77+
78+
# Configure a healthcheck to validate that everything is up&running
79+
HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:8080/fpm-ping

docker-compose.prod.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
version: "3.7"
2+
3+
services:
4+
db:
5+
container_name: badaso-db
6+
image: mysql:8.0
7+
command:
8+
[
9+
"--character-set-server=utf8mb4",
10+
"--collation-server=utf8mb4_unicode_ci",
11+
"--default-authentication-plugin=mysql_native_password",
12+
]
13+
restart: always
14+
volumes:
15+
- ./badaso/:/var/lib/mysql
16+
environment:
17+
MYSQL_DATABASE: badaso
18+
MYSQL_USER: sail
19+
MYSQL_PASSWORD: password
20+
MYSQL_ROOT_HOST: "%"
21+
MYSQL_ROOT_PASSWORD: password
22+
ports:
23+
- 3300:3306
24+
web:
25+
container_name: badaso-app
26+
build:
27+
context: .
28+
dockerfile: Dockerfile
29+
volumes:
30+
- /var/log/docker-data/badaso:/app/storage/logs
31+
environment:
32+
- DB_CONNECTION=mysql
33+
- DB_HOST=db
34+
- DB_PORT=3306
35+
- DB_DATABASE=badaso
36+
- DB_USERNAME=sail
37+
- DB_PASSWORD=password
38+
depends_on:
39+
- db
40+
ports:
41+
- 8080:8080
42+
# if your not use phpmyadmin in prodution comment this
43+
phpmyadmin:
44+
container_name: badaso-phpmyadmin
45+
image: phpmyadmin/phpmyadmin:4.7
46+
environment:
47+
PMA_HOST: db
48+
depends_on:
49+
- db
50+
ports:
51+
- 8081:80

docker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This folder contain docker environtment config

docker/config/fpm-pool.conf

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[global]
2+
; Log to stderr
3+
error_log = /dev/stderr
4+
5+
[www]
6+
; The address on which to accept FastCGI requests.
7+
; Valid syntaxes are:
8+
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
9+
; a specific port;
10+
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
11+
; a specific port;
12+
; 'port' - to listen on a TCP socket to all addresses
13+
; (IPv6 and IPv4-mapped) on a specific port;
14+
; '/path/to/unix/socket' - to listen on a unix socket.
15+
; Note: This value is mandatory.
16+
listen = /run/php-fpm.sock
17+
18+
; Enable status page
19+
pm.status_path = /fpm-status
20+
21+
; Ondemand process manager
22+
pm = static
23+
24+
; The number of child processes to be created when pm is set to 'static' and the
25+
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
26+
; This value sets the limit on the number of simultaneous requests that will be
27+
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
28+
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
29+
; CGI. The below defaults are based on a server without much resources. Don't
30+
; forget to tweak pm.* to fit your needs.
31+
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
32+
; Note: This value is mandatory.
33+
pm.max_children = 100
34+
35+
; The number of seconds after which an idle process will be killed.
36+
; Note: Used only when pm is set to 'ondemand'
37+
; Default Value: 10s
38+
pm.process_idle_timeout = 10s;
39+
40+
; The number of requests each child process should execute before respawning.
41+
; This can be useful to work around memory leaks in 3rd party libraries. For
42+
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
43+
; Default Value: 0
44+
pm.max_requests = 1000
45+
46+
; Make sure the FPM workers can reach the environment variables for configuration
47+
clear_env = no
48+
49+
; Catch output from PHP
50+
catch_workers_output = yes
51+
52+
; Remove the 'child 10 said into stderr' prefix in the log and only show the actual message
53+
decorate_workers_output = no
54+
55+
; Enable ping page to use in healthcheck
56+
ping.path = /fpm-ping

docker/config/nginx.conf

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
worker_processes 1;
2+
error_log stderr warn;
3+
pid /run/nginx.pid;
4+
5+
events {
6+
worker_connections 1024;
7+
}
8+
9+
http {
10+
include mime.types;
11+
default_type application/octet-stream;
12+
13+
# Define custom log format to include reponse times
14+
log_format main_timed '$remote_addr - $remote_user [$time_local] "$request" '
15+
'$status $body_bytes_sent "$http_referer" '
16+
'"$http_user_agent" "$http_x_forwarded_for" '
17+
'$request_time $upstream_response_time $pipe $upstream_cache_status';
18+
19+
access_log /dev/stdout main_timed;
20+
error_log /dev/stderr notice;
21+
22+
keepalive_timeout 65;
23+
24+
server_tokens off;
25+
26+
# set client body size to 8M #
27+
client_max_body_size 8M;
28+
29+
# Write temporary files to /tmp so they can be created as a non-privileged user
30+
client_body_temp_path /tmp/client_temp;
31+
proxy_temp_path /tmp/proxy_temp_path;
32+
fastcgi_temp_path /tmp/fastcgi_temp;
33+
uwsgi_temp_path /tmp/uwsgi_temp;
34+
scgi_temp_path /tmp/scgi_temp;
35+
36+
# Default server definition
37+
server {
38+
listen [::]:8080 default_server;
39+
listen 8080 default_server;
40+
server_name _;
41+
42+
sendfile off;
43+
44+
root /var/www/badaso/public;
45+
index index.php index.html;
46+
47+
location / {
48+
# First attempt to serve request as file, then
49+
# as directory, then fall back to index.php
50+
try_files $uri $uri/ /index.php?$query_string;
51+
}
52+
53+
# Redirect server error pages to the static page /50x.html
54+
error_page 500 502 503 504 /50x.html;
55+
location = /50x.html {
56+
root /var/lib/nginx/html;
57+
}
58+
59+
# Pass the PHP scripts to PHP-FPM listening on 127.0.0.1:9000
60+
location ~ \.php$ {
61+
try_files $uri =404;
62+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
63+
fastcgi_pass unix:/run/php-fpm.sock;
64+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
65+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
66+
fastcgi_index index.php;
67+
include fastcgi_params;
68+
}
69+
70+
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
71+
expires 5d;
72+
}
73+
74+
# Deny access to . files, for security
75+
location ~ /\. {
76+
log_not_found off;
77+
deny all;
78+
}
79+
80+
# Allow fpm ping and status from localhost
81+
location ~ ^/(fpm-status|fpm-ping)$ {
82+
access_log off;
83+
allow 127.0.0.1;
84+
deny all;
85+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
86+
include fastcgi_params;
87+
fastcgi_pass unix:/run/php-fpm.sock;
88+
}
89+
}
90+
91+
gzip on;
92+
gzip_proxied any;
93+
gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;
94+
gzip_vary on;
95+
gzip_disable "msie6";
96+
97+
# Include other server configs
98+
include /etc/nginx/conf.d/*.conf;
99+
}

docker/config/php.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
expose_php = Off
2+
3+
[Date]
4+
date.timezone = "Asia/Jakarta"
5+
6+
[www]
7+
user = nobody
8+
group = nobody
9+
10+
memory_limit = -1
11+
; Maximum size of POST data that PHP will accept.
12+
post_max_size = 0
13+
; Maximum allowed size for uploaded files.
14+
upload_max_filesize = 5M
15+
max_input_vars = 10000

docker/config/supervisord.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[supervisord]
2+
nodaemon=true
3+
logfile=/dev/null
4+
logfile_maxbytes=0
5+
pidfile=/run/supervisord.pid
6+
7+
[program:php-fpm]
8+
command=php-fpm8 -F
9+
stdout_logfile=/dev/stdout
10+
stdout_logfile_maxbytes=0
11+
stderr_logfile=/dev/stderr
12+
stderr_logfile_maxbytes=0
13+
autorestart=false
14+
startretries=0
15+
16+
[program:nginx]
17+
command=nginx -g 'daemon off;'
18+
stdout_logfile=/dev/stdout
19+
stdout_logfile_maxbytes=0
20+
stderr_logfile=/dev/stderr
21+
stderr_logfile_maxbytes=0
22+
autorestart=false
23+
startretries=0

0 commit comments

Comments
 (0)