Skip to content

Commit

Permalink
refactor dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Jahrulnr committed May 25, 2024
1 parent 0088d5b commit e427f3b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 92 deletions.
32 changes: 5 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,11 @@ ENV PS1="\[\e]0;\u@\h: \w\a\]${whoami}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01

ENV PATH="/opt/venv/bin:/app:/app/vendor/bin:$PATH"
ENV TZ="Asia/Jakarta"
RUN echo "apps:x:0:0:root:/root:/bin/bash" >> /etc/passwd && \
echo "alias ll='ls -l'" >> /root/.bashrc \
&& apk update && apk add --no-cache curl bash bash-completion shadow tzdata \
&& apk add --no-cache docker \
&& apk add --no-cache nginx nginx-mod-stream \
&& apk add --no-cache git python3 \
&& python3 -m venv /opt/venv \
&& mkdir -p /run/php \
&& pip install wheel \
&& pip install supervisor \
&& pip install git+https://github.com/coderanger/supervisor-stdout \
&& apk add --no-cache php82 php82-fpm php82-cli php82-phar php82-iconv php82-mbstring \
php82-gd php82-xml php82-zip php82-curl php82-opcache \
php82-fileinfo php82-session php82-dom php82-tokenizer php82-exif \
php82-xmlreader php82-simplexml php82-xmlwriter \
php82-sqlite3 php82-pdo_sqlite php82-openssl php82-redis php82-mysqli php82-pdo_mysql \
&& ln -s /usr/sbin/php-fpm82 /usr/sbin/php-fpm \
\
&& groupmod -og 1000 nginx \
&& usermod -ou 1000 -g 1000 nginx \
\
&& apk add certbot certbot-nginx --no-cache \
\
&& apk del shadow git \
&& curl -o /tmp/composer-setup.php https://getcomposer.org/installer \
&& php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer \
&& rm -rf /tmp/* /var/cache/apk/* ~/.cache
COPY infra/apk.sh /tmp/apk.sh
RUN \
chmod +x /tmp/apk.sh && sh /tmp/apk.sh && rm -rf /tmp/apk.sh && \
curl -o /tmp/composer-setup.php https://getcomposer.org/installer && \
php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer

COPY ./infra/cron.txt /tmp/
RUN cat /tmp/cron.txt >> /etc/crontabs/root && rm /tmp/cron.txt
Expand Down
61 changes: 6 additions & 55 deletions Dockerfile-prod
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,13 @@ FROM alpine:3.19

ENV PS1="\[\e]0;\u@\h: \w\a\]${whoami}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "

ENV PATH="/opt/venv/bin:/app:$PATH"
ENV PATH="/opt/venv/bin:/app:/app/vendor/bin:$PATH"
ENV TZ="Asia/Jakarta"
RUN echo "apps:x:0:0:root:/root:/bin/bash" >> /etc/passwd && \
echo "alias ll='ls -l'" >> /root/.bashrc \
&& apk update && apk add --no-cache curl=8.5.0-r0 \
shadow=4.14.2-r0 \
bash=5.2.21-r0 \
bash-completion=2.11-r6 \
tzdata=2024a-r0 \
nginx=1.24.0-r15 \
nginx-mod-stream=1.24.0-r15 \
docker=25.0.3-r1 \
python3=3.11.8-r0 \
git=2.43.0-r0 \
php82=8.2.16-r0 \
php82-phar=8.2.16-r0 \
php82-fpm=8.2.16-r0 \
php82-iconv=8.2.16-r0 \
php82-mbstring=8.2.16-r0 \
php82-gd=8.2.16-r0 \
php82-xml=8.2.16-r0 \
php82-zip=8.2.16-r0 \
php82-curl=8.2.16-r0 \
php82-opcache=8.2.16-r0 \
php82-fileinfo=8.2.16-r0 \
php82-session=8.2.16-r0 \
php82-dom=8.2.16-r0 \
php82-tokenizer=8.2.16-r0 \
php82-exif=8.2.16-r0 \
php82-xmlreader=8.2.16-r0 \
php82-simplexml=8.2.16-r0 \
php82-xmlwriter=8.2.16-r0 \
php82-sqlite3=8.2.16-r0 \
php82-pdo_sqlite=8.2.16-r0 \
php82-openssl=8.2.16-r0 \
php82-pecl-redis=6.0.2-r0 \
php82-mysqli=8.2.16-r0 \
php82-pdo_mysql=8.2.16-r0 \
certbot=2.7.4-r0 \
certbot-nginx=2.7.4-r0 \
&& python3 -m venv /opt/venv \
&& mkdir -p /run/php \
# bypass hadolint
&& echo "wheel==0.42.0" >> /tmp/pip.txt \
&& echo "supervisor==4.2.5" >> /tmp/pip.txt \
&& echo "git+https://github.com/coderanger/supervisor-stdout" >> /tmp/pip.txt \
&& pip install --no-cache-dir -r /tmp/pip.txt \
&& ln -s /usr/sbin/php-fpm82 /usr/sbin/php-fpm \
\
&& groupmod -og 1000 nginx \
&& usermod -ou 1000 -g 1000 nginx \
\
&& apk del shadow git \
&& curl -o /tmp/composer-setup.php https://getcomposer.org/installer \
&& php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer \
&& rm -rf /tmp/* /var/cache/apk/* /lib/apk/* ~/.cache
COPY infra/apk.sh /tmp/apk.sh
RUN \
chmod +x /tmp/apk.sh && sh /tmp/apk.sh && rm -rf /tmp/apk.sh && \
curl -o /tmp/composer-setup.php https://getcomposer.org/installer && \
php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer

COPY ./infra/nginx/nginx.conf /etc/nginx/
COPY ./infra/nginx/default.conf /etc/nginx/http.d/
Expand Down
24 changes: 24 additions & 0 deletions infra/apk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
echo "apps:x:0:0:root:/root:/bin/bash" >> /etc/passwd
echo "alias ll='ls -l'" >> /root/.bashrc
apk update
apk add --no-cache curl bash bash-completion shadow tzdata
apk add --no-cache docker
apk add --no-cache nginx nginx-mod-stream
apk add --no-cache git python3
python3 -m venv /opt/venv
mkdir -p /run/php
pip install wheel
pip install supervisor
pip install git+https://github.com/coderanger/supervisor-stdout
apk add --no-cache php82 php82-fpm php82-cli php82-phar php82-iconv php82-mbstring \
php82-gd php82-xml php82-zip php82-curl php82-opcache \
php82-fileinfo php82-session php82-dom php82-tokenizer php82-exif \
php82-xmlreader php82-simplexml php82-xmlwriter \
php82-sqlite3 php82-pdo_sqlite php82-openssl php82-redis php82-mysqli php82-pdo_mysql
ln -s /usr/sbin/php-fpm82 /usr/sbin/php-fpm

apk add certbot certbot-nginx --no-cache
groupmod -og 1000 nginx && \
usermod -ou 1000 -g 1000 nginx && \
apk del shadow git
rm -rf /tmp/* /var/cache/apk/* ~/.cache
15 changes: 15 additions & 0 deletions infra/nginx/custom.d/nginx-log.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# grafana
# source https://github.com/Mtt6300/nginx-geo-metricsreporter
log_format grafana '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$host"';

# splunk
log_format main 'src="$remote_addr" src_ip="$realip_remote_addr" user="$remote_user" '
'time_local="$time_local" status="$status" '
'bytes_out="$bytes_sent" bytes_in="$upstream_bytes_received" '
'http_referer="$http_referer" http_user_agent="$http_user_agent" '
'http_x_forwarded_for="$http_x_forwarded_for" '
'http_x_header="$http_x_header" uri_query="$query_string" uri_path="$uri" '
'http_method="$request_method" response_time="$upstream_response_time" '
'request_time="$request_time" category="$sent_http_content_type"';
10 changes: 0 additions & 10 deletions infra/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,11 @@ http {
default upgrade;
'' close;
}

log_format main 'host="$host" src="$remote_addr" src_ip="$realip_remote_addr" user="$remote_user" '
'time_local="$time_local" status="$status" '
'bytes_out="$bytes_sent" bytes_in="$upstream_bytes_received" '
'http_referer="$http_referer" http_user_agent="$http_user_agent" '
'http_x_forwarded_for="$http_x_forwarded_for" '
'http_x_header="$http_x_header" uri_query="$query_string" uri_path="$uri" '
'http_method="$request_method" response_time="$upstream_response_time" '
'request_time="$request_time" category="$sent_http_content_type"';

gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml;

access_log /app/storage/logs/access.log main;
error_log /app/storage/logs/error.log warn;
include /etc/nginx/http.d/*.conf;
include /etc/nginx/custom.d/fpm-status.conf;
include /app/storage/webconfig/active.d/*.conf;
}

0 comments on commit e427f3b

Please sign in to comment.