Skip to content

Commit

Permalink
Docker: Include integration
Browse files Browse the repository at this point in the history
Signed-off-by: Dicky Herlambang (花) <herlambangdicky5@gmail.com>
  • Loading branch information
Nicklas373 committed Mar 24, 2024
1 parent c62b41f commit 5804740
Show file tree
Hide file tree
Showing 13 changed files with 623 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env-db
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DB_DATABASE=postgres
DB_USERNAME=master
DB_PASSWORD=postgres
98 changes: 98 additions & 0 deletions Dockerfile/Dockerfile.hana-api-services.sit
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Configure php fpm as base image
FROM php:8.2-fpm

# Configure image maintainer
LABEL maintainer="Nicklas373 <herlambangdicky5@gmail.com>"
LABEL version="1.0"
LABEL description="Docker container for HANA PDF REST API"

# Configure ARG
ARG DB_USERNAME
ARG DB_PASSWORD
ARG JWT_SHOW_BLACKLIST_EXCEPTION
ARG JWT_TTL

# Configure work directory
WORKDIR /var/www/html

# Configure updates packages
RUN apt-get update && apt-get upgrade -y && apt-get upgrade dist -y && apt-get dist-upgrade -y

# Configure initial packages
RUN apt-get update && apt-get install -y \
curl \
unzip \
git \
libmagickwand-dev \
libzip-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
ghostscript

# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg && \
docker-php-ext-install -j$(nproc) \
gd \
zip

# Install Imagick extension
RUN pecl install imagick && \
docker-php-ext-enable imagick

# Configure PostgresSQL PHP Driver
RUN apt-get update && apt-get install -y libpq-dev && \
docker-php-ext-install pdo_pgsql

# Clone App Services
RUN git clone -b be/master https://github.com/Nicklas373/Hana-PDF hanaci-api
RUN chown -R www-data:www-data hanaci-api

# Configure Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN cd hanaci-api && composer install --no-interaction --no-scripts --no-progress --prefer-dist

# Configure App Service
RUN mkdir hanaci-api/storage/app/public/batch
RUN mkdir hanaci-api/storage/app/public/download
RUN mkdir hanaci-api/storage/app/public/image
RUN mkdir hanaci-api/storage/app/public/pool
RUN mkdir hanaci-api/storage/app/public/upload
RUN cd hanaci-api && chmod o+w /var/www/html/hanaci-api/storage/ -R
RUN cd hanaci-api && chmod o+w /var/www/html/hanaci-api/vendor/mpdf/mpdf/tmp/ -R
RUN cd hanaci-api && cp .env.example .env
RUN cd hanaci-api && php artisan key:generate
RUN cd hanaci-api && php artisan jwt:secret
RUN cd hanaci-api && php artisan storage:link
RUN cd hanaci-api && php artisan config:cache
RUN cd hanaci-api && php artisan config:clear

# Configure Laravel Env
RUN cd hanaci-api && echo "JWT_SHOW_BLACKLIST_EXCEPTION=$JWT_SHOW_BLACKLIST_EXCEPTION" >> .env
RUN cd hanaci-api && echo "JWT_TTL=$JWT_TTL" >> .env
RUN cd hanaci-api && echo "" >> .env
RUN cd hanaci-api && sed -i 's/APP_NAME=Laravel/APP_NAME="gw.hana-ci"/' .env
RUN cd hanaci-api && sed -i "s#APP_URL=http://localhost#APP_URL=http://sit.gw.hana-ci.com#" .env
RUN cd hanaci-api && sed -i "s/DB_CONNECTION=mysql/DB_CONNECTION=pgsql/" .env
RUN cd hanaci-api && sed -i "s/DB_HOST=127.0.0.1/DB_HOST=hana-db-services/" .env
RUN cd hanaci-api && sed -i "s/DB_PORT=3306/DB_PORT=5432/" .env
RUN cd hanaci-api && sed -i "s/DB_DATABASE=laravel/DB_DATABASE=postgres/" .env
RUN cd hanaci-api && sed -i "s/DB_USERNAME=root/DB_USERNAME=$DB_USERNAME/" .env
RUN cd hanaci-api && sed -i "s/DB_PASSWORD=/DB_PASSWORD=$DB_PASSWORD/" .env
RUN cd hanaci-api && echo "" >> .env
RUN cd hanaci-api && echo "ASPOSE_CLOUD_CLIENT_ID=xxxx" >> .env
RUN cd hanaci-api && echo "ASPOSE_CLOUD_TOKEN=xxxx" >> .env
RUN cd hanaci-api && echo "FTP_USERNAME=xxxx" >> .env
RUN cd hanaci-api && echo "FTP_USERPASS=xxxx" >> .env
RUN cd hanaci-api && echo "FTP_SERVER=xxxx" >> .env
RUN cd hanaci-api && echo "FTP_ROOT=xxxx" >> .env
RUN cd hanaci-api && echo "ILOVEPDF_PUBLIC_KEY=xxxx" >> .env
RUN cd hanaci-api && echo "ILOVEPDF_SECRET_KEY=xxxx" >> .env
RUN cd hanaci-api && echo "PDF_IMG_POOL=image" >> .env
RUN cd hanaci-api && echo "PDF_BATCH=batch" >> .env
RUN cd hanaci-api && echo "PDF_UPLOAD=upload" >> .env
RUN cd hanaci-api && echo "PDF_DOWNLOAD=download" >> .env
RUN cd hanaci-api && echo "PDF_POOL=pool" >> .env
RUN cd hanaci-api && echo "TELEGRAM_BOT_ID=xxxx" >> .env
RUN cd hanaci-api && echo "TELEGRAM_CHAT_ID=xxxx" >> .env
RUN cd hanaci-api && echo "HANA_UNIQUE_KEY=xxxx" >> .env
55 changes: 55 additions & 0 deletions Dockerfile/Dockerfile.hana-app-pdf.sit
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Configure php fpm as base image
FROM php:8.2-fpm

# Configure image maintainer
LABEL maintainer="Nicklas373 <herlambangdicky5@gmail.com>"
LABEL version="1.0"
LABEL description="Docker application image for HANA PDF Apps"

# Configure ARG
ARG DB_USERNAME
ARG DB_PASSWORD

# Configure work directory
WORKDIR /var/www/html

# Configure initial updates for instance
RUN apt-get update && apt-get upgrade -y

# Configure initial packages
RUN apt-get update && apt-get install -y \
curl \
unzip \
git \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Clone App Services
RUN git clone -b fe/master https://github.com/Nicklas373/Hana-PDF hanaci-pdf
RUN chown -R www-data:www-data hanaci-pdf

# Configure Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN cd hanaci-pdf && composer install --no-interaction --no-scripts --no-progress --prefer-dist

# Configure App Service
RUN cd hanaci-pdf && chmod o+w /var/www/html/hanaci-pdf/storage/ -R
RUN cd hanaci-pdf && cp .env.example .env
RUN cd hanaci-pdf && php artisan key:generate
RUN cd hanaci-pdf && php artisan config:cache
RUN cd hanaci-pdf && php artisan config:clear

# Configure Laravel Env
RUN cd hanaci-pdf && echo "VITE_ADOBE_CLIENT_ID=xxxx" >> .env
RUN cd hanaci-pdf && echo "" >> .env
RUN cd hanaci-pdf && sed -i 's/APP_NAME=Laravel/APP_NAME="HANA PDF"/' .env
RUN cd hanaci-pdf && sed -i "s#APP_URL=http://localhost#APP_URL=http://sit.pdf.hana-ci.com#" .env
RUN cd hanaci-pdf && sed -i "s/DB_CONNECTION=mysql/DB_CONNECTION=pgsql/" .env
RUN cd hanaci-pdf && sed -i "s/DB_HOST=127.0.0.1/DB_HOST=hana-db-services/" .env
RUN cd hanaci-pdf && sed -i "s/DB_PORT=3306/DB_PORT=5432/" .env
RUN cd hanaci-pdf && sed -i "s/DB_DATABASE=laravel/DB_DATABASE=postgres/" .env
RUN cd hanaci-pdf && sed -i "s/DB_USERNAME=root/DB_USERNAME=$DB_USERNAME/" .env
RUN cd hanaci-pdf && sed -i "s/DB_PASSWORD=/DB_PASSWORD=$DB_PASSWORD/" .env
RUN cd hanaci-pdf && echo "TELEGRAM_BOT_ID=xxxx" >> .env
RUN cd hanaci-pdf && echo "TELEGRAM_CHAT_ID=xxxx" >> .env
87 changes: 87 additions & 0 deletions Dockerfile/Dockerfile.hana-instance-services.sit
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
FROM nginx:latest

# Configure image maintainer
LABEL maintainer="Nicklas373 <herlambangdicky5@gmail.com>"
LABEL version="1.0"
LABEL description="Docker container for instance on HANA-CI"

# Configure timezone
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -yq tzdata && \
ln -fs /usr/share/zoneinfo/Asia/Jakarta /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata
ENV TZ="Asia/Jakarta"
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Configure updates packages
RUN apt-get update && apt-get upgrade -y && apt-get upgrade dist -y && apt-get dist-upgrade -y

# Configure Supervisord and PHP-FPM
RUN apt-get update && apt-get install -y \
supervisor \
php8.2-fpm \
wget

# Configure PHP dependencies
RUN wget http://archive.ubuntu.com/ubuntu/pool/main/i/icu/libicu70_70.1-2ubuntu1_amd64.deb
RUN dpkg -i libicu70_70.1-2ubuntu1_amd64.deb

# Configure initial packages
RUN apt-get update \
&& mkdir -p /etc/apt/keyrings \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git sqlite3 libcap2-bin libpng-dev python3 python3-pip dnsutils librsvg2-bin fswatch cron \
&& curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \
&& echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.2-cli php8.2-dev \
php8.2-pgsql php8.2-sqlite3 php8.2-gd php8.2-imagick \
php8.2-curl \
php8.2-imap php8.2-mbstring \
php8.2-xml php8.2-zip php8.2-bcmath php8.2-soap \
php8.2-intl php8.2-readline \
php8.2-ldap \
php8.2-msgpack php8.2-igbinary php8.2-redis php8.2-swoole \
php8.2-memcached php8.2-pcov php8.2-xdebug \
php8.2-imagick \
ghostscript \
&& curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \
&& apt-get update \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Configure PHP
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.2
RUN sed -i 's/user = www-data/user = nginx/' /etc/php/8.2/fpm/pool.d/www.conf
RUN sed -i 's/group = www-data/group = nginx/' /etc/php/8.2/fpm/pool.d/www.conf
RUN sed -i 's/listen.owner = www-data/listen.owner = nginx/' /etc/php/8.2/fpm/pool.d/www.conf
RUN sed -i 's/listen.group = www-data/listen.group = nginx/' /etc/php/8.2/fpm/pool.d/www.conf
RUN sed -i 's/;listen.mode = 0660/listen.mode = 0660/' /etc/php/8.2/fpm/pool.d/www.conf
RUN sed -i 's/post_max_size = 8M/post_max_size = 125M/' etc/php/8.2/cli/php.ini
RUN sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 125M/' etc/php/8.2/cli/php.ini
RUN sed -i 's/max_execution_time = 30/max_execution_time = 360/' etc/php/8.2/cli/php.ini
RUN sed -i 's/max_input_time = 60/max_input_time = 360/' etc/php/8.2/fpm/php.ini
RUN sed -i 's/post_max_size = 8M/post_max_size = 125M/' etc/php/8.2/fpm/php.ini
RUN sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 125M/' etc/php/8.2/fpm/php.ini
RUN sed -i 's/max_execution_time = 30/max_execution_time = 360/' etc/php/8.2/fpm/php.ini
RUN sed -i 's/max_input_time = 60/max_input_time = 360/' etc/php/8.2/fpm/php.ini

# Configure Python modules
ENV PIP_BREAK_SYSTEM_PACKAGES 1
RUN pip3 install --upgrade pip && pip3 install requests

# Configure nginx instances
RUN mkdir /etc/nginx/sites-enabled/
RUN ln -s /etc/nginx/sites-available/pdf-hanaci.conf /etc/nginx/sites-enabled/
RUN ln -s /etc/nginx/sites-available/api-hanaci.conf /etc/nginx/sites-enabled/
RUN rm /etc/nginx/conf.d/default.conf

# Configure cronjob and init process
COPY module/instance/supervisord.conf /etc/supervisor/
RUN echo "* * * * * cd /var/www/html/hanaci-api && php artisan schedule:run >> /dev/null 2>&1" | crontab -
RUN service cron start

VOLUME [ "/var/www/html" ]

CMD ["/usr/bin/supervisord","-n", "-c", "/etc/supervisor/supervisord.conf"]
94 changes: 94 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: '3.8'
services:
hana-app-pdf:
image: nicklas373/hana-app-pdf-sit:1.0
container_name: 'hana-app-pdf'
cpus: 1.0
mem_limit: 256m
mem_reservation: 128M
restart: unless-stopped
working_dir: /var/www/html/hanaci-pdf
environment:
- APP_NAME=pdf.hana-ci.com
volumes:
- hana-app-pdf:/var/www/html/hanaci-pdf
networks:
- hana-network
depends_on:
- hana-api-services
- hana-instance-services
hana-api-services:
image: nicklas373/hana-api-services-sit:1.0
container_name: 'hana-api-services'
cpus: 2.0
mem_limit: 1024M
mem_reservation: 512M
restart: always
working_dir: /var/www/html/hanaci-api
environment:
- APP_NAME=gw.hana-ci.com
volumes:
- hana-api-services:/var/www/html/hanaci-api
networks:
- hana-network
depends_on:
- hana-db-services
- hana-instance-services
hana-db-services:
image: postgres:16.1
container_name: 'hana-db-services'
restart: unless-stopped
cpus: 1.0
mem_limit: 256M
mem_reservation: 128M
ports:
- '${DB_PORT:-5432}:5432'
env_file:
- .env
environment:
PGPASSWORD: '${DB_PASSWORD}'
POSTGRES_DB: '${DB_DATABASE}'
POSTGRES_USER: '${DB_USERNAME}'
POSTGRES_PASSWORD: '${DB_PASSWORD}'
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- 'hana-db-services:/var/lib/postgresql/data'
- './module/instance/init-user-db.sh:/docker-entrypoint-initdb.d/init-user-db.sh'
networks:
- hana-network
depends_on:
- hana-instance-services
hana-instance-services:
image: nicklas373/hana-instance-services-sit:1.0
container_name: 'hana-instance-services'
cpus: 2.0
mem_limit: 1024M
mem_reservation: 512M
restart: always
ports:
- "80:80"
- "81:81"
volumes:
- ./module/imagick/policy.xml:/etc/ImageMagick-6/policy.xml
- ./module/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./module/nginx/sites-available/api-hanaci.conf:/etc/nginx/sites-available/api-hanaci.conf
- ./module/nginx/sites-available/pdf-hanaci.conf:/etc/nginx/sites-available/pdf-hanaci.conf
- ./module/php/php.ini:/etc/php/8.2/cli/conf.d/99-hana.ini
- ./module/php/php.ini:/etc/php/8.2/fpm/conf.d/99-hana.ini
- hana-app-pdf:/var/www/html/hanaci-pdf
- hana-api-services:/var/www/html/hanaci-api
- hana-instance-services:/var/log/supervisor
networks:
- hana-network
networks:
hana-network:
driver: bridge
volumes:
hana-db-services:
driver: local
hana-app-pdf:
driver: local
hana-api-services:
driver: local
hana-instance-services:
driver: local
36 changes: 36 additions & 0 deletions module/bash/docker-build-info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

TG_TOKEN=$1
TG_CHAT_ID=$2
CONTAINER_NAME=$3
WORKFLOW_URL=$4
IMAGE_NAME=$5
STATUS=$6
curdate=$(TZ=Indonesia/Jakarta date)

function bot_template() {
curl -s -X POST https://api.telegram.org/bot$TG_TOKEN/sendMessage -d chat_id=$TG_CHAT_ID -d "parse_mode=HTML" -d text="$(
for POST in "${@}";
do
echo "${POST}"
done
)"
}

# Telegram Bot Service || Compiling Message
function bot_message() {
bot_template "<b>|| HANA-CI Build Bot ||</b>" \
"" \
"<b> Github Workflow Start ! </b>" \
"" \
"============= Job Information ================" \
"<b>Workflow :</b><code> $CONTAINER_NAME </code>" \
"<b>Workflow Detail :</b><code> <a href='$WORKFLOW_URL'>$WORKFLOW_URL</a> </code>" \
"<b>Workflow Environment :</b><code> Production </code>" \
"<b>Workflow Status :</b><code> $STATUS </code>" \
"<b>Workflow Step :</b><code> $IMAGE_NAME </code>" \
"<b>Workflow Start At :</b><code> ${curdate} </code>" \
""
}

bot_message

0 comments on commit 5804740

Please sign in to comment.