Skip to content

Commit

Permalink
Dockerize
Browse files Browse the repository at this point in the history
  • Loading branch information
hosni committed Apr 8, 2024
1 parent b24861a commit 4a63b8c
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 0 deletions.
208 changes: 208 additions & 0 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
name: 'Install Dependencies'
description: 'Install Jalno Dependencies For Ghafiye'

inputs:
GITLAB_PRIVATE_KEY:
description: 'git.jeyserver.com private token'
required: true
GITLAB_KNOWN_HOST:
description: 'git.jeyserver.com known host'
required: true
GITLAB_SERVER_URL:
description: 'git.jeyserver.com url'
required: false
default: 'https://git.jeyserver.com'
CACHE_PACKAGES:
description: 'cache Jalno dependencies in packages directory, except base and ghafiye package'
required: false
default: 'true'
CACHE_PACKAGES_KEY_DATE_FORMAT:
description: 'a format to give date command to generate key for cache'
required: false
default: '+%Y%m%d'

runs:
using: "composite"
steps:
- name: Checkout jalno/base
uses: actions/checkout@v4
with:
repository: jalno/base
path: base

- name: Get Date for Cache Key
id: get-cache-key
if: inputs.CACHE_PACKAGES == 'true'
run: |
echo "date=$(/bin/date -u "${{ inputs.CACHE_PACKAGES_KEY_DATE_FORMAT }}")" >> $GITHUB_OUTPUT
echo $GITHUB_OUTPUT
shell: bash

- name: Restore cached Jalno Packages
id: cache-packages-restore
if: inputs.CACHE_PACKAGES == 'true'
uses: actions/cache/restore@v4
with:
path: base/packages
key: ${{ runner.os }}-jalno-packages-${{ steps.get-cache-key.outputs.date }}

- name: Checkout jalno/PhpParser
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: jalno/PhpParser
path: base/packages/PhpParser

- name: Checkout jalno/notifications
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: jalno/notifications
path: base/packages/notifications

- name: Checkout jalno/userpanel
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: jalno/userpanel
path: base/packages/userpanel

- name: Checkout abedi/blog
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: abedi/blog
path: base/packages/blog
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout abedi/contactus
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: abedi/contactus
path: base/packages/contactus
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout yeganemehr/email
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: yeganemehr/email
path: base/packages/email
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout abedi/geoip
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: abedi/geoip
path: base/packages/geoip
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout dnj/musixmatch
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: dnj/musixmatch
path: base/packages/musixmatch

- name: Checkout abedi/pages
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: abedi/pages
path: base/packages/pages
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout abedi/redirect
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: abedi/redirect
path: base/packages/redirect
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout yeganemehr/sitemap
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: yeganemehr/sitemap
path: base/packages/sitemap
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout yeganemehr/sms
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: yeganemehr/sms
path: base/packages/sms
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout hosni/phpmailer
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: hosni/phpmailer
path: base/packages/phpmailer
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout yeganemehr/phpmailer_emailsender
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: yeganemehr/phpmailer_emailsender
path: base/packages/phpmailer_emailsender
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout hosni/s3
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: hosni/s3
path: base/packages/s3
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Checkout hosni/s3_api
uses: actions/checkout@v4
if: (inputs.CACHE_PACKAGES != 'true' || steps.cache-packages-restore.outputs.cache-hit != 'true')
with:
repository: hosni/s3_api
path: base/packages/s3_api
github-server-url: ${{ inputs.GITLAB_SERVER_URL }}
ssh-known-hosts: ${{ inputs.GITLAB_KNOWN_HOST }}
ssh-key: ${{ inputs.GITLAB_PRIVATE_KEY }}

- name: Cache Jalno Packages
id: cache-packages
if: inputs.CACHE_PACKAGES == 'true'
uses: actions/cache@v4
with:
path: base/packages
key: ${{ runner.os }}-jalno-packages-${{ steps.get-cache-key.outputs.date }}

- name: Checkout dnj/ghafiye
uses: actions/checkout@v4
with:
path: base/packages/ghafiye
113 changes: 113 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Test and Build Ghafiye

on:
push:
pull_request:
workflow_dispatch:

env:
TARGET_PHP_VERSION: 7.4
GITLAB_KNOWN_HOST: |
git.jeyserver.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC+Xhcnp8pJ6a0BuFe7MiBTVwticsJHsMkwAOo2vXs0XNrbFu3CToHNh0r7zywXSLOgNwxRM52xyCi6/844Xh3Coza/GfR/7S3bN47tDmR8nPhhrcZbKDsVnpBrNFEIkRLp9sCb4Uu+xabAdewvOvS3FJvfuHL8xnwUXcNdWR7ot9dgqNywg23x40b8EBzEZhDToSYZm0wgtX4Y1BzCa7vff4eCygZA6vD6yr88eJsTXHBywiqpqpXEPaQ815ajzdUNv4Q2ZLi3Avt10DfEmGr+l93ZxHDkb0/Gh4+jotsXo2TJ04KnFkHsTXi2LFeXeXsCmI8eQQOBNGel4JP0aIQl7xP5Weytukg2WI8rOOvqRsS5gKI2hz+deEXEqSg14w33/DhVyij5vGv7afNKu8Df2S36ROuB6nHBY9GMur/sM2kkbvHmaWsZIAhnK1Bmz6oxfKNxue01LBWZzXDPWwFLQzYoaalZWYz6mjuQzidX0cgD8I97/sBJQgIxmwFCFvs=
git.jeyserver.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBH8kqdVFHBUbGR1nCqvZnkh1Z39Xq15KxHxg6xQT3b4G28WAw7t5cWR9DcrGmGSPIdNWeFEhyn/c3azt2LO2868=
git.jeyserver.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN1PDZEczwMyJs3dLAkeBN5jVFgPspJsoWXYIy2Rr47W
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
path: base/packages/ghafiye

- run: pwd
- run: ls -lh base
- run: ls -lh base/packages

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.TARGET_PHP_VERSION }}

- name: Validate ghafiye package.json
run: php -r 'json_decode(file_get_contents("./base/packages/ghafiye/package.json"), false, 512, JSON_THROW_ON_ERROR);'

- name: Validate ghafiye routing.json
run: php -r 'json_decode(file_get_contents("./base/packages/ghafiye/routing.json"), false, 512, JSON_THROW_ON_ERROR);'

- name: Validate ghafiye sitemap.json
run: php -r 'json_decode(file_get_contents("./base/packages/ghafiye/sitemap.json"), false, 512, JSON_THROW_ON_ERROR);'

- name: Validate ghafiye autoloader.json
run: php -r 'json_decode(file_get_contents("./base/packages/ghafiye/autoloader.json"), false, 512, JSON_THROW_ON_ERROR);'

build:
runs-on: ubuntu-latest
needs: [test]
permissions:
contents: read
packages: write
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
path: base/packages/ghafiye

- name: Install Dependencies
uses: ./base/packages/ghafiye/.github/actions/install-dependencies
with:
GITLAB_KNOWN_HOST: ${{ env.GITLAB_KNOWN_HOST }}
GITLAB_PRIVATE_KEY: ${{ secrets.GITLAB_PRIVATE_KEY }}

- name: Checkout jalno/node_webpack
uses: actions/checkout@v4
with:
repository: jalno/node_webpack
path: base/packages/node_webpack

- name: Checkout jalno/dockerize
uses: actions/checkout@v4
with:
repository: jalno/dockerize
path: base/packages/dockerize

- run: cp base/packages/dockerize/.dockerignore base/.

- run: pwd
- run: ls -lh base
- run: ls -lh base/packages

- name: Log into registry ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
file: ./base/packages/ghafiye/Dockerfile
context: base/
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM ghcr.io/dnj/php-alpine:7.4-mysql-nginx

ARG TSCONFIG_PATH="packages/ghafiye/frontend-userpanel/tsconfig.json"

RUN apk --no-cache add --virtual .dev pcre-dev yaml-dev ${PHPIZE_DEPS} \
&& pecl install timezonedb yaml \
&& docker-php-ext-install calendar \
&& docker-php-ext-enable timezonedb yaml calendar \
&& apk del .dev \
&& apk add yaml bind-tools \
&& echo 'php_admin_value[upload_max_filesize] = 100M' >> /usr/local/etc/php-fpm.d/www.conf \
&& echo 'php_admin_value[post_max_size] = 100M' >> /usr/local/etc/php-fpm.d/www.conf \
&& echo 'date.timezone = Asia/Tehran' > /usr/local/etc/php/conf.d/tz.ini \
&& echo 'max_input_vars = 65535' > /usr/local/etc/php/conf.d/zz-araduser.ini

COPY --chown=www-data:www-data . /var/www/html
COPY packages/dockerize/nginx/jalno.conf /etc/nginx/conf.d/default.conf.d/

RUN rm -fr packages/dockerize; \
find /var/www/html -type d -name ".docker" -prune -exec rm -fr {} \;; \
if [[ -d /var/www/html/packages/node_webpack ]]; then \
chown -R root:root /var/www/html && \
mkdir -p /tmp/nodejs && \
cd /tmp/nodejs && \
wget -O nodejs.tar.gz https://unofficial-builds.nodejs.org/download/release/v14.9.0/node-v14.9.0-linux-x64-musl.tar.gz && \
tar --strip-components=1 -xf nodejs.tar.gz && \
ln -s /tmp/nodejs/bin/node /usr/bin/node && \
ln -s /tmp/nodejs/bin/npm /usr/bin/npm && \
ln -s /tmp/nodejs/bin/npx /usr/bin/npx && \
cd /var/www/html/packages/node_webpack/nodejs && \
mkdir -p storage/public/frontend/dist && \
if [[ -n "$TSCONFIG_PATH" ]]; then \
NODE_ENV=production npm start -- --production --tsconfig=$TSCONFIG_PATH; \
else \
NODE_ENV=production npm start -- --production; \
fi; \
find /var/www/html -type d -name "node_modules" -prune -exec rm -fr {} \;; \
rm -fr ~/.npm ~/.config /tmp/nodejs /usr/bin/node /usr/bin/npm /usr/bin/npx && \
chown -R www-data:www-data /var/www/html; \
fi; \
(crontab -l 2>/dev/null; echo -e -n \
'* * * * * php /var/www/html/index.php --process=packages/ghafiye/processes/crawler@run' '\n' \
) | crontab -

WORKDIR /var/www/html

0 comments on commit 4a63b8c

Please sign in to comment.