Skip to content

Commit

Permalink
feat: migrate to laravel 10
Browse files Browse the repository at this point in the history
  • Loading branch information
vermorag committed Mar 10, 2023
1 parent 4b2fca9 commit 0a26b5a
Show file tree
Hide file tree
Showing 37 changed files with 3,050 additions and 2,614 deletions.
16 changes: 0 additions & 16 deletions .env.docker

This file was deleted.

27 changes: 0 additions & 27 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
APP_NAME="Cattr"
APP_ENV=local
APP_KEY=
APP_DEBUG=true
JSON_ERRORS=true
APP_LOG_LEVEL=error
APP_URL=http://127.0.0.1:8000

REQUEST_SIGNATURE=_CHANGE_ME_

DB_CONNECTION=mysql
DB_PORT=3306
DB_HOST=localhost
DB_DATABASE=cattr
DB_USERNAME=root
DB_PASSWORD=password

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=database

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=mail
MAIL_SENDMAIL_PATH="/usr/sbin/sendmail -i -t"
MAIL_FROM_NAME="Cattr"
MAIL_FROM_ADDRESS=no-reply@cattr.local

MAIL_ADDRESS=example@mail.com
MAIL_PASS=password
MAIL_SERVER=smtp.mail.com
MAIL_PORT=465
MAIL_SECURITY=true

ALLOWED_ORIGINS=*
FRONTEND_APP_URL=

# ReCaptcha Settings
Expand Down
8 changes: 0 additions & 8 deletions .env.testing.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
APP_NAME="Cattr"
APP_ENV=testing
APP_KEY=
JWT_SECRET=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=cattr_tests
DB_USERNAME=root
DB_PASSWORD=secret
Expand All @@ -20,5 +14,3 @@ REQUEST_SIGNATURE=
RECAPTCHA_ENABLED=false

ALLOWED_ORIGINS=*

TELESCOPE_ENABLED=false
21 changes: 10 additions & 11 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ stages:
sast:
stage: test

sentry:
sentry_upload:
image: getsentry/sentry-cli:latest
stage: release
only:
- tags
rules:
- if: $CI_COMMIT_TAG && $SENTRY_ORG
- if: $SENTRY_ORG
before_script:
- export DOCKER_TAG=$(echo "$CI_COMMIT_REF_NAME" | sed 's/^v//g')
script:
Expand All @@ -39,21 +41,18 @@ build:
--build-arg "SENTRY_DSN=$SENTRY_DSN"
--build-arg "APP_VERSION=$DOCKER_TAG"
mark_release:
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:20
tag_latest:
image:
name: gcr.io/go-containerregistry/crane:debug
entrypoint: [""]
stage: release
only:
- tags
services:
- name: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:20-dind
alias: docker
before_script:
- echo $CI_REGISTRY_PASSWORD | docker login --username $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- export DOCKER_TAG=$(echo "$CI_COMMIT_REF_NAME" | sed 's/^v//g')
script:
- docker pull $CI_REGISTRY_IMAGE:$DOCKER_TAG
- docker image tag $CI_REGISTRY_IMAGE:$DOCKER_TAG $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:latest
- crane tag $CI_REGISTRY_IMAGE:$DOCKER_TAG latest

deploy_prod:
stage: deploy
Expand Down
81 changes: 29 additions & 52 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,55 +1,15 @@
FROM composer:2.3.5 as composer
# syntax=docker/dockerfile:1-labs
FROM registry.git.amazingcat.net/cattr/core/wolfi-os-image/cattr-dev AS builder

FROM php:8.1-alpine AS runtime

ARG SENTRY_DSN
ARG APP_VERSION
ARG APP_ENV=production
ARG MODULES="cattr/gitlab_integration-module cattr/redmine_integration-module"
ENV IMAGE_VERSION=4.1.0
ENV APP_VERSION $APP_VERSION
ENV SENTRY_DSN $SENTRY_DSN
ENV APP_ENV $APP_ENV

RUN set -x && \
apk add --no-cache icu-libs zlib libpng libzip libjpeg libcurl bash && \
apk add --no-cache --virtual .build-deps \
autoconf \
openssl \
make \
g++ \
zlib-dev \
libpng-dev \
libzip-dev \
libjpeg-turbo-dev \
icu-dev \
curl-dev && \
docker-php-ext-configure gd --with-jpeg && \
CFLAGS="$CFLAGS -D_GNU_SOURCE" docker-php-ext-install -j$(nproc) \
gd \
zip \
intl \
pcntl \
pdo_mysql && \
printf "\n\n\nyes\nyes\nyes\n" | pecl install swoole-4.8.9 && \
docker-php-ext-enable swoole && \
wget -q "https://github.com/aptible/supercronic/releases/download/v0.1.12/supercronic-linux-amd64" \
-O /usr/bin/supercronic && \
chmod +x /usr/bin/supercronic && \
docker-php-source delete && \
apk del .build-deps && \
rm -R /tmp/pear && \
mkdir /app && \
echo '* * * * * php /app/artisan schedule:run' > /app/crontab && \
chown -R www-data:www-data /app

USER www-data:www-data
COPY php.ini /php/php.ini

COPY --from=composer /usr/bin/composer /usr/local/bin/composer
WORKDIR /app

COPY php.ini /usr/local/etc/php/php.ini
RUN echo '* * * * * php /app/artisan schedule:run' > /crontab

WORKDIR /app
USER www-data:www-data

COPY --chown=www-data:www-data ./composer.* /app/

Expand All @@ -59,16 +19,33 @@ RUN composer require -n --no-install --no-ansi $MODULES && \
COPY --chown=www-data:www-data . /app

RUN set -x && \
cp .env.docker storage/.env && \
composer dump-autoload -n --optimize && \
php artisan storage:link

VOLUME /app/storage
VOLUME /app/Modules
FROM registry.git.amazingcat.net/cattr/core/wolfi-os-image/cattr AS runtime

ARG SENTRY_DSN
ARG APP_VERSION
ARG APP_ENV=production
ARG APP_KEY="base64:PU/8YRKoMdsPiuzqTpFDpFX1H8Af74nmCQNFwnHPFwY="
ENV IMAGE_VERSION=5.0.0
ENV DB_CONNECTION=mysql
ENV DB_HOST=db
ENV DB_USERNAME=root
ENV DB_PASSWORD=password
ENV APP_VERSION $APP_VERSION
ENV SENTRY_DSN $SENTRY_DSN
ENV APP_ENV $APP_ENV
ENV APP_KEY $APP_KEY

ENTRYPOINT ["/app/start"]
COPY --from=builder /app /app

COPY php.ini /php/php.ini

VOLUME /app/storage
VOLUME /app/bootstrap/cache

HEALTHCHECK --interval=5m --timeout=10s \
CMD wget --spider -q "http://127.0.0.1:8090/status"
#HEALTHCHECK --interval=5m --timeout=10s \
# CMD wget --spider -q "http://127.0.0.1:8090/status"

EXPOSE 8090
24 changes: 24 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ class Handler extends ExceptionHandler
{
use ConvertsExceptions;

/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [
//
];

/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<\Throwable>>
*/
protected $dontReport
= [
AuthenticationException::class,
Expand All @@ -35,6 +49,16 @@ class Handler extends ExceptionHandler
PDOException::class,
];

/**
* A list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
public function register(): void
{
$this->reportable(function (Throwable $e) {
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Str;
use Psr\SimpleCache\InvalidArgumentException;

class AuthController extends BaseController
{
Expand Down Expand Up @@ -265,7 +264,6 @@ public function issueDesktopKey(Request $request): JsonResponse
*
* @return JsonResponse
* @throws Exception
* @throws InvalidArgumentException
*/
public function authDesktopKey(Request $request): JsonResponse
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Http\Middleware\Authenticate;
use App\Http\Middleware\SentryContext;
use App\Http\Middleware\TrimStrings;
use Fruitcake\Cors\HandleCors;
use Illuminate\Http\Middleware\HandleCors;
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
Expand Down
14 changes: 6 additions & 8 deletions app/Models/TimeInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
use App\Scopes\TimeIntervalAccessScope;
use Database\Factories\TimeIntervalFactory;
use Eloquent as EloquentIdeHelper;
use Grimzy\LaravelMysqlSpatial\Eloquent\Builder;
use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;
use Grimzy\LaravelMysqlSpatial\Types\Point;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -20,6 +17,9 @@
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Carbon;
use Storage;
use MatanYadaev\EloquentSpatial\SpatialBuilder as Builder;
use MatanYadaev\EloquentSpatial\Objects\Point;
use MatanYadaev\EloquentSpatial\Traits\HasSpatial;

/**
* @apiDefine TimeIntervalObject
Expand Down Expand Up @@ -127,7 +127,7 @@ class TimeInterval extends Model
{
use SoftDeletes;
use HasFactory;
use SpatialTrait;
use HasSpatial;

/**
* table name from database
Expand Down Expand Up @@ -160,6 +160,7 @@ class TimeInterval extends Model
'mouse_fill' => 'integer',
'keyboard_fill' => 'integer',
'is_manual' => 'boolean',
'location' => Point::class,
];

/**
Expand All @@ -174,9 +175,6 @@ class TimeInterval extends Model
];

protected $appends = ['has_screenshot'];
protected array $spatialFields = [
'location'
];

/**
* Override parent boot and Call deleting event
Expand Down Expand Up @@ -221,7 +219,7 @@ public function hasScreenshot(): Attribute
public function location(): Attribute
{
return Attribute::make(
get: static fn($value) => $value ? ['lat' => $value->getLat(), 'lng' => $value->getLng()] : null,
get: static fn($value) => $value ? ['lat' => $value->latitude, 'lng' => $value->longitude] : null,
set: static fn($value) => $value ? new Point($value['lat'], $value['lng']) : null,
)->shouldCache();
}
Expand Down
6 changes: 3 additions & 3 deletions artisan
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define('LARAVEL_START', microtime(true));
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
| loading of any of our classes manually. It's great to relax.
|
*/

Expand All @@ -33,8 +33,8 @@ $app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);

/*
Expand Down
4 changes: 0 additions & 4 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
App\Exceptions\Handler::class
);

if (env('IMAGE_VERSION', false)) {
$app->useEnvironmentPath(storage_path());
}

/*
|--------------------------------------------------------------------------
| Return The Application
Expand Down
17 changes: 0 additions & 17 deletions bootstrap/autoload.php

This file was deleted.

Loading

0 comments on commit 0a26b5a

Please sign in to comment.