Skip to content

Commit

Permalink
Merge pull request #15 from iwasherefirst2/feature/change-title
Browse files Browse the repository at this point in the history
Add dockerfiles to enhance package testing
  • Loading branch information
iwasherefirst2 authored Dec 31, 2020
2 parents fa69fd3 + 09cba57 commit 9cbed54
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM php:7.2-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
libzip-dev \
-y mariadb-client

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install zip mysqli pdo_mysql mbstring exif pcntl bcmath gd && docker-php-ext-enable mysqli

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www

USER $user

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,10 @@ If you plan to contribute to this package, please make sure that the unit tests
all succeed. In order to test the integration tests please create a free mailtraip account, copy `tests/.env.example`
to `tests/.env` and add your mailtrap API credentials in `tests/.env`. The integration tests will now send
a test email to your mailtrap account and verify through the API if the mail was successfully send.

The package ships with a Dockerfile to make it easy to run the tests for you. Simply follow these steps:

docker-compose up --build
docker-compose exec app bash
composer install
./vendor/bin/phpunit
63 changes: 63 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
version: "3.7"
services:
app:
build:
args:
user: sammy
uid: 1000
context: ./
dockerfile: Dockerfile.dev
image: mailable
container_name: mailable-app
working_dir: /var/www/
environment:
- COMPOSER_MEMORY_LIMIT=-1
depends_on:
- db
volumes:
- ./:/var/www
networks:
- lahmi

db:
image: mysql:5.7
container_name: mailable-db
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
MYSQL_ROOT_PASSWORD: local
volumes:
- dbdata:/var/lib/mysql
- ./docker-compose/mysql/my.cnf:/etc/mysql/my.cnf
- ./docker-compose/mysql/init:/docker-entrypoint-initdb.d
ports:
- 3308:3306
networks:
- lahmi

nginx:
image: nginx:alpine
container_name: mailable-nginx
ports:
- 8006:80
depends_on:
- db
- app
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
networks:
- lahmi

networks:
lahmi:
driver: bridge

volumes:
dbdata:
driver: local

7 changes: 7 additions & 0 deletions docker-compose/mysql/init/01-databases.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# create databases
CREATE DATABASE IF NOT EXISTS `local_laravel`;

# create local_developer user and grant rights
CREATE USER 'local_developer'@'db' IDENTIFIED BY 'secret';
GRANT ALL PRIVILEGES ON *.* TO 'local_developer'@'%';

4 changes: 4 additions & 0 deletions docker-compose/mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[mysqld]
general_log = 1
general_log_file = /var/lib/mysql/general.log

21 changes: 21 additions & 0 deletions docker-compose/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}

0 comments on commit 9cbed54

Please sign in to comment.