Skip to content

Commit f7de503

Browse files
TatevikGrtatevikg1
andauthored
Add Docker setup and CI/CD improvements (#107)
* dev version * Add docker * Update port * Add: gitattributes file * Fix: github pipeline * Add postgres * Fix missing web-frontend * CodeRabbit config * Use main branches * After review 0 * Env --------- Co-authored-by: Tatevik <tatevikg1@gmail.com>
1 parent 0d40429 commit f7de503

File tree

10 files changed

+2267
-794
lines changed

10 files changed

+2267
-794
lines changed

.coderabbit.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: "en-US"
2+
reviews:
3+
profile: "chill"
4+
high_level_summary: true
5+
poem: false
6+
auto_review:
7+
enabled: true
8+
base_branches:
9+
- ".*"
10+
drafts: false

.dockerignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Docker build context exclusions
2+
.git
3+
.gitignore
4+
.github
5+
.idea
6+
.vscode
7+
node_modules
8+
npm-debug.log
9+
yarn.lock
10+
composer.phar
11+
var/cache
12+
var/logs
13+
var/sessions
14+
.env
15+
Dockerfile*
16+
docker-compose*.yml
17+
**/.DS_Store
18+
**/Thumbs.db
19+
vendor/

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Exclude tests and development stuff from archives
2+
/tests export-ignore
3+
/.github export-ignore

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,3 @@
11
### Summary
22

3-
Provide a general description of the code changes in your pull request …
4-
were there any bugs you had fixed? If so, mention them. If these bugs have open
5-
GitHub issues, be sure to tag them here as well, to keep the conversation
6-
linked together.
7-
8-
9-
### Unit test
10-
11-
Are your changes covered with unit tests, and do they not break anything?
12-
13-
You can run the existing unit tests using this command:
14-
15-
vendor/bin/phpunit tests/
16-
17-
18-
### Code style
19-
20-
Have you checked that you code is well-documented and follows the PSR-2 coding
21-
style?
22-
23-
You can check for this using this command:
24-
25-
vendor/bin/phpcs --standard=PSR2 src/ tests/
26-
27-
28-
### Other Information
29-
30-
If there's anything else that's important and relevant to your pull
31-
request, mention that information here. This could include benchmarks,
32-
or other information.
33-
34-
If you are updating any of the CHANGELOG files or are asked to update the
35-
CHANGELOG files by reviewers, please add the CHANGELOG entry at the top of the file.
36-
373
Thanks for contributing to phpList!

.github/workflows/ci.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ on: [push, pull_request]
33
jobs:
44
main:
55
name: phpList Base Dist on PHP ${{ matrix.php-versions }}, with dist ${{ matrix.dependencies }} [Build, Test]
6-
runs-on: ubuntu-20.04
6+
runs-on: ubuntu-22.04
77
env:
88
DB_DATABASE: phplist
99
DB_USERNAME: root
1010
DB_PASSWORD: phplist
11-
BROADCAST_DRIVER: log
11+
BROADCAST_DRIVER: log
1212
services:
1313
mysql:
1414
image: mysql:5.7
@@ -63,7 +63,13 @@ jobs:
6363
- name: Run integration tests with phpunit
6464
run: vendor/bin/phpunit tests/Integration/
6565
- name: Running the system tests
66-
run: vendor/bin/phpunit tests/System/;
66+
run: |
67+
export PHPLIST_DATABASE_NAME=${{ env.DB_DATABASE }}
68+
export PHPLIST_DATABASE_USER=${{ env.DB_USERNAME }}
69+
export PHPLIST_DATABASE_PASSWORD=${{ env.DB_PASSWORD }}
70+
export PHPLIST_DATABASE_PORT=${{ job.services.mysql.ports['3306'] }}
71+
export PHPLIST_DATABASE_HOST=127.0.0.1
72+
vendor/bin/phpunit tests/System/
6773
- name: Running static analysis
6874
run: vendor/bin/phpstan analyse -l 5 src/ tests/;
6975
- name: Running PHPMD

Dockerfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Build a production image for phpList base-distribution (Symfony-based)
4+
FROM php:8.1-apache-bullseye
5+
6+
# Set workdir
7+
WORKDIR /var/www/html
8+
9+
# Install system dependencies and PHP extensions
10+
RUN apt-get update \
11+
&& apt-get install -y --no-install-recommends \
12+
git unzip libzip-dev libicu-dev libpng-dev libonig-dev libxml2-dev \
13+
libc-client2007e-dev libkrb5-dev libssl-dev libpq-dev \
14+
&& docker-php-ext-configure intl \
15+
&& docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
16+
&& docker-php-ext-install -j"$(nproc)" \
17+
pdo pdo_mysql pdo_pgsql zip intl imap \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Enable Apache modules and set DocumentRoot to /public
21+
RUN a2enmod rewrite headers \
22+
&& sed -ri 's!/var/www/html!/var/www/html/public!g' /etc/apache2/sites-available/000-default.conf \
23+
&& sed -ri 's!/var/www/!/var/www/html/public!g' /etc/apache2/apache2.conf \
24+
&& echo "<Directory /var/www/html/public>\n AllowOverride All\n Require all granted\n</Directory>" > /etc/apache2/conf-available/phplist.conf \
25+
&& a2enconf phplist
26+
27+
# Copy composer definition first and install dependencies
28+
COPY composer.json composer.lock ./
29+
30+
# Install Composer
31+
ENV COMPOSER_ALLOW_SUPERUSER=1 \
32+
PATH="/usr/local/bin:${PATH}"
33+
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
34+
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
35+
&& rm composer-setup.php
36+
37+
# Ensure config directory exists for Composer scripts that write into it
38+
COPY config ./config
39+
40+
# Install PHP dependencies (include scripts so phpList creates config structure)
41+
RUN composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
42+
43+
# Copy the rest of the application (except files ignored by .dockerignore)
44+
COPY . .
45+
46+
# Build Symfony prod cache to match the current vendor code (prevents stale container issues)
47+
# If env vars are needed for DB during warmup, they can be provided at runtime; warmup should still succeed without DB.
48+
RUN php bin/console cache:clear --env=prod --no-warmup || true \
49+
&& php bin/console cache:warmup --env=prod || true
50+
51+
# Ensure correct permissions for cache/logs
52+
RUN chown -R www-data:www-data var public \
53+
&& find var -type d -exec chmod 775 {} \; \
54+
&& find var -type f -exec chmod 664 {} \;
55+
56+
# Expose port and run Apache
57+
EXPOSE 80
58+
CMD ["apache2-foreground"]

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,36 @@ contribute and how to run the unit tests and style checks locally.
176176
This project adheres to a [Contributor Code of Conduct](CODE_OF_CONDUCT.md).
177177
By participating in this project and its community, you are expected to uphold
178178
this code.
179+
180+
181+
## Docker deployment
182+
183+
The project includes a Docker setup to run phpList with Apache and MySQL.
184+
185+
Quick start (development/test):
186+
187+
- Build and start the stack: `docker compose up --build`
188+
- Open [http://localhost:8081](http://localhost:8081)
189+
190+
The app container is configured to read database settings from environment variables that match config/parameters.yml defaults. The provided docker-compose.yml sets:
191+
192+
- PHPLIST_DATABASE_HOST=db
193+
- PHPLIST_DATABASE_PORT=3306
194+
- PHPLIST_DATABASE_NAME=phplistdb
195+
- PHPLIST_DATABASE_USER=phplist
196+
- PHPLIST_DATABASE_PASSWORD=phplist
197+
198+
Notes:
199+
200+
- For production deployments, build and push the image, then run it behind a reverse proxy or load balancer. Example:
201+
- `docker build -t your-registry/phplist-base:latest .`
202+
- `docker run -p 8080:80 --env PHPLIST_DATABASE_HOST=... --env PHPLIST_DATABASE_NAME=... --env PHPLIST_DATABASE_USER=... --env PHPLIST_DATABASE_PASSWORD=... your-registry/phplist-base:latest`
203+
- Persist the MySQL data using the db_data volume defined in docker-compose.yml, or bind mount your own volume.
204+
- You can also mount ./var to persist logs/cache between restarts. See commented volume in docker-compose.yml.
205+
- The container uses Apache with DocumentRoot set to /var/www/html/public and mod_rewrite enabled.
206+
- The base image uses PHP 8.1 (php:8.1-apache-bullseye) to match the Composer constraint (^8.1) and to ensure the IMAP build dependencies are available. You can bump to a newer 8.x tag (e.g., 8.3) if your deployment prefers it, but ensure IMAP build deps are present for that base.
207+
208+
209+
```bash
210+
docker exec -it base-distribution-app bash
211+
```

composer.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@
3636
{
3737
"type": "vcs",
3838
"url": "https://github.com/tatevikgr/phplist-api-client"
39+
},
40+
{
41+
"type": "vcs",
42+
"url": "https://github.com/tatevikgr/rss-bundle.git"
3943
}
4044
],
4145
"require": {
4246
"php": "^8.1",
4347
"phplist/core": "dev-main",
4448
"phplist/rest-api": "dev-main",
45-
"phplist/web-frontend": "dev-master",
49+
"phplist/web-frontend": "dev-main",
4650
"doctrine/orm": "^3.3",
47-
"tatevikgr/rest-api-client": "dev-ISSUE-357"
51+
"tatevikgr/rest-api-client": "dev-ISSUE-357",
52+
"tatevikgr/rss-feed": "dev-main as 0.1.0"
4853
},
4954
"require-dev": {
5055
"phpunit/phpunit": "^9.5.2",
@@ -103,5 +108,10 @@
103108
"symfony-var-dir": "var",
104109
"symfony-web-dir": "public",
105110
"symfony-tests-dir": "tests"
111+
},
112+
"config": {
113+
"allow-plugins": {
114+
"php-http/discovery": true
115+
}
106116
}
107117
}

0 commit comments

Comments
 (0)