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

#1 - boilerplate of Laravel app #3

Merged
merged 60 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
a08edce
- init
kamilpiech97 Nov 13, 2023
136a60e
- fixes
kamilpiech97 Nov 13, 2023
cb73a79
- fix
kamilpiech97 Nov 13, 2023
21f79fa
- fixes
kamilpiech97 Nov 13, 2023
437291e
- fixes
kamilpiech97 Nov 13, 2023
4592725
- name space fixgp
kamilpiech97 Nov 13, 2023
f2252f2
- fix
kamilpiech97 Nov 13, 2023
c44f4ae
- some script fixes
kamilpiech97 Nov 13, 2023
8f1ee00
- update script
kamilpiech97 Nov 14, 2023
208aee3
- update script
kamilpiech97 Nov 14, 2023
c35de32
- update script
kamilpiech97 Nov 14, 2023
102dee8
- update script
kamilpiech97 Nov 14, 2023
744e798
- added gitignore
kamilpiech97 Nov 14, 2023
1ac2166
- idea removed
kamilpiech97 Nov 14, 2023
fc17bb1
- update bash script
kamilpiech97 Nov 14, 2023
7b1b236
- red color
kamilpiech97 Nov 14, 2023
e690d3f
- update
kamilpiech97 Nov 14, 2023
e29312c
- prompt
kamilpiech97 Nov 14, 2023
7d57275
- some fixes
kamilpiech97 Nov 14, 2023
f9d0e25
- namespace update
kamilpiech97 Nov 14, 2023
ae73acd
- update
kamilpiech97 Nov 14, 2023
8affc02
- update
kamilpiech97 Nov 14, 2023
49e7c95
- update
kamilpiech97 Nov 14, 2023
8ea290e
- updated readme
kamilpiech97 Nov 14, 2023
8a28d59
- workflows deleted
kamilpiech97 Nov 14, 2023
ecbc99e
- workflow title update
kamilpiech97 Nov 14, 2023
f3d6e0e
- updated namespace
kamilpiech97 Nov 14, 2023
590db3c
Apply suggestions from code review
kamilpiech97 Nov 14, 2023
0a7e93e
- cr fix
kamilpiech97 Nov 14, 2023
59d9bb0
- cr fix
kamilpiech97 Nov 14, 2023
edefdcf
- cr fixes\updates
kamilpiech97 Nov 14, 2023
10908cb
- added workflow
kamilpiech97 Nov 14, 2023
d24a0b3
- fix workflow
kamilpiech97 Nov 14, 2023
9c79f5f
- fix workflow
kamilpiech97 Nov 14, 2023
e7d38a8
- workflow update
kamilpiech97 Nov 14, 2023
4d77fa4
- workflow update
kamilpiech97 Nov 14, 2023
8cf8d95
- update branch in workdflow
kamilpiech97 Nov 14, 2023
c66cf75
- update branch in workflow
kamilpiech97 Nov 14, 2023
037f8e6
- update
kamilpiech97 Nov 14, 2023
651ddff
- update
kamilpiech97 Nov 14, 2023
26b4e61
- update workflow after cr
kamilpiech97 Nov 14, 2023
c06c0ec
- fix
kamilpiech97 Nov 14, 2023
68bb27c
- update branch name
kamilpiech97 Nov 14, 2023
88289d6
- update branch name
kamilpiech97 Nov 14, 2023
ec9086c
- update branch name
kamilpiech97 Nov 14, 2023
d1c3357
- cr fixes
kamilpiech97 Nov 14, 2023
4b743e4
- cr fixes
kamilpiech97 Nov 15, 2023
495826b
- fix
kamilpiech97 Nov 15, 2023
9696419
- fix
kamilpiech97 Nov 15, 2023
2f91571
- fix bash script workflow
kamilpiech97 Nov 15, 2023
38797fc
- updated .env.example
kamilpiech97 Nov 15, 2023
2df937a
Update src/eslint.config.js
kamilpiech97 Nov 15, 2023
4c32236
- cr fixes
kamilpiech97 Nov 15, 2023
7f6efd1
- cr fixes
kamilpiech97 Nov 15, 2023
d8b7dfb
- cr fixes
kamilpiech97 Nov 15, 2023
9c382f6
- cr fixes
kamilpiech97 Nov 15, 2023
5036ee0
- updated comments
kamilpiech97 Nov 15, 2023
822481f
Update src/.editorconfig
kamilpiech97 Nov 15, 2023
fe7e163
- cr fixes
kamilpiech97 Nov 15, 2023
afaa5f8
- updated readme
kamilpiech97 Nov 15, 2023
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
46 changes: 46 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: 2

updates:
- package-ecosystem: composer
directory: "/src"
schedule:
interval: monthly
time: "06:30"
timezone: "Europe/Warsaw"
commit-message:
prefix: "- (php) "
target-branch: main
open-pull-requests-limit: 1

- package-ecosystem: npm
directory: "/src"
schedule:
interval: monthly
time: "06:30"
timezone: "Europe/Warsaw"
commit-message:
prefix: "- (js) "
target-branch: main
open-pull-requests-limit: 1

- package-ecosystem: github-actions
directory: "/src"
schedule:
interval: monthly
time: "06:30"
timezone: "Europe/Warsaw"
commit-message:
prefix: "- (github actions) "
target-branch: main
open-pull-requests-limit: 1

- package-ecosystem: docker
directory: "/src/environment/dev/app"
schedule:
interval: monthly
time: "06:30"
timezone: "Europe/Warsaw"
commit-message:
prefix: "- (docker dev) "
target-branch: main
open-pull-requests-limit: 1
12 changes: 12 additions & 0 deletions .github/workflows/check-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Check PR Title
on:
pull_request:
branches: [ "main" ]
types: [opened, edited, synchronize, ready_for_review, reopened]

jobs:
check-pr-title:
name: Check PR title
runs-on: ubuntu-latest
steps:
- uses: blumilksoftware/action-pr-title@v1.2.0 # https://github.com/blumilksoftware/action-pr-title
42 changes: 42 additions & 0 deletions .github/workflows/test-and-lint-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Test & lint JS codebase

on:
pull_request:
branches: [ "main" ]
types: [opened, synchronize, reopened, ready_for_review]
paths:
- '**.js'
- '**.ts'
- '**.vue'
- 'package.json'
- 'package.lock'

jobs:
test-and-lint-js:
name: Test & lint JS codebase
timeout-minutes: 10
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4.1.1 # https://github.com/actions/checkout

- name: Cache dependencies
uses: actions/cache@v3.3.2 # https://github.com/actions/cache
with:
path: node_modules
key: ${{ runner.os }}-npm-dependencies-${{ hashFiles('package.lock') }}
restore-keys: ${{ runner.os }}-npm-dependencies

- name: Set up node
uses: actions/setup-node@v4.0.0 # https://github.com/actions/setup-node
with:
node-version: 21

- name: Install npm dependencies
working-directory: src
run: npm install
mtracz marked this conversation as resolved.
Show resolved Hide resolved

- name: Run JS linter
working-directory: src
run: npm run lint
44 changes: 44 additions & 0 deletions .github/workflows/test-and-lint-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test & lint PHP codebase

on:
pull_request:
branches: [ "main" ]
types: [opened, synchronize, reopened, ready_for_review]
paths:
- '**.php'
- 'composer.json'
- 'composer.lock'
- 'phpunit.xml'
- 'env.ci'

jobs:
test-and-lint-php:
name: Test & lint PHP codebase
timeout-minutes: 10
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4.1.1 # https://github.com/actions/checkout

- name: Cache dependencies
uses: actions/cache@v3.3.2 # https://github.com/actions/cache
with:
path: vendor
key: ${{ runner.os }}-composer-dependencies-${{ hashFiles('composer.lock') }}
restore-keys: ${{ runner.os }}-composer-dependencies

- name: Setup PHP
uses: shivammathur/setup-php@2.27.1 # https://github.com/shivammathur/setup-php
with:
php-version: 8.2
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_pgsql, intl
coverage: none

- name: Install Composer dependencies
working-directory: src
run: composer install --prefer-dist --no-interaction --no-suggest

- name: Run PHP linter
working-directory: src
run: composer cs
22 changes: 22 additions & 0 deletions .github/workflows/test-bash-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test Bash Script

on:
pull_request:
branches: [ "main" ]
types: [opened, synchronize, reopened, ready_for_review]

jobs:
test:
name: Run Script
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4.1.1 # https://github.com/actions/checkout

- name: Run Bash Script
run: |
mkdir example-project
mv init.sh example-project/init.sh
cd example-project
chmod +x init.sh
./init.sh "TestApp" "TestNamespace" "${{ github.head_ref }}" "12345" "23456" "34567" "45678"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea/
.vscode/
src/composer.lock
src/package-lock.json
100 changes: 100 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash

set -e

BLUE='\033[01;34m'
RED='\033[0;31m'
NC='\033[0m'

isValidAppNamespace() {
local appName="$1"

if [ -z "$appName" ]; then
echo -e "${RED}Application namespace cannot be empty.${NC}"
return 1
fi

if ! [[ $appName =~ ^[A-Z][a-zA-Z0-9\\]*$ ]]; then
echo -e "${RED}Application namespace must start with an uppercase letter and be alphanumeric.${NC}"
return 1
fi

local len=${#appName}
if [ "$len" -lt 2 ] || [ "$len" -gt 20 ]; then
echo -e "${RED}Application namespace must be between 2 and 20 characters.${NC}"
return 1
fi

return 0
}

promptForInput() {
read -r -p "Enter the app name: " APP_NAME
read -r -p "Enter the namespace for the app (leave empty for default namespace 'App'): " APP_NAMESPACE
read -r -p "Enter the branch name (leave empty for default branch): " BRANCH_NAME
read -r -p "Enter the docker app host port (leave empty for default 63851): " DOCKER_APP_HOST_PORT
read -r -p "Enter the docker database host port (leave empty for default 63853): " DOCKER_DATABASE_HOST_PORT
read -r -p "Enter the docker mailpit host port (leave empty for default 63854): " DOCKER_MAILPIT_DASHBOARD_HOST_PORT
read -r -p "Enter the docker redis host port (leave empty for default 63854): " DOCKER_REDIS_HOST_PORT
APP_NAMESPACE=${APP_NAMESPACE:-App}
DOCKER_APP_HOST_PORT=${DOCKER_APP_HOST_PORT:-63851}
DOCKER_DATABASE_HOST_PORT=${DOCKER_DATABASE_HOST_PORT:-63853}
DOCKER_MAILPIT_DASHBOARD_HOST_PORT=${DOCKER_MAILPIT_DASHBOARD_HOST_PORT:-63854}
DOCKER_REDIS_HOST_PORT=${DOCKER_REDIS_HOST_PORT:-63852}
}

echo -e "${BLUE}
██████╗ ██╗ ██╗ ██╗███╗ ███╗██╗██╗ ██╗ ██╗ ██████╗ ██████╗ ██╗██╗ ███████╗██████╗ ██████╗ ██╗ █████╗ ████████╗███████╗
██╔══██╗██║ ██║ ██║████╗ ████║██║██║ ██║ ██╔╝ ██╔══██╗██╔═══██╗██║██║ ██╔════╝██╔══██╗██╔══██╗██║ ██╔══██╗╚══██╔══╝██╔════╝
██████╔╝██║ ██║ ██║██╔████╔██║██║██║ █████╔╝ ██████╔╝██║ ██║██║██║ █████╗ ██████╔╝██████╔╝██║ ███████║ ██║ █████╗
██╔══██╗██║ ██║ ██║██║╚██╔╝██║██║██║ ██╔═██╗ ██╔══██╗██║ ██║██║██║ ██╔══╝ ██╔══██╗██╔═══╝ ██║ ██╔══██║ ██║ ██╔══╝
██████╔╝███████╗╚██████╔╝██║ ╚═╝ ██║██║███████╗██║ ██╗ ██████╔╝╚██████╔╝██║███████╗███████╗██║ ██║██║ ███████╗██║ ██║ ██║ ███████╗
╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝
${NC}"

if [ "$#" -lt 1 ]; then
echo "Arguments missing or incomplete. Please follow the prompts."
promptForInput
else
APP_NAME=$1
APP_NAMESPACE=${2:-App}
BRANCH_NAME=${3:-}
DOCKER_APP_HOST_PORT=${4:-63851}
DOCKER_DATABASE_HOST_PORT=${5:-63853}
DOCKER_MAILPIT_DASHBOARD_HOST_PORT=${6:-63854}
DOCKER_REDIS_HOST_PORT=${7:-63852}
fi

if ! isValidAppNamespace "$APP_NAMESPACE"; then
exit 1
fi

TARGET_DIR=$(pwd)
TEMP_DIR=$(mktemp -d)

if [ -z "$BRANCH_NAME" ]; then
git clone "https://github.com/blumilksoftware/boilerplate" "$TEMP_DIR"
else
git clone --branch "$BRANCH_NAME" "https://github.com/blumilksoftware/boilerplate" "$TEMP_DIR"
fi

if [ $? -ne 0 ]; then
echo "Failed to clone the repository."
exit 1
fi

shopt -s dotglob
mv "$TEMP_DIR/src/"* "$TARGET_DIR"
shopt -u dotglob

rm -rf "$TEMP_DIR"

ESCAPED_APP_NAMESPACE=$(printf '%s\n' "$APP_NAMESPACE" | sed -e 's/[\/&]/\\&/g')
find "$TARGET_DIR" -type f -exec sed -i "s/example-app/$APP_NAME/g" {} \;
find "$TARGET_DIR" -type f -exec sed -i "s/ExampleApp/$ESCAPED_APP_NAMESPACE/g" {} \;
find "$TARGET_DIR" -type f -name ".env.example" -exec sed -i "s/63851/$DOCKER_APP_HOST_PORT/g" {} \;
find "$TARGET_DIR" -type f -name ".env.example" -exec sed -i "s/63853/$DOCKER_DATABASE_HOST_PORT/g" {} \;
find "$TARGET_DIR" -type f -name ".env.example" -exec sed -i "s/63854/$DOCKER_MAILPIT_DASHBOARD_HOST_PORT/g" {} \;
find "$TARGET_DIR" -type f -name ".env.example" -exec sed -i "s/63852/$DOCKER_REDIS_HOST_PORT/g" {} \;

echo "Boilerplate copied."
31 changes: 29 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
## boilerplate
A boilerplate for PHP projects with plug-and-play dockerized environment, Composer and its scripts, preconfigured Github Actions, added [Codestyle package](https://github.com/blumilksoftware/codestyle) and handy scripts, including starting a Laravel project.
# Blumilk Boilerplate
A boilerplate for PHP projects with plug-and-play dockerized environment, Inertia.js, Composer and its scripts, preconfigured Github Actions, added [Codestyle package](https://github.com/blumilksoftware/codestyle), [Eslint package](https://github.com/blumilksoftware/eslint-config-blumilk) and handy scripts, including starting a Laravel project.

## Prerequisites
- Bash shell
- Git installed

## Usage
To use the script, you can either pass arguments directly or enter them interactively when prompted.

### Direct argument passing
```bash
bash <(curl -s https://raw.githubusercontent.com/blumilksoftware/boilerplate/init.sh) <app-name> [app-namespace] [branch-name] [app-host-port] [db-host-port] [mailpit-dashboard-port] [redis-host-port]
```

- `<app-name>`: Required. Name of your application.
- `[app-namespace]`: Optional. The namespace for your application. Defaults to **App** if not provided.
- `[branch-name]`: Optional. The specific branch to clone. Defaults to the **main** branch if not provided.
- `[app-host-port]`: Optional. Docker app host port. Defaults to 63851.
- `[db-host-port]`: Optional. Docker database host port. Defaults to 63853.
- `[mailpit-dashboard-port]`: Optional. Docker Mailpit dashboard host port. Defaults to 63854.
- `[redis-host-port]`: Optional. Docker Redis host port. Defaults to 63852.

### Interactive Mode
Run the script without arguments:
```bash
bash <(curl -s https://raw.githubusercontent.com/blumilksoftware/boilerplate/init.sh)
```
You will be prompted to enter the application name, namespace, branch name, and Docker port settings.
21 changes: 21 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[*.{js,ts,vue,css}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
16 changes: 16 additions & 0 deletions src/.env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
APP_NAME=example-app
APP_ENV=testing
APP_KEY=base64:WVG2VcHt+a2uzCw7n1tVUBPyw2kof644d6EoYA/UUAg=
APP_DEBUG=false
APP_URL=http://example-app.blumilk.localhost

LOG_CHANNEL=stack
LOG_LEVEL=debug

BROADCAST_DRIVER=log
CACHE_DRIVER=array
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=array
SESSION_LIFETIME=120
MAIL_MAILER=array
47 changes: 47 additions & 0 deletions src/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
APP_NAME=example-app
VITE_APP_NAME=example-app
APP_ENV=local
APP_KEY=base64:sCsJw8z+d/4ymp0OvzSip2h4Vp2hZZhpV2uOxgTqP94=
APP_DEBUG=true
APP_URL=http://example-app.blumilk.localhost

LOG_CHANNEL=stack
jsawo marked this conversation as resolved.
Show resolved Hide resolved
LOG_DEPRECATIONS_CHANNEL=null
mtracz marked this conversation as resolved.
Show resolved Hide resolved
LOG_LEVEL=debug

DB_CONNECTION=pgsql
DB_HOST=example-app-db-dev
DB_PORT=5432
DB_DATABASE=example-app
DB_USERNAME=example-app
DB_PASSWORD=password
DB_ROOT_PASSWORD=example

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
FILESYSTEM_DISK=local
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120

REDIS_HOST=example-app-redis-dev
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"

# DOCKER
DOCKER_APP_HOST_PORT=63851
DOCKER_DATABASE_HOST_PORT=63853
DOCKER_MAILPIT_DASHBOARD_HOST_PORT=63854
DOCKER_REDIS_HOST_PORT=63852
DOCKER_INSTALL_XDEBUG=true

DOCKER_HOST_USER_ID=1000
Loading
Loading