diff --git a/.gitignore b/.gitignore index 0b81d17..a5dbc7e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ # Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,laravel,vuejs,phpstorm # Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,laravel,vuejs,phpstorm -composer-prod.json ### Laravel ### /vendor/ diff --git a/Dockerfile b/Dockerfile index 079dfd0..5e5361e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,17 @@ FROM dfs1368/laravel-php-fpm:7.4 +ARG ssh_prv_key + WORKDIR /var/www -RUN apt install -y sendmail libpng-dev +RUN apt install -y sendmail openssh-server libpng-dev + +# Authorize SSH Host +RUN mkdir -p /root/.ssh && \ + chmod 0700 /root/.ssh && \ + echo "$ssh_prv_key" > /root/.ssh/id_rsa && \ + ssh-keyscan git.willaspace.com > /root/.ssh/known_hosts && \ + chmod 600 /root/.ssh/id_rsa RUN docker-php-ext-install gd diff --git a/Dockerfile.nginx b/Dockerfile.nginx new file mode 100644 index 0000000..aae6504 --- /dev/null +++ b/Dockerfile.nginx @@ -0,0 +1,9 @@ +FROM registry.willaspace.com/willaspace/${IMAGE_NAME}-staging:latest AS php_builder + +FROM node:16.7.0-alpine AS builder +COPY --from=php_builder /var/www /app +WORKDIR /app +RUN npm run staging + +FROM nginx:1.21.1 +COPY --from=builder /app/public /usr/share/nginx/html diff --git a/Dockerfile.staging b/Dockerfile.staging new file mode 100644 index 0000000..e0f6968 --- /dev/null +++ b/Dockerfile.staging @@ -0,0 +1,35 @@ +FROM dfs1368/laravel-php-fpm:7.4 + +ARG ssh_prv_key + +WORKDIR /var/www + +RUN apt install -y sendmail openssh-server libpng-dev + +# Authorize SSH Host +RUN mkdir -p /root/.ssh && \ + chmod 0700 /root/.ssh && \ + echo "$ssh_prv_key" > /root/.ssh/id_rsa && \ + ssh-keyscan git.willaspace.com > /root/.ssh/known_hosts && \ + chmod 600 /root/.ssh/id_rsa + +RUN docker-php-ext-install gd + +RUN printf 'upload_max_filesize=300M;\npost_max_size=300M;\nmax_execution_time=600;\nmax_input_time=600;\n' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini; +RUN echo 'pm.max_children = 100' >> /usr/local/etc/php-fpm.d/zz-docker.conf + +COPY database /var/www/database + +COPY composer-staging.* /var/www/ + +RUN composer clearcache && COMPOSER=composer-staging.json composer install --no-scripts + +COPY . /var/www + +RUN php artisan morphmap:cache + +RUN chown -R www-data:www-data \ + /var/www/public \ + /var/www/storage \ + /var/www/bootstrap/cache + diff --git a/Jenkinsfile b/Jenkinsfile index 4a1924f..4c63403 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,15 +5,24 @@ pipeline { } } stages { - stage('build') { + stage('build for production') { when { branch 'master' } steps { - sh 'cd /home/administrator/apps/${IMAGE_NAME}/;docker build -t registry.willaspace.com/willaspace/${IMAGE_NAME}:latest .' + sh 'docker build -t registry.willaspace.com/willaspace/${IMAGE_NAME}:latest --build-arg ssh_prv_key="$(cat /home/administrator/.ssh/id_rsa)" .' sh 'cd /home/administrator/apps/${IMAGE_NAME}/;sudo ./BuildDocker' } } + stage('build for staging') { + when { + branch 'dev' + } + steps { + sh 'docker build -t registry.willaspace.com/willaspace/${IMAGE_NAME}-staging:latest -f Dockerfile.staging --build-arg ssh_prv_key="$(cat /home/administrator/.ssh/id_rsa)" .' + sh 'docker build -t registry.willaspace.com/willaspace/${IMAGE_NAME}-staging-nginx:latest -f Dockerfile.nginx .' + } + } stage('deploy to production') { when { branch 'master' @@ -31,7 +40,8 @@ pipeline { branch 'dev' } steps { - sh 'echo ${IMAGE_NAME}-staging comming soon ...' + sh 'cd /apps/${IMAGE_NAME}-staging/ ; docker-compose up -d' + sh 'docker exec willaengine bash -c "COMPOSER=composer-staging.json composer update"' } } } diff --git a/composer-prod.json b/composer-prod.json new file mode 100644 index 0000000..3a4232c --- /dev/null +++ b/composer-prod.json @@ -0,0 +1,163 @@ +{ + "name": "laravel/laravel", + "type": "project", + "description": "The Laravel Framework.", + "keywords": [ + "framework", + "laravel" + ], + "license": "MIT", + "require": { + "php": "^7.4", + "coraxster/flysystem-aws-s3-v3-minio": "^1.0", + "fideloper/proxy": "^4.0", + "laravel/framework": "^8.0", + "laravel/passport": "^10", + "laravel/tinker": "^2.0", + "maatwebsite/excel": "^3.1", + "kalnoy/nestedset": "^6.0", + "sentry/sentry-laravel": "^2.3", + "spatie/laravel-medialibrary": "^8.0.0", + "io-developer/php-whois": "^4.0", + "silber/bouncer": "v1.0.0-rc.10", + "wm/blog": "dev-master", + "wm/common": "dev-master", + "wm/core": "dev-master", + "wm/crm": "dev-master", + "wm/portfolio": "dev-master", + "wm/product": "dev-master", + "wm/service": "dev-master", + "wm/store": "dev-master", + "wm/finance": "dev-master", + "wm/admin": "dev-master", + "wm/web-builder": "dev-master", + "wm/app-management": "dev-master", + "wm/notification": "dev-master", + "wm/roll-call": "dev-master", + "wm/lms": "dev-master", + "wm/service-store": "dev-master", + "wm/contact-us": "dev-master", + "zircote/swagger-php": "^3.0" + }, + "provide": { + "ext-imagick": "*" + }, + "require-dev": { + "facade/ignition": "^2.3.6", + "fzaninotto/faker": "^1.4", + "mockery/mockery": "^1.0", + "nunomaduro/collision": "^5.0", + "phpunit/phpunit": "^9.0" + }, + "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true + }, + "extra": { + "laravel": { + "dont-discover": [] + } + }, + "autoload": { + "psr-4": { + "App\\": "app/", + "Modules\\": "Modules/" + }, + "classmap": [ + "database/seeds", + "database/factories" + ] + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "post-autoload-dump": [ + "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", + "@php artisan package:discover --ansi", + "@php artisan morphmap:cache" + ], + "post-root-package-install": [ + "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" + ], + "post-create-project-cmd": [ + "@php artisan key:generate --ansi" + ] + }, + + "repositories": [ + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/crm.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/common.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/core.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/blog.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/portfolio.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/product.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/service.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/store.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/notification.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/roll-call.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/app-management.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/web-builder.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/finance.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/service-store.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/admin.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/lms.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/contact-us.git" + } + ] +} diff --git a/composer-staging.json b/composer-staging.json new file mode 100644 index 0000000..e4d2159 --- /dev/null +++ b/composer-staging.json @@ -0,0 +1,163 @@ +{ + "name": "laravel/laravel", + "type": "project", + "description": "The Laravel Framework.", + "keywords": [ + "framework", + "laravel" + ], + "license": "MIT", + "require": { + "php": "^7.4", + "coraxster/flysystem-aws-s3-v3-minio": "^1.0", + "fideloper/proxy": "^4.0", + "laravel/framework": "^8.0", + "laravel/passport": "^10", + "laravel/tinker": "^2.0", + "maatwebsite/excel": "^3.1", + "kalnoy/nestedset": "^6.0", + "sentry/sentry-laravel": "^2.3", + "spatie/laravel-medialibrary": "^8.0.0", + "io-developer/php-whois": "^4.0", + "silber/bouncer": "v1.0.0-rc.10", + "wm/blog": "dev-dev", + "wm/common": "dev-dev", + "wm/core": "dev-dev", + "wm/crm": "dev-dev", + "wm/portfolio": "dev-dev", + "wm/product": "dev-dev", + "wm/service": "dev-dev", + "wm/store": "dev-dev", + "wm/finance": "dev-dev", + "wm/admin": "dev-dev", + "wm/web-builder": "dev-dev", + "wm/app-management": "dev-dev", + "wm/notification": "dev-dev", + "wm/roll-call": "dev-dev", + "wm/lms": "dev-dev", + "wm/service-store": "dev-dev", + "wm/contact-us": "dev-dev", + "zircote/swagger-php": "^3.0" + }, + "provide": { + "ext-imagick": "*" + }, + "require-dev": { + "facade/ignition": "^2.3.6", + "fzaninotto/faker": "^1.4", + "mockery/mockery": "^1.0", + "nunomaduro/collision": "^5.0", + "phpunit/phpunit": "^9.0" + }, + "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true + }, + "extra": { + "laravel": { + "dont-discover": [] + } + }, + "autoload": { + "psr-4": { + "App\\": "app/", + "Modules\\": "Modules/" + }, + "classmap": [ + "database/seeds", + "database/factories" + ] + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "post-autoload-dump": [ + "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", + "@php artisan package:discover --ansi", + "@php artisan morphmap:cache" + ], + "post-root-package-install": [ + "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" + ], + "post-create-project-cmd": [ + "@php artisan key:generate --ansi" + ] + }, + + "repositories": [ + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/crm.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/common.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/core.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/blog.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/portfolio.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/product.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/service.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/store.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/notification.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/roll-call.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/app-management.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/web-builder.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/finance.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/service-store.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/admin.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/lms.git" + }, + { + "type": "vcs", + "url": "git@git.willaspace.com:WillaEngine-Project/contact-us.git" + } + ] +}