Skip to content

Commit

Permalink
Added docker files to allow running application in containerized envi…
Browse files Browse the repository at this point in the history
…ronment
  • Loading branch information
damian-nowak committed Jul 15, 2019
1 parent 10477fd commit 3b6d572
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 1 deletion.
52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM php:7.3.1-fpm

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

# Set working directory
WORKDIR /var/www

# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
mysql-client \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
libzip-dev \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl

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

# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-install bcmath

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www

# Copy existing application directory contents
COPY . /var/www

# Copy existing application directory permissions
COPY --chown=www:www . /var/www

# Change current user to www
USER www

# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
45 changes: 45 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: '3'
services:

#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network

#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "82:80"
- "444:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network

#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
20 changes: 20 additions & 0 deletions nginx/conf.d/app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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;
}
}
2 changes: 2 additions & 0 deletions php/local.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
upload_max_filesize=40M
post_max_size=40M
52 changes: 52 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,56 @@ the greatest challenge in this task - due to little practical knowledge of it. A
way of combining Laravel with DDD, albeit even taking it into consideration, allows to make more conscious choices
while constructing your application - and that is for me the immediate benefit of this task.

## Docker installation

Running application in docker environment requires docker and docker-compose installed on your system.

1. set permissions for project dir

```
sudo chown -R $USER:$USER <dir_name>
```
2. cd into project directory.
3. copy env variables
```
cp .env.example .env
```
4. create new sqlite db
```
touch database/database.sqlite
```
5. start docker containers
```
docker-compose up -d
```
6. install dependencies with composer
via docker temp container:
```
docker run --rm -v $(pwd):/app composer install
```
via docker running container:
```
docker exec app composer install
```
or locally on your system
7. generate laravel app key
```
docker-compose exec app php artisan key:generate
```
8. run migrations and seed db
```
docker-compose exec app php artisan migrate --seed
```
9. application is now ready at "localhost:82/api/v1
2 changes: 1 addition & 1 deletion tests/Feature/ClientVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Tests\Feature;

use Domain\Clients\Client;
use Domain\Subscriptions\Subscription;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use Domain\Subscriptions\Subscription;

/**
* @group latest
Expand Down

0 comments on commit 3b6d572

Please sign in to comment.