Skip to content

Commit a2de630

Browse files
authored
Add Dockerfile (#3)
* Add Dockerfile * Update github action * Add chmod +x with git on entrypoint.sh
1 parent cbfd181 commit a2de630

17 files changed

Lines changed: 248 additions & 124 deletions

‎.dockerignore‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Git
2+
.git
3+
4+
# IntelliJ
5+
.idea
6+
*.iml
7+
8+
# Composer
9+
vendor
10+
11+
# PHP code sniffer
12+
.php_cs.cache
13+
14+
# PHP Unit
15+
build
16+
.phpunit.result.cache
17+
18+
# Dev / Testing
19+
test.php
20+
coverage/*

‎.editorconfig‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file is for unifying the coding style for different editors and IDEs.
2+
# More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[Dockerfile]
15+
indent_size = 2
16+
17+
[*.md]
18+
trim_trailing_whitespace = false

‎.github/dependabot.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "composer"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
time: "08:00"
8+
timezone: "Europe/Paris"
9+
- package-ecosystem: "github-actions"
10+
directory: "/"
11+
schedule:
12+
interval: "daily"
13+
time: "08:00"
14+
timezone: "Europe/Paris"

‎.github/workflows/test.yml‎

Lines changed: 19 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,24 @@
11
name: test
22

33
on:
4-
push:
5-
pull_request:
4+
push:
5+
pull_request:
66

77
jobs:
8-
test:
9-
runs-on: ${{ matrix.os }}
10-
strategy:
11-
fail-fast: false
12-
matrix:
13-
os:
14-
- ubuntu-latest
15-
16-
services:
17-
mysql:
18-
image: mysql:5.7
19-
env:
20-
MYSQL_ALLOW_EMPTY_PASSWORD: yes
21-
MYSQL_USER: root
22-
MYSQL_PASSWORD: ''
23-
MYSQL_DATABASE: test_database
24-
ports:
25-
- 3306:3306
26-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
27-
28-
redis:
29-
image: redis
30-
options: >-
31-
--health-cmd "redis-cli ping"
32-
--health-interval 10s
33-
--health-timeout 5s
34-
--health-retries 5
35-
ports:
36-
- 6379:6379
37-
38-
steps:
39-
- name: Verify MySQL connection from host
40-
run: |
41-
sudo apt-get install -y mysql-client
42-
mysql --host 127.0.0.1 --port 3306 -uroot --password="" -e "SHOW DATABASES"
43-
44-
- uses: actions/checkout@v2
45-
46-
- uses: shivammathur/setup-php@v2
47-
with:
48-
php-version: '7.4'
49-
coverage: xdebug
50-
51-
- name: Set files permission
52-
run: |
53-
sudo chown -R www-data:www-data /var/lib/php/sessions/
54-
sudo chmod -R 777 /var/lib/php/sessions/
55-
56-
- name: Validate composer.json and composer.lock
57-
run: composer validate
58-
59-
- name: Cache Composer packages
60-
id: composer-cache
61-
uses: actions/cache@v2
62-
with:
63-
path: vendor
64-
key: ${{ runner.os }}-node-${{ hashFiles('**/composer.lock') }}
65-
restore-keys: |
66-
${{ runner.os }}-node-
67-
68-
- name: Install dependencies
69-
if: steps.composer-cache.outputs.cache-hit != 'true'
70-
run: composer install --prefer-dist --no-progress --no-suggest
71-
72-
- name: PHPCS
73-
if: ${{ runner.os != 'Windows' }}
74-
run: |
75-
vendor/bin/php-cs-fixer fix --diff --dry-run
76-
77-
- name: PHPUnit
78-
run: |
79-
vendor/bin/phpunit --colors --coverage-text --coverage-clover coverage/clover.xml
80-
env:
81-
MYSQL_HOST: 127.0.0.1
82-
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
83-
MYSQL_USER: root
84-
MYSQL_PASSWORD:
85-
86-
- name: Upload coverage
87-
uses: codecov/codecov-action@v1.0.7
88-
if: success()
89-
with:
90-
token: ${{ secrets.CODECOV_TOKEN }}
91-
file: ./coverage/clover.xml
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
- name: Pull
14+
run: docker-compose pull --quiet
15+
- name: Build
16+
run: docker-compose build
17+
- name: Test
18+
run: docker-compose run lib composer ci
19+
- name: Upload coverage
20+
uses: codecov/codecov-action@v1.0.14
21+
if: success()
22+
with:
23+
token: ${{ secrets.CODECOV_TOKEN }}
24+
file: ./coverage/clover.xml

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ build/
1414

1515
# Dev / Testing
1616
test.php
17-
coverage/
17+
coverage/*
18+
!coverage/.gitkeep

‎Dockerfile‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARG PHPVERSION="7.4"
2+
FROM php:$PHPVERSION-cli-alpine
3+
4+
RUN apk --update --no-cache add \
5+
mysql-client \
6+
&& rm -rf /tmp/* /var/cache/apk/*
7+
8+
RUN docker-php-ext-install \
9+
pdo_mysql
10+
11+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
12+
13+
WORKDIR /app
14+
15+
COPY composer.json .
16+
COPY composer.lock .
17+
RUN composer validate
18+
RUN composer install --no-interaction --no-progress --no-suggest
19+
20+
COPY . .
21+
22+
ENTRYPOINT ["./entrypoint.sh"]

‎README.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,4 @@ composer require predis/predis
196196
```
197197

198198
## How to Dev
199-
`composer ci` for php-cs-fixer and phpunit and coverage
200-
`composer lint` for php-cs-fixer
201-
`composer test` for phpunit and coverage
199+
`docker-compose run lib composer ci` for launching tests

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"php-cs-fixer fix"
3737
],
3838
"test": [
39-
"phpunit --colors --coverage-html ./coverage"
39+
"phpdbg -qrr vendor/bin/phpunit --colors --coverage-text --coverage-clover ./coverage/clover.xml"
4040
]
4141
}
4242
}

‎coverage/.gitkeep‎

Whitespace-only changes.

‎docker-compose.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: "3.8"
2+
3+
services:
4+
mariadb:
5+
image: mariadb:10.4
6+
environment:
7+
- "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
8+
- "MYSQL_DATABASE=test_database"
9+
restart: "on-failure"
10+
11+
redis:
12+
image: redis:6
13+
restart: "on-failure"
14+
15+
lib:
16+
build: ./
17+
depends_on:
18+
- mariadb
19+
- redis
20+
environment:
21+
- "MYSQL_HOST=mariadb"
22+
- "REDIS_HOST=redis"
23+
volumes:
24+
- "./coverage:/app/coverage"
25+
restart: "no"

0 commit comments

Comments
 (0)