Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Docker configuration in the package #182

Merged
merged 8 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ indent_style = space
indent_size = 4
max_line_length = 120

[*.{yml,json}]
indent_size = 2
109 changes: 55 additions & 54 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,64 @@ on:
- main

jobs:
integration-tests:
# Will not run if the event is a PR to bump-meilisearch-v* (so a pre-release PR)
# Will still run for each push to bump-meilisearch-v*
if: github.event_name != 'pull_request' || !startsWith(github.base_ref, 'bump-meilisearch-v')
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4', '8.0', '8.1']
include:
- php-version: '7.4'
sf-version: '4.4.*'
- php-version: '7.4'
sf-version: '5.4.*'
- php-version: '8.0'
sf-version: '6.0.*'
- php-version: '8.1'
sf-version: '6.0.*'
- php-version: '8.1'
sf-version: '6.1.*'
name: integration-tests (PHP ${{ matrix.php-version }})
steps:
- uses: actions/checkout@v3
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v2, flex
- name: Validate composer.json and composer.lock
run: composer validate
- name: Install dependencies
env:
SYMFONY_REQUIRE: ${{ matrix.sf-version }}
run: composer install --prefer-dist --no-progress --quiet
- name: Meilisearch setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics
- name: Run test suite
run: composer test:unit
integration-tests:
# Will not run if the event is a PR to bump-meilisearch-v* (so a pre-release PR)
# Will still run for each push to bump-meilisearch-v*
if: github.event_name != 'pull_request' || !startsWith(github.base_ref, 'bump-meilisearch-v')
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4', '8.0', '8.1']
include:
- php-version: '7.4'
sf-version: '4.4.*'
- php-version: '7.4'
sf-version: '5.4.*'
- php-version: '8.0'
sf-version: '6.0.*'
- php-version: '8.1'
sf-version: '6.0.*'
- php-version: '8.1'
sf-version: '6.1.*'

code-style:
runs-on: ubuntu-latest
name: 'Code style'
steps:
- uses: actions/checkout@v3
name: integration-tests (PHP ${{ matrix.php-version }})
steps:
- uses: actions/checkout@v3
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v2, flex
- name: Validate composer.json and composer.lock
run: composer validate
- name: Install dependencies
env:
SYMFONY_REQUIRE: ${{ matrix.sf-version }}
run: composer install --prefer-dist --no-progress --quiet
- name: Meilisearch setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics
- name: Run test suite
run: composer test:unit

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
code-style:
runs-on: ubuntu-latest
name: 'Code style'
steps:
- uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Install dependencies
run: composer install --prefer-dist --no-progress --quiet
- name: Validate composer.json and composer.lock
run: composer validate

- name: PHP CS Fixer
run: composer lint:check
- name: Install dependencies
run: composer install --prefer-dist --no-progress --quiet

- name: PHPstan
run: composer phpstan
- name: PHP CS Fixer
run: composer lint:check

- name: PHPstan
run: composer phpstan
20 changes: 18 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume

#### Setup

Install the dependencies:
You can set up your local environment natively or using `docker`, check out the [`docker-compose.yml`](/docker-compose.yml).

Example of running all the checks with docker:
```bash
docker-compose run --rm package bash -c "composer install && composer test:unit && composer lint:check"
```

To install dependencies:

```sh
composer install
Expand Down Expand Up @@ -62,6 +69,15 @@ These commands do not work on MacOS, see [this issue](https://github.com/meilise

#### Setup

You can set up your local environment natively or using `docker`, check out the [`docker-compose.yml`](/docker-compose.yml).

Example of running all the checks with docker:
```bash
docker-compose run --rm package bash -c "list of the commands required to build + run tests + run linters"
```

To install dependencies:

brunoocasali marked this conversation as resolved.
Show resolved Hide resolved
To start and build your Docker environment, just execute the next command in a terminal:

```sh
Expand All @@ -76,7 +92,7 @@ Each Pull Request should pass the tests, and the linter to be accepted.

```sh
# Tests
docker-compose exec -e MEILISEARCH_URL=http://meilisearch:7700 php composer test:unit
docker-compose exec -e MEILISEARCH_HOST=http://meilisearch:7700 php composer test:unit
# Linter
docker-compose exec php composer lint:check
# Linter (with auto-fix)
Expand Down
33 changes: 9 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
FROM php:8.0-fpm-alpine as php

# persistent / runtime deps
RUN apk add --no-cache \
acl \
fcgi \
file \
gettext \
git \
;
FROM php:8.0-fpm as php

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1

WORKDIR /usr/src

# prevent the reinstallation of vendors at every changes in the source code
COPY composer.json ./
RUN set -eux; \
composer install; \
composer clear-cache

# copy only specifically what we need
COPY src src/
COPY tests tests/
RUN apt-get update && apt-get install -y \
libfcgi0ldbl \
zlib1g-dev \
gettext \
libzip-dev \
unzip \
git

COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
RUN docker-php-ext-install zip

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"phpstan": "./vendor/bin/phpstan --memory-limit=1G --ansi",
Expand Down
18 changes: 0 additions & 18 deletions docker-compose.yaml

This file was deleted.

24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.8'

services:
package:
build: .
tty: true
stdin_open: true
working_dir: /home/package
environment:
- MEILISEARCH_HOST=http://meilisearch:7700
depends_on:
- meilisearch
links:
- meilisearch
volumes:
- ./:/home/package:rw,cached

meilisearch:
image: getmeili/meilisearch:latest
ports:
- "7700"
environment:
- MEILI_MASTER_KEY=masterKey
- MEILI_NO_ANALYTICS=true
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<env name="APP_ENV" value="test"/>
<env name="APP_DEBUG" value="false"/>
<env name="MEILISEARCH_PREFIX" value="sf_phpunit_"/>
<env name="MEILISEARCH_URL" value="http://127.0.0.1:7700"/>
<env name="MEILISEARCH_HOST" value="http://127.0.0.1:7700"/>
<env name="MEILISEARCH_API_KEY" value="masterKey"/>
<env name="TRAVIS_JOB_NUMBER" value=""/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/config/meili_search.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
meili_search:
url: '%env(MEILISEARCH_URL)%'
url: '%env(MEILISEARCH_HOST)%'
api_key: '%env(MEILISEARCH_API_KEY)%'
prefix: '%env(MEILISEARCH_PREFIX)%_'
nbResults: 12
Expand Down