Skip to content

Commit

Permalink
feature/DLT-30-update-info
Browse files Browse the repository at this point in the history
- Update ReadMe
  • Loading branch information
nspalo committed Sep 12, 2023
1 parent 829e4cd commit a0ce8f8
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 42 deletions.
155 changes: 115 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Docker Laravel Template
> This is a simple project that aims to build a template for a
> This is a simple project that aims to build a template for a
> *Dockerize web development environment with NginX, MySQL, PHP, and Laravel*.
![CI BUILD](https://github.com/nspalo/docker-laravel-template/actions/workflows/build.yml/badge.svg)
Expand All @@ -9,67 +9,125 @@
- nginx
- NginX stable-alpine
- mysql
- MySQL 8.0.30
- MySQL 5.7.22
- php
- PHP 8.1 fpm-alpine
- PHP 8.1-fpm-alpine
- composer
- Composer 2.1.5
- Composer 2.6.1
- npm
- Node 16 alpine
- Node 20.6-alpine
- artisan
- Laravel ^8.0

## Set Up Procedure
> **Note:**
> In this structure, we always need to add few flags for our commands to work.
> - --env-file flag then the path to the environment config we want to load.
> - -f flag then the path to the docker compose yaml file.
> which in our case it is:

## TLDR;
- A Quick guide to get things up and running

### Step 1: Build and Start Services
```
> ./scripts/up.sh -d --build
```

### Step 2: Running Composer
```
> ./scripts/composer.sh install
> ./scripts/composer.sh dump-autoload
```

### Step 3: Running NPM
```
// Running NPM
> ./scripts/run.sh npm install
> ./scripts/run.sh npm run build
```

### Step 4: Laravel Set-up
```
// Copying Laravel .env file
> ./scripts/composer.sh run post-root-package-install
// Generating key
> ./scripts/artisan.sh key:generate
// Running migrations
> ./scripts/artisan.sh migrate
```

### Step 5: Accessing the site
Hit the browser at `localhost:8080`

----

## More Details ...

### Environment File and Configurations
_In here, we will use a file with `.env` extension to support multi-environment set up and load the correct variable values automatically.
For now, its just_ `local.env` but feel free to add more depending on the need like `staging.env`, `uat.env`, `test.env`, `prod.env` and the likes.
- _see:_ `docker/environments/local.env` to set up your configs and credentials for this file.
- Take note that some values in this file will be use later on by laravel `.env` and our `config.env` file.

The generic `.env` file `config.env` should always be used in the command and should use the variable `SYS_ENV` to set the specific environment file configuration.
- _see:_ `docker/environments/config.env`

### Docker Compose Command Structure
> **Note:** In this structure, we always need to add few flags for our docker composer commands to work.
> - `--env-file` flag is the path to the environment config we want to load.
> - `-f` flag is the path to the docker compose yaml file.
> which in our case it is:
> - `--env-file docker/environments/config.env`
> - `-f docker/docker-compose.yml`
>
> _See: `docker/docker-compose.yml` for the list of service containers_
### Step 0: Environment File Configurations
Note:
_In here we will use a file with `.env` extension to support multi-environment set up and load the correct variable values automatically.
For now, its just_ `local.env` but feel free to add more depending on the need like `staging.env`, `uat.env`, `test.env`, `prod.env` and the likes.
- _see:_ `docker/environments/local.env` to set up your configs and credentials for this file.
- Take note that some values in this file will be use later on by laravel `.env` and our `config.env` file.
> - _See: `docker/docker-compose.yml` for the list of service containers_
>
> _So for our full command to build the images would look something like this_
> `> docker-compose --env-file docker/environments/config.env -f docker/docker-compose.yml build`
>
> However, for ease of use and to make running of commands easy, a few scripts was prepared.
> The simplified version of the command above is `> ./scripts/build.sh`
> _See:`scripts/`_ for more info.
The generic `.env` file `config.env` should always be used in the command and should use the variable `SYS_ENV` to set the specific environment file configuration.
- _see:_ `docker/environments/config.env`

### Step 1: Service containers - Building and Starting
### Service containers: Building, Starting, and Stopping
```
// Building the services/containers
> docker-compose --env-file docker/environments/config.env -f docker/docker-compose.yml build
> ./scripts/build.sh
// Starting the services/containers
// - optionally add the -d (detach) flag to run in the background
> docker-compose --env-file docker/environments/config.env -f docker/docker-compose.yml up -d
> ./scripts/up.sh -d
// Or do a one-liner command for the build and start process
> docker-compose --env-file docker/environments/config.env -f docker/docker-compose.yml up -d --build
> ./scripts/up.sh -d --build
// Stoping the services/containers
// - To stop a specific service add the continer name
> ./scripts/stop.sh <_ContainerName_>
// Tear down routine
// - optionally add the -v to remove the images
> ./scripts/down.sh -v
```

### Step 2 - A: Packages and Dependencies
> **_Note:_** for a specific service, use the container name
> **_Format:_** docker-compose --env-file <_EnvFile_> -f <_DockerComposeYamlFile_> up <_ContainerName_>
> **_E.g.:_** `docker-compose --env-file docker/environments/config.env -f docker/docker-compose.yml up php`
>
### Packages and Dependencies
```
// Running composer install
> docker-compose --env-file docker/environments/config.env -f docker/docker-compose.yml run --rm composer install
// Running NPM
> ./scripts/run.sh npm install
> ./scripts/run.sh npm run build
// Running Composer
> ./scripts/composer.sh install
> ./scripts/composer.sh dump-autoload
// Copying Laravel .env file
> ./scripts/composer.sh run post-root-package-install
// Running artisan migrate
> docker-compose --env-file docker/environments/config.env -f docker/docker-compose.yml run --rm artisan migrate
// Generating Key
> ./scripts/artisan.sh key:generate
// Running npm
> docker-compose --env-file docker/environments/config.env -f docker/docker-compose.yml run --rm npm install
// Running Migration
> ./scripts/artisan.sh migrate
```

### Step 2 - B: Importing existing database data
### Importing existing database data
```
// First we need to copy the .sql file for import to the container
// docker cp <FilePath>/<SqlFile>.sql <ContainerName>:./<SqlFile>.sql
Expand All @@ -84,5 +142,22 @@ The generic `.env` file `config.env` should always be used in the command and sh
mysql> source file.sql
```

### Step 3: Accessing the site
Hit the browser at `localhost:9100`
### Code Quality and Testing
```
// Running PhpStan
> ./scripts/composer.sh run phpstan
// Running Easy Coding Standards for the entire project
> ./scripts/composer.sh run ecs-all
// Running Easy Coding Standards for App or Test ONLY
> ./scripts/composer.sh run ecs-app
> ./scripts/composer.sh run ecs-test
// Running Auto-Fix for ecs
> ./scripts/composer.sh run ecs-app-fix
> ./scripts/composer.sh run ecs-test-fix
// Running Automated Test with PhpUnit
> ./scripts/composer.sh run phpunit
```
5 changes: 3 additions & 2 deletions scripts/prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -eo pipefail

# Delete All Images
echo '####################################################'
echo 'Running docker system prune -a --force'
echo '####################################################'
docker system prune -a --force
docker ps
docker images

0 comments on commit a0ce8f8

Please sign in to comment.