Skip to content

Commit 5677507

Browse files
CICD tweaks
1 parent a5d1228 commit 5677507

File tree

18 files changed

+105
-70
lines changed

18 files changed

+105
-70
lines changed

.github/workflows/action.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ on:
77
branches: [ main, master ]
88

99
jobs:
10+
cs-check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Setup PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: '8.3'
19+
20+
- name: Install Dependencies
21+
run: composer install --no-interaction --prefer-dist --ignore-platform-reqs
22+
23+
- name: Run PHP CS Fixer
24+
run: vendor/bin/php-cs-fixer fix --dry-run
25+
1026
build:
1127
runs-on: ubuntu-latest
1228
steps:
@@ -33,22 +49,15 @@ jobs:
3349
- name: Wait for services to be ready
3450
run: |
3551
echo "Waiting for services to start..."
36-
sleep 30
52+
sleep 5
3753
docker compose ps
3854
39-
- name: Run migrations
40-
run: docker compose exec -T php php bin/app.php migrate --force
41-
42-
- name: Refresh caches
43-
run: make refresh-caches
44-
4555
- name: Cleanup
4656
if: always()
4757
run: make down
4858

4959
test:
5060
runs-on: ubuntu-latest
51-
needs: build
5261
steps:
5362
- uses: actions/checkout@v4
5463

@@ -67,15 +76,12 @@ jobs:
6776
- name: Wait for services to be ready
6877
run: |
6978
echo "Waiting for services to start..."
70-
sleep 30
79+
sleep 5
7180
docker compose ps
7281
7382
- name: Run migrations
7483
run: docker compose exec -T php php bin/app.php migrate --force
7584

76-
- name: Refresh caches
77-
run: make refresh-caches
78-
7985
- name: Install curl and jq
8086
run: sudo apt-get update && sudo apt-get install -y curl jq
8187

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ seed:
4545
docker-compose exec php php bin/app.php events:seed
4646

4747
cs-check:
48-
docker compose exec php php-cs-fixer fix --dry-run --diff
48+
docker compose exec php php-cs-fixer fix --dry-run
4949

5050
cs-fix:
5151
docker compose exec php php-cs-fixer fix

bin/app.php

100644100755
File mode changed.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "app/analytics",
2+
"name": "bemyslavedarlin/collider",
33
"type": "project",
44
"description": "RESTful API on Spiral Framework with Swoole",
55
"require": {

docker/php/Dockerfile

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,12 @@
1-
FROM php:8.3-cli AS php_base
1+
FROM bemyslavedarlin/collider:1.0 AS php_base
22

33
ARG APP_PORT=9501
44
ARG TIMEZONE=UTC
55

6-
RUN apt-get update && apt-get install -y \
7-
zlib1g-dev libpq-dev libzip-dev libbrotli-dev \
8-
libonig-dev libxslt1-dev libicu-dev libpq-dev \
9-
mc nano make git curl wget unzip \
10-
&& rm -rf /var/lib/apt/lists/*
11-
12-
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone \
13-
&& printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > $PHP_INI_DIR/conf.d/tzone.ini
14-
15-
RUN docker-php-ext-install \
16-
pdo pdo_pgsql pgsql sockets \
17-
zip pcntl mbstring bcmath
18-
19-
RUN pecl update-channels \
20-
&& pecl install swoole redis \
21-
&& docker-php-ext-enable swoole redis
22-
236
ENV COMPOSER_ALLOW_SUPERUSER=1
247
ENV COMPOSER_HOME=/tmp
25-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
26-
278
ENV PATH=/usr/local/bin:/app/vendor/bin:/app/bin:${PATH}
289

29-
COPY . /app
30-
31-
RUN chmod +x /app/bin/app.php \
32-
&& chmod +x /app/bin/http.php
33-
3410
WORKDIR /app
3511

3612
EXPOSE ${APP_PORT}

docker/php/Dockerfile-full

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM php:8.3-cli AS php_base
2+
3+
ARG APP_PORT=9501
4+
ARG TIMEZONE=UTC
5+
6+
RUN apt-get update && apt-get install -y \
7+
zlib1g-dev libpq-dev libzip-dev \
8+
libbrotli-dev libonig-dev libpq-dev \
9+
mc nano make git curl wget unzip \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone \
13+
&& printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > $PHP_INI_DIR/conf.d/tzone.ini
14+
15+
RUN docker-php-ext-install \
16+
pdo pdo_pgsql pgsql sockets \
17+
zip pcntl mbstring
18+
19+
RUN pecl update-channels \
20+
&& pecl install swoole redis \
21+
&& docker-php-ext-enable swoole redis
22+
23+
ENV COMPOSER_ALLOW_SUPERUSER=1
24+
ENV COMPOSER_HOME=/tmp
25+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
26+
27+
ENV PATH=/usr/local/bin:/app/vendor/bin:/app/bin:${PATH}
28+
29+
WORKDIR /app
30+
31+
EXPOSE ${APP_PORT}
32+
33+
FROM php_base AS php_dev
34+
35+
ENV APP_ENV=dev
36+
37+
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
38+
COPY docker/php/conf.d/php.dev.ini $PHP_INI_DIR/conf.d/99-app.ini
39+
40+
FROM php_base AS php_prod
41+
42+
ENV APP_ENV=prod
43+
44+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
45+
COPY docker/php/conf.d/php.prod.ini $PHP_INI_DIR/conf.d/99-app.ini
46+
47+
FROM php_base AS composer_dev
48+
49+
CMD composer install \
50+
&& composer dump-autoload --classmap-authoritative
51+
52+
FROM php_base AS composer_prod
53+
54+
CMD composer install --no-dev --optimize-autoloader \
55+
&& composer dump-autoload --classmap-authoritative --no-dev

src/Application/Bootloader/AppBootloader.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
use Spiral\Interceptors\HandlerInterface;
1414
use Swoole\Runtime;
1515

16-
use function extension_loaded;
17-
1816
final class AppBootloader extends DomainBootloader
1917
{
2018
protected const array SINGLETONS = [HandlerInterface::class => [self::class, 'domainCore']];
@@ -41,7 +39,7 @@ public function defineSingletons(): array
4139
*/
4240
public function init(Container $container, EnvironmentInterface $env): void
4341
{
44-
if (!extension_loaded('swoole')) {
42+
if (!\extension_loaded('swoole')) {
4543
throw new ErrorException('Swoole extension is required but not loaded');
4644
}
4745

src/Domain/UserAnalytics/Repository/CachedEventRepository.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function findByUserId(int $uid, int $limit = 1000): array
2424
{
2525
return $this->cache->remember(
2626
"events:uid:{$uid}",
27-
fn() => $this->repository->findByUserId($uid, $limit),
27+
fn () => $this->repository->findByUserId($uid, $limit),
2828
self::DEFAULT_TTL
2929
);
3030
}
@@ -33,7 +33,7 @@ public function findWithPagination(int $limit, int $offset): array
3333
{
3434
return $this->cache->remember(
3535
"events:page:{$limit}:{$offset}",
36-
fn() => $this->repository->findWithPagination($limit, $offset),
36+
fn () => $this->repository->findWithPagination($limit, $offset),
3737
self::DEFAULT_TTL
3838
);
3939
}
@@ -42,7 +42,7 @@ public function findBeforeDate(DateTimeInterface $date): int
4242
{
4343
return $this->cache->remember(
4444
"events:before:{$date->getTimestamp()}",
45-
fn() => $this->repository->findBeforeDate($date),
45+
fn () => $this->repository->findBeforeDate($date),
4646
self::DEFAULT_TTL
4747
);
4848
}
@@ -57,16 +57,16 @@ public function getStats(
5757

5858
return $this->cache->remember(
5959
"events:stats:{$suffix}",
60-
fn() => $this->repository->getStats($limit, $from, $to, $eventTypeId),
60+
fn () => $this->repository->getStats($limit, $from, $to, $eventTypeId),
6161
self::DEFAULT_TTL
6262
);
6363
}
6464

6565
public function countAll(): int
6666
{
6767
return $this->cache->remember(
68-
"events:count:all",
69-
fn() => $this->repository->countAll(),
68+
'events:count:all',
69+
fn () => $this->repository->countAll(),
7070
self::DEFAULT_TTL
7171
);
7272
}
@@ -91,6 +91,6 @@ public function delete(Event $event): void
9191

9292
public function invalidateCache(): void
9393
{
94-
$this->cache->deleteBatch("events:*");
94+
$this->cache->deleteBatch('events:*');
9595
}
9696
}

src/Domain/UserAnalytics/Repository/CachedEventTypeRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function findById(int $id): ?EventTypeEntityInterface
2525
{
2626
return $this->cache->remember(
2727
"event_type:id:{$id}",
28-
fn() => $this->repository->findById($id),
28+
fn () => $this->repository->findById($id),
2929
self::DEFAULT_TTL,
3030
[$this, 'typeFromArray']
3131
);
@@ -35,7 +35,7 @@ public function findByName(string $name): ?EventTypeEntityInterface
3535
{
3636
return $this->cache->remember(
3737
"event_type:name:{$name}",
38-
fn() => $this->repository->findByName($name),
38+
fn () => $this->repository->findByName($name),
3939
self::DEFAULT_TTL,
4040
[$this, 'typeFromArray']
4141
);

src/Domain/UserAnalytics/Repository/CachedUserRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function findById(int $id): ?UserEntityInterface
2525
{
2626
return $this->cache->remember(
2727
"user:id:{$id}",
28-
fn() => $this->repository->findById($id),
28+
fn () => $this->repository->findById($id),
2929
self::DEFAULT_TTL,
3030
[$this, 'userFromArray']
3131
);
@@ -35,7 +35,7 @@ public function findByName(string $name): ?UserEntityInterface
3535
{
3636
return $this->cache->remember(
3737
"user:name:{$name}",
38-
fn() => $this->repository->findByName($name),
38+
fn () => $this->repository->findByName($name),
3939
self::DEFAULT_TTL,
4040
[$this, 'userFromArray']
4141
);

0 commit comments

Comments
 (0)