diff --git a/.gitignore b/.gitignore index 4befed30..270328c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store .idea +.env \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..96049d41 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,26 @@ +# .travis.yml +dist: precise + +language: php + +php: + - 7.3 + +addons: + mysql: 5.7 + +cache: + directories: + - node_modules + - vendor + +before_script: + - cd src + - cp .env.travis .env + - sudo mysql -e 'CREATE DATABASE testing;' + - composer self-update + - composer install --no-interaction + - php artisan migrate:fresh --seed --no-interaction -vvv + +script: + - php artisan test diff --git a/Dockerfile b/Dockerfile index b90eb57c..cf17eb04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,36 @@ FROM php:7.4-fpm-alpine -ADD php/php.ini /usr/local/etc/php/conf.d/40-custom.ini - WORKDIR /var/www/html COPY src/.env.example /var/www/html/.env RUN apk add --update libzip-dev curl-dev &&\ - docker-php-ext-install curl && \ + docker-php-ext-install curl + +RUN docker-php-ext-install pdo pdo_mysql + +# xdebug with PHPSHTORM +ENV XDEBUG_VERSION=2.9.2 +RUN apk --no-cache add --virtual .build-deps \ + g++ \ + autoconf \ + make && \ + pecl install xdebug-${XDEBUG_VERSION} && \ + docker-php-ext-enable xdebug && \ + apk del .build-deps && \ + rm -r /tmp/pear/* && \ apk del gcc g++ &&\ rm -rf /var/cache/apk/* -RUN docker-php-ext-install pdo pdo_mysql +# Change TimeZone +RUN apk add --update tzdata +ENV TZ=Europe/Kiev + +ADD var/etc/php /usr/local/etc/php + +#Install composer +RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer -RUN usermod -u 1000 www-data; \ - chown -R www-data:www-data /var/www/html +RUN apk --no-cache add shadow && usermod -u 1000 www-data; \ + chown -R www-data:www-data /var/www/html && chmod 777 -R /var/log diff --git a/README.md b/README.md index fd44173f..40f7a079 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,26 @@ ## API2CartBoilerplate +
+ ## Usage -To get started, make sure you have [Docker installed](https://docs.docker.com/docker-for-mac/install/) on your system +To get started, make sure you have [Docker installed and runned](https://docs.docker.com/docker-for-mac/install/) on your system + + +### Automatic start +1. Be sure you have Docker installed and runned on your PC. + +2. please run `start_me.sh` (for Linux/Unix/MacOS) or `start_me.bat` (for Windows) + + + +### Manual start First open a terminal and from this cloned respository's root run `docker-compose up -d --build`. -Open up your browser of choice to [http://localhost:8080](http://localhost:8080) and you should see your Laravel app running as intended. -**Your Laravel app needs to be in the src directory first before bringing the containers up, otherwise the artisan container will not build, as it's missing the appropriate file.** +Open up your browser of choice to [http://localhost:8080](http://localhost:8080) and you should see your Laravel app running as intended. Three new containers have been added that handle Composer, NPM, and Artisan commands without having to have these platforms installed on your local computer. Use the following command templates from your project root, modifiying them to fit your particular use case: @@ -36,3 +50,7 @@ Containers created and their ports (if used) are as follows: - **npm** - **composer** - **artisan** + +## Testing + +- `docker-compose run app php artisan test` diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 5787edcd..9b2066dc 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -2,4 +2,5 @@ pipelines: default: - step: script: - - git push --mirror git@github.com:api2cart/php-a2c-demo-module-boilerplate.git + - git filter-branch -- --all + - git push --force git@github.com:api2cart/php-a2c-demo-module-boilerplate.git diff --git a/docker-compose.yml b/docker-compose.yml index 86df9071..fd763e76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,9 +9,12 @@ services: container_name: nginx ports: - "8080:80" + - "8443:443" volumes: - ./src:/var/www/html - - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + - ./var/etc/nginx/default.conf:/etc/nginx/conf.d/default.conf + - ./var/etc/nginx/ssl:/etc/ssl + - ./var/logs/nginx:/var/log/nginx depends_on: - php - mysql @@ -24,7 +27,7 @@ services: restart: unless-stopped tty: true ports: - - "3306:3306" + - "33061:3306" environment: MYSQL_DATABASE: homestead MYSQL_USER: homestead @@ -34,6 +37,7 @@ services: SERVICE_NAME: mysql volumes: - dbdata:/var/lib/mysql + - ./var/logs/mysql:/var/log/mysql networks: - laravel php: @@ -43,19 +47,7 @@ services: container_name: php volumes: - ./src:/var/www/html - ports: - - "9000:9000" - networks: - - laravel - - composer: - image: composer:latest - container_name: composer - volumes: - - ./src:/var/www/html - working_dir: /var/www/html - depends_on: - - php + - ./var/logs:/var/log networks: - laravel @@ -86,7 +78,6 @@ services: context: . dockerfile: Dockerfile container_name: app - restart: unless-stopped volumes: - ./src:/var/www/html depends_on: diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 00000000..cee60dc5 --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,25 @@ +#!/bin/sh + +if ! [ -x "$(command -v docker-compose)" ]; then + echo "Please check if Docker installed and runned." + + if ! [ -x "$(command -v xdg-open)" ]; then + open https://docs.docker.com/get-docker/ + exit 1 + fi + + xdg-open https://docs.docker.com/get-docker/ + exit 1 +fi + +docker-compose run artisan test + + +if [ $? -eq 0 ]; +then + echo "Looks all ok" + exit 0 +else + echo "missing tests passes, please fix errors" + exit 1 +fi \ No newline at end of file diff --git a/run_me.bat b/run_me.bat new file mode 100644 index 00000000..23d49d1d --- /dev/null +++ b/run_me.bat @@ -0,0 +1,31 @@ +@ECHO OFF + +SET mypath=%cd% +SET CONFIGFILE=%mypath%\src\.env + +copy %mypath%\hooks\pre-commit %mypath%\.git\hooks + +IF EXIST %CONFIGFILE% ( + echo Config exists +) ELSE ( + copy %mypath%\src\.env.example %CONFIGFILE% +) + +docker-compose down + +if errorlevel 1 ( + echo Please check if Docker installed and runned. + pause 0 + start "" https://www.docker.com/products/docker-desktop + exit +) + +docker-compose up -d + +docker-compose run --rm composer update + +docker-compose run app php artisan migrate + +docker-compose run app php artisan db:seed + +start "" https://demo-module.api2cart.local.com:8443 diff --git a/run_me.sh b/run_me.sh new file mode 100755 index 00000000..3d7c86e9 --- /dev/null +++ b/run_me.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +dir=$(pwd) + +# setup user uid:gid for composer +uid="$(id -u):$(id -g)" +echo "uid=$uid" > "$dir/.env" + +cp "$dir/hooks/pre-commit" "$dir/.git/hooks" + +#overwrite config +CONFIGFILE="$dir/src/.env" + +if [ -f "$CONFIGFILE" ]; then + echo "config $CONFIGFILE exist" +else + echo "config do not exists" + cp "$dir/src/.env.example" "$dir/src/.env" +fi +# cp "$dir/src/.env.example" "$dir/src/.env" + +# give rw permissions for temorary folder +sudo chmod -R 777 $dir/src/storage + +#stop for any case container +if ! [ -x "$(command -v docker-compose)" ]; then + echo "Please check if Docker installed and runned." + + if ! [ -x "$(command -v xdg-open)" ]; then + open https://docs.docker.com/get-docker/ + exit 1 + fi + + xdg-open https://docs.docker.com/get-docker/ + exit 1 +fi + +docker-compose down + + +#run containers in background +docker-compose up -d + +if [ $? -eq 0 ]; +then + echo "Looks all ok, update related dependencies..." + docker-compose run app composer update + docker-compose run app php artisan migrate + docker-compose run app php artisan db:seed +else + echo "missing start please contact support" + exit +fi + +if ! [ -x "$(command -v xdg-open)" ]; then + open https://demo-module.api2cart.local.com:8443 + exit 0 +fi +xdg-open https://demo-module.api2cart.local.com:8443 diff --git a/src/.env.example b/src/.env.example index 42fa7e7b..c83ef72a 100644 --- a/src/.env.example +++ b/src/.env.example @@ -2,7 +2,7 @@ APP_NAME="Api2Cart Demo" APP_ENV=local APP_KEY=base64:+oaKbnRJG4izevBAqf0ctXhcV0A0J5E/2Os5+XgA5ZY= APP_DEBUG=false -APP_URL=http://localhost +APP_URL=https://demo-module.api2cart.com APP_LOCALE=en APP_FALLBACK_LOCALE=en APP_LOCALE_PHP=en_US @@ -29,13 +29,13 @@ REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 -MAIL_DRIVER=smtp -MAIL_HOST=localhost -MAIL_PORT=1025 +MAIL_MAILER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null -MAIL_FROM_ADDRESS=hello@example.com +MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}" AWS_ACCESS_KEY_ID= @@ -51,4 +51,8 @@ PUSHER_APP_CLUSTER=mt1 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" -#API2CART_URL=http://api.api2cart.local +API2CART_URL=https://api.api2cart.com/v1.1 + +UID=1000 + +FORCE_HTTPS=true \ No newline at end of file diff --git a/src/.env.travis b/src/.env.travis new file mode 100644 index 00000000..9c49c31b --- /dev/null +++ b/src/.env.travis @@ -0,0 +1,54 @@ +APP_NAME="Api2Cart Demo" +APP_ENV=local +APP_KEY=base64:+oaKbnRJG4izevBAqf0ctXhcV0A0J5E/2Os5+XgA5ZY= +APP_DEBUG=false +APP_URL=http://localhost +APP_LOCALE=en +APP_FALLBACK_LOCALE=en +APP_LOCALE_PHP=en_US +APP_TIMEZONE=UTC +LOG_CHANNEL=single + +DEBUGBAR_ENABLED=true + +DB_CONNECTION=mysql +DB_HOST=localhost +DB_PORT=3306 +DB_DATABASE=testing +DB_USERNAME=travis +DB_PASSWORD= + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +QUEUE_CONNECTION=database +SESSION_DRIVER=file +SESSION_LIFETIME=120 +SESSION_ENCRYPT=false + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" + +#API2CART_URL=http://api.api2cart.local diff --git a/src/.phpstorm.meta.php b/src/.phpstorm.meta.php index 26559415..b6e34a84 100644 --- a/src/.phpstorm.meta.php +++ b/src/.phpstorm.meta.php @@ -5,7 +5,7 @@ /** * PhpStorm Meta file, to provide autocomplete information for PhpStorm - * Generated on 2020-04-10 08:58:02. + * Generated on 2020-07-02 06:55:43. * * @author Barry vd. Heuvel