Skip to content

Commit cd23633

Browse files
committed
Setup CRUD
1 parent 9aa2a7a commit cd23633

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4877
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/.idea/
55
/.vscode/
66
/build/
7+
ab*.log
8+
*.log

Dockerfile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
FROM php:8.2-cli AS build
2+
3+
# --- System deps ---
4+
RUN apt-get update && apt-get install -y \
5+
git unzip libpq-dev libssl-dev libzip-dev zlib1g-dev \
6+
libbrotli-dev libsqlite3-dev autoconf build-essential \
7+
libcurl4-openssl-dev pkg-config libc-ares-dev \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# --- Build Swoole from source with Redis + full features ---
11+
ENV SWOOLE_VERSION=5.1.3
12+
RUN docker-php-ext-install sockets
13+
RUN git clone -b v${SWOOLE_VERSION} https://github.com/swoole/swoole-src.git /usr/src/swoole \
14+
&& cd /usr/src/swoole \
15+
&& phpize \
16+
&& ./configure \
17+
--enable-openssl \
18+
--enable-http2 \
19+
--enable-swoole-curl \
20+
--enable-sockets \
21+
--enable-cares \
22+
--enable-redis \
23+
&& make -j$(nproc) && make install \
24+
&& docker-php-ext-enable swoole
25+
26+
# --- PHP extensions ---
27+
RUN docker-php-ext-install pdo pdo_mysql pdo_sqlite
28+
29+
# --- phpredis ---
30+
RUN pecl install redis \
31+
&& docker-php-ext-enable redis
32+
33+
# --- Composer ---
34+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
35+
36+
37+
# ================= Runtime =================
38+
FROM php:8.2-cli
39+
40+
# Runtime system deps
41+
RUN apt-get update && apt-get install -y \
42+
unzip git libbrotli-dev libpq-dev libssl-dev libzip-dev zlib1g-dev \
43+
libsqlite3-dev libcurl4-openssl-dev pkg-config libc-ares-dev \
44+
&& rm -rf /var/lib/apt/lists/*
45+
46+
# Copy compiled PHP extensions + config
47+
COPY --from=build /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
48+
COPY --from=build /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
49+
COPY --from=build /usr/bin/composer /usr/bin/composer
50+
51+
WORKDIR /app
52+
53+
# --- Composer install ---
54+
# Copy composer.json first (required)
55+
COPY composer.json ./
56+
57+
# Copy composer.lock only if it exists
58+
# (avoids build failure when no lock file is present)
59+
RUN if [ -f composer.lock ]; then cp composer.lock composer.lock; fi
60+
61+
RUN composer install --no-dev --optimize-autoloader || true
62+
63+
COPY docker/php/php.ini /usr/local/etc/php/conf.d/zz-preload.ini
64+
# Copy app source
65+
COPY . .
66+
67+
# Ensure logs dir
68+
RUN mkdir -p /app/logs
69+
70+
EXPOSE 9501 9310 9502
71+
72+
CMD ["php","public/index.php"]

composer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "rxcod9/php-swoole-crud-microservice",
3+
"description": "PHP Swoole CRUD Microservice",
4+
"type": "project",
5+
"license": "MIT",
6+
"require": {
7+
"monolog/monolog": "^3.6",
8+
"promphp/prometheus_client_php": "^2.10"
9+
},
10+
"require-dev": {
11+
"phpmd/phpmd": "^2.15",
12+
"phpstan/phpstan": "^2.1",
13+
"phpunit/phpunit": "^10",
14+
"squizlabs/php_codesniffer": "^3.13"
15+
},
16+
"scripts": {
17+
"start": "php public/index.php",
18+
"test": "vendor/bin/phpunit",
19+
"cs": "vendor/bin/phpcs -p --standard=phpcs.xml",
20+
"cbf": "vendor/bin/phpcbf -p --standard=phpcs.xml"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"App\\": "src/"
25+
}
26+
},
27+
"config": {
28+
"optimize-autoloader": true,
29+
"sort-packages": true
30+
},
31+
"minimum-stability": "stable",
32+
"prefer-stable": true,
33+
"authors": [
34+
{
35+
"name": "Ramakant Gangwar",
36+
"email": "14928642+rxcod9@users.noreply.github.com"
37+
}
38+
]
39+
}

0 commit comments

Comments
 (0)