diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c777905 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 + +[{Makefile,**.mk}] +# Use tabs for indentation (Makefiles require tabs) +indent_style = tab diff --git a/.env.example b/.env.example index e721fe0..b8e3239 100644 --- a/.env.example +++ b/.env.example @@ -2,13 +2,13 @@ APP_ENV=local APP_DEBUG=true APP_KEY=B5CLY5YFG5c7X4aTLw13AxmtrkVTcUWb -DB_HOST=localhost -DB_HOST_READ=localhost -DB_DATABASE=muhit -DB_USERNAME=homestead -DB_PASSWORD=secret -RDS_HOST=127.0.0.1 +DB_HOST=muhit-db +DB_HOST_READ=muhit-db +DB_DATABASE=muhit +DB_USERNAME=muhit +DB_PASSWORD=11235 +RDS_HOST=muhit-redis CACHE_DRIVER=redis SESSION_DRIVER=redis diff --git a/.travis.yml b/.travis.yml index 99f5aa3..8945cb9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,20 +13,3 @@ before_deploy: - rm -rf node_modules/ - zip -qr ../MuhitAPP-${TRAVIS_BUILD_NUMBER}.zip ./* - mv ../MuhitAPP-${TRAVIS_BUILD_NUMBER}.zip ${TRAVIS_BUILD_DIR}/ - -deploy: - - provider: elasticbeanstalk - skip_cleanup: true - zip_file: MuhitAPP-${TRAVIS_BUILD_NUMBER}.zip - access_key_id: - secure: QQYc+cdhycjmxInCd1qCNeUQptZyJPAjHl5tAY6b54YuhWIzJapnXrWWeL0snebelzRvi82vk+Tc7YcK0zIzsXM62/K4OUqAlsfAnih5cnm234w9EYfcHOzJY2fFcrgbLkWRKXWXTB3YhcT4/N6W0KwGUYhpiOgD0cZ+Sez5iwAJO4XPP/z0G8ellFhsH3UJrsi/iULPTPA6Spp44tTd9k4uLrd86A+28GsKLjVjQ52xbTlC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v8s2mEq1YWMhrKs5a/5XkiyPSPzuUo5wl/osyavBHF3ZOCo2ot2msmA8EGuEcKPVLUw= - region: eu-west-1 - app: - secure: LBezfVKi8ZOVae10OEVdjNNp7sM3qQcDKm7R+BPkwdqMK4TqgE1sdQVpBQw8F/2hIB7Eo7zI6HJKfoNqZfgtB9OMQjq2/wQYhMziJGNAe8n6fcuxXcHTv1vFpLk0LRDz3HXSKZQiGibw1pKAziZQHq/qqTrSZQzOHWoEHAzDI9J8H+hY0+Gb+RI/veN+0MyyOxDbD7TZkd4ByEJb1GlajIy0/DAZhvzd5jqyl1jODhV9VK5+JJNY+bUdjKQrSBopMZgEE8xSxvvQOcelgcMof9CqhwF921LsL9i7cgQNE7CeOeTbV3CDY8hOGlOwafZJGb4CZmLEXQVnfjBI2FcIpXCvFTVMIPJqEpywuWRCq4gB0KGw1IOEjRlfL/1kbgI3Bjsi/p1POeKL7Krm4DZE6p4hysx3zZLGDxIBswrzH4Gq5f8pw0xAJkxq6f3fQa5D/KBK7K9QI+v7+rbX6ezt7IHDDnIj1xxpdiKSDgkZc+4VjAGjaUWu/DBfff+bjpslQy9XcZ/ujZ8muHTbZOiuqpjw38zx3HVo/SQqRo435Bq1GHI4uSvS5ryaYAl3Obbgj6zKZNRzRA1EeRTEGcJYUDKpmuzKq0ZkoL8Fu6XjTV8z8UzHItjKrPPI7I5tDRA4m0MaDjYp5uuV8md9Ii9+ebsJDPb4yD7Lw8ghySo8AKQ= - env: app-live - bucket_name: muhit-travis-ci - on: - repo: Muhit-co/api - branch: master diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..09f248a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +FROM php:fpm-alpine3.10 + +RUN apk --update add wget \ + curl \ + git \ + grep \ + nginx \ + build-base \ + libmemcached-dev \ + libmcrypt-dev \ + libxml2-dev \ + zlib-dev \ + autoconf \ + cyrus-sasl-dev \ + libgsasl-dev \ + supervisor \ + re2c \ + openssl \ + nodejs \ + npm + +RUN docker-php-ext-install mysqli mbstring pdo pdo_mysql tokenizer xml opcache soap + +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +# install igbinary +RUN cd /tmp && \ + wget https://github.com/igbinary/igbinary/archive/3.0.1.zip && \ + unzip 3.0.1.zip && cd igbinary-3.0.1 && \ + phpize && ./configure && make && make install && \ + docker-php-ext-enable igbinary + +# install memcached +RUN cd /tmp && \ + wget https://github.com/php-memcached-dev/php-memcached/archive/v3.1.3.zip && \ + unzip v3.1.3.zip && cd php-memcached-3.1.3 && \ + phpize && ./configure --enable-memcached-igbinary && make && make install && \ + docker-php-ext-enable memcached + +# clean up and create www +RUN mkdir -p /var/www && \ + rm -rf /tmp/* + +WORKDIR /var/www/html + +COPY . ./ +RUN composer install +RUN chown -R www-data:www-data ./ + +# copy service configs and files +COPY docker/nginx.conf /etc/nginx/nginx.conf +COPY docker/php-uploads.ini /usr/local/etc/php/conf.d/uploads.ini +COPY docker/supervisord.conf /etc/supervisord.conf + +EXPOSE 80 + +ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..96cd6a0 --- /dev/null +++ b/Makefile @@ -0,0 +1,70 @@ +.PHONY: build build-prod composer dev check test docker-dev docker-build ci dev-db release gulp + +# Install composer and node deps and run composer scripts. +build: + docker build -t muhit/web . + +# This will install composer packages but will not run scripts. +build-prod: + composer install --no-scripts --no-dev + +# Alias for building and running docker composer +dev: docker-dev + +# Alias for running composer checks script +check: + composer checks + +# Alias for running composer test script +test: + composer test + +# Creates the development environment with docker compose +docker-dev: + -chmod -Rf 777 storage/ + docker-compose -f docker-compose-dev.yml up + +# Rebuilds the docker images if something changes. +docker-build: + docker-compose -f docker-compose-dev.yml build + +# Alias to run on CI environment. +ci: + make build-prod + +# Runs the artisan db commands +dev-db: + docker exec -i api_muhitweb_1 /usr/local/bin/php artisan migrate + docker exec -i api_muhitweb_1 /usr/local/bin/php artisan db:seed + +# Removes everything in development database +dev-db-refresh: + docker exec -i api_muhitweb_1 /usr/local/bin/php artisan migrate:fresh + +# Runs the rollback command on the docker +dev-rollback: + docker exec -i api_muhitweb_1 /usr/local/bin/php artisan migrate:rollback + +# clears caches on docker +view-clear: + docker exec -i api_muhitweb_1 /usr/local/bin/php artisan view:clear + docker exec -i api_muhitweb_1 /usr/local/bin/php artisan view:cache + +# install npm and run gulp +gulp: + docker exec -i api_muhitweb_1 npm install + docker exec -i api_muhitweb_1 ./node_modules/.bin/gulp --production + +# reads the latest tag, creates a new release incrementing the patch number +release: + $(eval branch := $(shell git rev-parse --abbrev-ref HEAD)) + $(eval v := $(shell git describe --tags --abbrev=0 | sed -Ee 's/^v|-.*//')) + $(eval f := 3) + $(eval n := $(shell echo $(v) | awk -F. -v OFS=. -v f=$(f) '{ $$f++ } 1')) + git flow release start $(n) + git flow release finish $(n) + git push origin develop + git push --tags + git checkout master + git push origin master + git checkout develop diff --git a/app/Console/Commands/DataExporter.php b/app/Console/Commands/DataExporter.php new file mode 100644 index 0000000..ca9feef --- /dev/null +++ b/app/Console/Commands/DataExporter.php @@ -0,0 +1,79 @@ +argument('target'); + switch ($target) { + case 'tags': + $this->tags(); + break; + + case 'hoods': + $this->hoods(); + break; + case 'issues': + $this->issues(); + break; + + default: + $this->comment("No default target"); + break; + } + } + + public function tags() + { + $tags = Tag::all(); + echo $tags->toJson(); + } + + public function hoods() + { + $hoods = Hood::all(); + echo $hoods->toJson(); + } + + public function issues() + { + $issues = Issue::with('comments.user', 'user', 'tags', 'images', 'updates')->get(); + echo $issues->toJson(); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 3ff117c..81f8275 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -12,6 +12,7 @@ class Kernel extends ConsoleKernel { */ protected $commands = [ 'Muhit\Console\Commands\Inspire', + 'Muhit\Console\Commands\DataExporter', ]; /** diff --git a/app/Models/Comment.php b/app/Models/Comment.php index afe9bbd..9229031 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -4,12 +4,21 @@ class Comment extends \Eloquent { protected $guarded = ['id']; + protected $hidden = [ + 'issue_id', + 'user_id', + ]; public function muhtar() { return $this->belongsTo(User::class, 'user_id'); } + public function user() + { + return $this->belongsTo(User::class, 'user_id'); + } + public function issue() { return $this->belongsTo(Issue::class, 'issue_id'); diff --git a/app/Models/Issue.php b/app/Models/Issue.php index edccab2..458e420 100644 --- a/app/Models/Issue.php +++ b/app/Models/Issue.php @@ -11,6 +11,9 @@ class Issue extends \Eloquent protected $guarded = ['id']; protected $dates = ['deleted_at']; + protected $hidden = [ + 'deleted_at', + ]; public function tags() { @@ -40,8 +43,8 @@ public function comments() public function toArray($user_id = null) { $array = parent::toArray(); - $array['supporter_counter'] = (int)Redis::get('supporter_counter:' . $this->id); - $array['is_supported'] = (((int)Redis::zscore('issue_supporters:' . $this->id, $user_id) > 0) ? 1 : 0); + //$array['supporter_counter'] = (int)Redis::get('supporter_counter:' . $this->id); + //$array['is_supported'] = (((int)Redis::zscore('issue_supporters:' . $this->id, $user_id) > 0) ? 1 : 0); return $array; } diff --git a/app/Models/IssueImage.php b/app/Models/IssueImage.php index 4545c89..eb5a5ed 100644 --- a/app/Models/IssueImage.php +++ b/app/Models/IssueImage.php @@ -4,4 +4,9 @@ class IssueImage extends \Eloquent { protected $guarded = ['id']; + protected $hidden = [ + 'created_at', + 'updated_at', + 'issue_id', + ]; } diff --git a/app/Models/IssueUpdate.php b/app/Models/IssueUpdate.php index 41abf21..3d9e1b1 100644 --- a/app/Models/IssueUpdate.php +++ b/app/Models/IssueUpdate.php @@ -4,5 +4,8 @@ class IssueUpdate extends \Eloquent { - + protected $hidden = [ + 'issue_id', + 'updated_at', + ]; } diff --git a/app/Models/Tag.php b/app/Models/Tag.php index 45df133..75cf2d7 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -1,17 +1,19 @@ id); - - return $array; + return DB::table('issue_tag')->where('tag_id', $this->id)->count(); } } diff --git a/app/Models/User.php b/app/Models/User.php index 520dce5..aec12c6 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -38,7 +38,24 @@ class User extends \Eloquent implements AuthenticatableContract * * @var array */ - protected $hidden = ['password', 'remember_token']; + protected $hidden = [ + 'password', + 'remember_token', + 'supported_issue_counter', + 'opened_issue_counter', + 'admin_type', + 'verify_token', + 'deleted_at', + 'phone', + 'password_token_expires_at', + 'password_reset_token', + 'coordinates', + 'location', + 'hood_id', + 'level', + 'updated_at', + 'created_at', + ]; protected $appends = ['full_name']; diff --git a/composer.json b/composer.json index a906278..7027ba6 100644 --- a/composer.json +++ b/composer.json @@ -51,15 +51,11 @@ "scripts": { "post-install-cmd": [ "php artisan clear-compiled", - "php artisan optimize", - "npm install", - "./node_modules/.bin/gulp --production" + "php artisan optimize" ], "post-update-cmd": [ "php artisan clear-compiled", - "php artisan optimize", - "npm install", - "./node_modules/.bin/gulp --production" + "php artisan optimize" ] } } diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 0000000..3053203 --- /dev/null +++ b/docker-compose-dev.yml @@ -0,0 +1,21 @@ +version: '3.1' +services: + muhitredis: + image: "redis:alpine" + ports: + - 6379/tcp + muhitdb: + image: mysql + command: --sql_mode="" --default-authentication-plugin=mysql_native_password + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: 11235 + MYSQL_DATABASE: muhit + MYSQL_USER: muhit + MYSQL_PASSWORD: 11235 + ports: + - "4306:3306" + muhitweb: + build: . + ports: + - "3000:80" diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..4ea9d32 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,75 @@ +worker_processes 1; +pid /run/nginx.pid; + +events { + worker_connections 5000; + multi_accept on; + use epoll; +} + +worker_rlimit_nofile 65000; + +http { + server_names_hash_bucket_size 64; + + include /etc/nginx/mime.types; + access_log off; + server_tokens off; + sendfile on; + tcp_nopush on; + keepalive_timeout 20; + tcp_nodelay on; + + reset_timedout_connection on; + client_body_timeout 20; + client_max_body_size 30M; + client_header_buffer_size 10K; + client_header_timeout 32; + + open_file_cache max=200000 inactive=20s; + open_file_cache_valid 30s; + open_file_cache_min_uses 2; + open_file_cache_errors on; + + gzip on; + gzip_disable "MSIE [1-6]\."; + gzip_min_length 256; + gzip_proxied any; + gzip_comp_level 4; + gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; + + server { + listen 80 default_server; + root /var/www/html/public; + index index.php; + + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With'; + + fastcgi_hide_header X-Powered-By; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.css { + add_header Content-Type text/css; + } + + location ~ \.js { + add_header Content-Type application/x-javascript; + } + + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass 127.0.0.1:9000; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_NAME $fastcgi_script_name; + fastcgi_index index.php; + include fastcgi_params; + } + } +} diff --git a/docker/php-uploads.ini b/docker/php-uploads.ini new file mode 100644 index 0000000..7fc73c5 --- /dev/null +++ b/docker/php-uploads.ini @@ -0,0 +1,5 @@ +file_uploads = On +memory_limit = 64M +upload_max_filesize = 64M +post_max_size = 64M +max_execution_time = 600 diff --git a/docker/supervisord.conf b/docker/supervisord.conf new file mode 100644 index 0000000..a196c54 --- /dev/null +++ b/docker/supervisord.conf @@ -0,0 +1,23 @@ +[supervisord] +nodaemon=true +logfile=/dev/null +pidfile=/var/run/supervisord.pid + +[program:php-fpm] +command=php-fpm -F +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +autorestart=true +startretries=0 + + +[program:nginx] +command=nginx -g 'daemon off;' +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +autorestart=true +startretries=0 diff --git a/storage/.gitignore b/storage/.gitignore old mode 100644 new mode 100755 diff --git a/storage/app/.gitignore b/storage/app/.gitignore old mode 100644 new mode 100755 diff --git a/storage/clockwork/.gitignore b/storage/clockwork/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/.gitignore b/storage/framework/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/.gitignore b/storage/framework/cache/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/sessions/.gitignore b/storage/framework/sessions/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/views/.gitignore b/storage/framework/views/.gitignore old mode 100644 new mode 100755 diff --git a/storage/logs/.gitignore b/storage/logs/.gitignore old mode 100644 new mode 100755