mirror of
https://github.com/Yannick7777/codeigniter-setup-script.git
synced 2025-06-25 21:55:33 +02:00
Initial commit
This commit is contained in:
commit
dc46c9e48f
18 changed files with 360 additions and 0 deletions
18
.editorconfig
Normal file
18
.editorconfig
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
[docker-compose.yml]
|
||||||
|
indent_size = 4
|
11
.gitattributes
vendored
Normal file
11
.gitattributes
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
* text=auto eol=lf
|
||||||
|
|
||||||
|
*.blade.php diff=html
|
||||||
|
*.css diff=css
|
||||||
|
*.html diff=html
|
||||||
|
*.md diff=markdown
|
||||||
|
*.php diff=php
|
||||||
|
|
||||||
|
/.github export-ignore
|
||||||
|
CHANGELOG.md export-ignore
|
||||||
|
.styleci.yml export-ignore
|
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
.env
|
||||||
|
/dbdata
|
||||||
|
/.vscode
|
||||||
|
/.fleet
|
||||||
|
/.idea
|
||||||
|
/.nova
|
||||||
|
/.zed
|
||||||
|
.idea
|
||||||
|
|
||||||
|
|
||||||
|
laravel/
|
41
README.md
Normal file
41
README.md
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
## Idea
|
||||||
|
This Project aims to simplify setting up a laravel project in a local development environment for new and experienced developers.
|
||||||
|
|
||||||
|
It stores all data (excluding the built docker image) in a single directory to make it easy for a developer to remove existing projects again and keep their system clutter-free.
|
||||||
|
|
||||||
|
The only **dependencies** for this project are **git** and **docker(-compose)**.
|
||||||
|
|
||||||
|
Tested shells are: `bash`, `zsh`
|
||||||
|
|
||||||
|
## Content
|
||||||
|
This project ships with a custom docker container based on **php:8.2-apache** with the php extensions opcache, pdo_mysql, intl, and zip.
|
||||||
|
|
||||||
|
It also includes **mysql:8** and **phpmyadmin:latest**.
|
||||||
|
|
||||||
|
## Other useful info
|
||||||
|
- To reset the Database, stop the Docker containers, go to the project root and execute `rm -rf dbdata`. Then execute `./setup`.
|
||||||
|
- The apps and PMAs port can be changed by editing the `SETUP_APP_PORT` and `SETUP_PMA_PORT` variables in `.env`. This resets after running `./setup`.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
### Windows with VSCode
|
||||||
|
- If WSL isn't installed yet, install it by executing `wsl --install` in your preferred shell.
|
||||||
|
- Open WSL from startmenu or your preferred shell by executing `wsl`.
|
||||||
|
- Open VSCode by executing `code`.
|
||||||
|
- Wait until the VSCode server is installed.
|
||||||
|
- VSCode should open up. Press F1 and use `WSL: Connect to WSL` command.
|
||||||
|
- Press F1 and use `Git: Clone` to clone this repo.
|
||||||
|
- `cd` into this repo (the laravel-setup-script directory).
|
||||||
|
- Press F1 and use `Git: Clone` again. Make sure to clone it into this repo's folder and to NOT open the cloned repository and instead click `cancel`.
|
||||||
|
- Rename your project to `laravel` by either using the `mv` command in the VSCode terminal or by right-clicking on the directory in VSCode and clicking `rename`.
|
||||||
|
- Start Docker Desktop on Windows.
|
||||||
|
- Type `./setup` into the VSCode terminal.
|
||||||
|
- Type `./start` into the VSCode terminal.
|
||||||
|
- Done!
|
||||||
|
#### Tips & Tricks
|
||||||
|
- If you encounter any Docker-related issues, it might help to close Docker Engine and stop WSL by executing `wsl -t ubuntu` in your preferred shell. After that, start both again.
|
||||||
|
- If you want to commit to your laravel repo with the VSCode F1 commands, make sure to switch to the folder your repo is in first. This can be done via `File` => `Open Folder...`
|
||||||
|
|
||||||
|
### Linux
|
||||||
|
- If you're a (sigma) Linux user, follow the Windows instructions starting from when the repo should be cloned.
|
||||||
|
- Make sure you have access to the `docker` and `docker compose` commands.
|
||||||
|
- Make sure you started the Docker Daemon; that's `rc-service docker start` for Open-RC based distros and `systemctl start docker` for Systemd based distros. If you're not sure what type of distro you're running, you probably run a Systemd based one.
|
10
art
Executable file
10
art
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$(basename $(pwd))" == "laravel" ]]; then
|
||||||
|
cd ..
|
||||||
|
./art "$@"
|
||||||
|
cd laravel
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker compose exec -it app php artisan $@
|
48
compose.yaml
Normal file
48
compose.yaml
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
services:
|
||||||
|
# Application & web server
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
context: docker_build
|
||||||
|
working_dir: /var/www
|
||||||
|
volumes:
|
||||||
|
- ./laravel/:/var/www
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
|
ports:
|
||||||
|
- ${SETUP_APP_PORT:-80}:80
|
||||||
|
user: ${dockerUID}:${dockerGID}
|
||||||
|
# Database
|
||||||
|
database:
|
||||||
|
image: mysql:8
|
||||||
|
volumes:
|
||||||
|
- ./dbdata:/var/lib/mysql
|
||||||
|
environment:
|
||||||
|
MYSQL_DATABASE: ${DB_DATABASE}
|
||||||
|
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
|
||||||
|
MYSQL_PASSWORD: ${DB_PASSWORD}
|
||||||
|
MYSQL_USER: ${DB_USERNAME}
|
||||||
|
MYSQL_PORT: ${DB_PORT}
|
||||||
|
ports:
|
||||||
|
- "33061:3306"
|
||||||
|
user: ${dockerUID}:${dockerGID}
|
||||||
|
# Database management
|
||||||
|
pma:
|
||||||
|
image: phpmyadmin:latest
|
||||||
|
environment:
|
||||||
|
- PMA_ARBITRARY=1
|
||||||
|
- PMA_HOST=${DB_HOST}
|
||||||
|
- PMA_USER=${DB_USERNAME}
|
||||||
|
- PMA_PASSWORD=${DB_PASSWORD}
|
||||||
|
- PMA_PORT=${DB_PORT}
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
|
ports:
|
||||||
|
- ${SETUP_PMA_PORT:-8888}:80
|
||||||
|
# Mailing Server
|
||||||
|
# mailhog:
|
||||||
|
# image: mailhog/mailhog
|
||||||
|
# logging:
|
||||||
|
# driver: 'none'
|
||||||
|
# ports:
|
||||||
|
# - 1025:1025
|
||||||
|
# - 8025:8025
|
1
docker_build/.dockerignore
Normal file
1
docker_build/.dockerignore
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Dockerfile
|
30
docker_build/Dockerfile
Normal file
30
docker_build/Dockerfile
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
FROM composer AS composer
|
||||||
|
|
||||||
|
|
||||||
|
FROM php:8.2-apache
|
||||||
|
|
||||||
|
COPY --from=composer /usr/bin/composer /usr/bin/composer
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y \
|
||||||
|
libicu-dev libzip-dev \
|
||||||
|
&& docker-php-ext-enable opcache \
|
||||||
|
&& docker-php-ext-install pdo_mysql intl zip -j$(nproc) \
|
||||||
|
&& apt-get autoclean -y \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y "$(cat add_pkgs | head -n 1)" || true \
|
||||||
|
&& docker-php-ext-enable "$(cat enable_ext | head -n 1)" || true \
|
||||||
|
&& docker-php-ext-enable "$(cat install_ext | head -n 1)" || true \
|
||||||
|
&& apt-get autoclean -y \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
|
||||||
|
# Update apache config to point to the *public* directory
|
||||||
|
ENV APACHE_DOCUMENT_ROOT=/var/www/public
|
||||||
|
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
|
||||||
|
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
|
||||||
|
|
||||||
|
# Enable headers module
|
||||||
|
RUN a2enmod rewrite headers
|
1
docker_build/README.md
Normal file
1
docker_build/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
If you edit the files in this directory to add contents to the container remember that the buildprocess will not throw an error if you entered an invalid packagename / PHP extension.
|
2
docker_build/add_pkgs
Normal file
2
docker_build/add_pkgs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
curl
|
||||||
|
#list additional packages to be installed inside the container on the first line only
|
2
docker_build/enable_ext
Normal file
2
docker_build/enable_ext
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
#list additional PHP extensions to be enabled inside the container on the first line only
|
2
docker_build/install_ext
Normal file
2
docker_build/install_ext
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
#list additional PHP extensions to be installed inside the container on the first line only
|
69
env_docker
Normal file
69
env_docker
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
APP_NAME=Laravel
|
||||||
|
APP_ENV=local
|
||||||
|
APP_KEY=
|
||||||
|
APP_DEBUG=true
|
||||||
|
APP_TIMEZONE=UTC
|
||||||
|
APP_URL=http://localhost
|
||||||
|
|
||||||
|
APP_LOCALE=en
|
||||||
|
APP_FALLBACK_LOCALE=en
|
||||||
|
APP_FAKER_LOCALE=en_US
|
||||||
|
|
||||||
|
APP_MAINTENANCE_DRIVER=file
|
||||||
|
# APP_MAINTENANCE_STORE=database
|
||||||
|
|
||||||
|
PHP_CLI_SERVER_WORKERS=4
|
||||||
|
|
||||||
|
BCRYPT_ROUNDS=12
|
||||||
|
|
||||||
|
LOG_CHANNEL=stack
|
||||||
|
LOG_STACK=single
|
||||||
|
LOG_DEPRECATIONS_CHANNEL=null
|
||||||
|
LOG_LEVEL=debug
|
||||||
|
|
||||||
|
DB_CONNECTION=mysql
|
||||||
|
DB_HOST=database
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_DATABASE=laravel
|
||||||
|
DB_USERNAME=laravel-user
|
||||||
|
DB_PASSWORD=laravel-password
|
||||||
|
|
||||||
|
SESSION_DRIVER=database
|
||||||
|
SESSION_LIFETIME=120
|
||||||
|
SESSION_ENCRYPT=false
|
||||||
|
SESSION_PATH=/
|
||||||
|
SESSION_DOMAIN=null
|
||||||
|
|
||||||
|
BROADCAST_CONNECTION=log
|
||||||
|
FILESYSTEM_DISK=local
|
||||||
|
QUEUE_CONNECTION=database
|
||||||
|
|
||||||
|
CACHE_STORE=database
|
||||||
|
CACHE_PREFIX=
|
||||||
|
|
||||||
|
MEMCACHED_HOST=127.0.0.1
|
||||||
|
|
||||||
|
REDIS_CLIENT=phpredis
|
||||||
|
REDIS_HOST=127.0.0.1
|
||||||
|
REDIS_PASSWORD=null
|
||||||
|
REDIS_PORT=6379
|
||||||
|
|
||||||
|
MAIL_MAILER=log
|
||||||
|
MAIL_HOST=mailhost
|
||||||
|
MAIL_PORT=1025
|
||||||
|
MAIL_USERNAME=null
|
||||||
|
MAIL_PASSWORD=null
|
||||||
|
MAIL_ENCRYPTION=null
|
||||||
|
MAIL_FROM_ADDRESS="hello@example.com"
|
||||||
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
AWS_ACCESS_KEY_ID=
|
||||||
|
AWS_SECRET_ACCESS_KEY=
|
||||||
|
AWS_DEFAULT_REGION=us-east-1
|
||||||
|
AWS_BUCKET=
|
||||||
|
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||||
|
|
||||||
|
VITE_APP_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
SETUP_APP_PORT=80
|
||||||
|
SETUP_PMA_PORT=8888
|
10
exec
Executable file
10
exec
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$(basename $(pwd))" == "laravel" ]]; then
|
||||||
|
cd ..
|
||||||
|
./exec "$@"
|
||||||
|
cd laravel
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker compose exec -it app $@
|
62
setup
Executable file
62
setup
Executable file
|
@ -0,0 +1,62 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$(basename $(pwd))" == "laravel" ]]; then
|
||||||
|
cd ..
|
||||||
|
./setup
|
||||||
|
cd laravel
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker compose down
|
||||||
|
|
||||||
|
for executable in start stop setup exec art switch-branch-migrate; do
|
||||||
|
ln -sf ../$executable laravel/$executable
|
||||||
|
done
|
||||||
|
|
||||||
|
dockerUID=$(id -u)
|
||||||
|
dockerGID=$(id -g)
|
||||||
|
|
||||||
|
mkdir dbdata &> /dev/null
|
||||||
|
|
||||||
|
echo "Container build in progress.."
|
||||||
|
composer_docker_hash=$(docker build -q docker_build)
|
||||||
|
docker run --user $dockerUID:$dockerGID --rm -v ./laravel:/var/www/html -it $composer_docker_hash composer install
|
||||||
|
cp env_docker laravel/.env
|
||||||
|
cp env_docker .env
|
||||||
|
echo "dockerUID=$dockerUID" >> .env
|
||||||
|
echo "dockerGID=$dockerGID" >> .env
|
||||||
|
|
||||||
|
if [ -z "$(ls -A dbdata)" ]; then
|
||||||
|
echo "Initialising database.."
|
||||||
|
docker compose up database -d &> /dev/null
|
||||||
|
while ! docker compose logs database | grep -q 'mysqld: ready for connections'; do
|
||||||
|
sleep 0.5
|
||||||
|
done
|
||||||
|
docker compose down database &> /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker compose up database -d &> /dev/null
|
||||||
|
while ! docker compose logs database | grep -q 'mysqld: ready for connections'; do
|
||||||
|
sleep 0.5
|
||||||
|
done
|
||||||
|
docker compose down database &> /dev/null
|
||||||
|
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
echo "Waiting for app to start up..."
|
||||||
|
while ! docker compose logs app | grep -q 'Command line: '; do
|
||||||
|
sleep 0.5
|
||||||
|
done
|
||||||
|
|
||||||
|
docker compose exec app php artisan key:generate
|
||||||
|
docker compose exec app php artisan config:cache
|
||||||
|
|
||||||
|
echo "Waiting for database to start up..."
|
||||||
|
while ! docker compose logs database | grep -q 'mysqld: ready for connections'; do
|
||||||
|
echo "not ready.."
|
||||||
|
sleep 0.5
|
||||||
|
done
|
||||||
|
|
||||||
|
docker compose exec app php artisan migrate:fresh --seed
|
||||||
|
docker compose exec app php artisan test
|
||||||
|
docker compose down
|
10
start
Executable file
10
start
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$(basename $(pwd))" == "laravel" ]]; then
|
||||||
|
cd ..
|
||||||
|
./start
|
||||||
|
cd laravel
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker compose up
|
10
stop
Executable file
10
stop
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$(basename $(pwd))" == "laravel" ]]; then
|
||||||
|
cd ..
|
||||||
|
./stop
|
||||||
|
cd laravel
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker compose down
|
22
switch-branch-migrate
Executable file
22
switch-branch-migrate
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$(basename $(pwd))" == "laravel" ]]; then
|
||||||
|
cd ..
|
||||||
|
./switch-branch-migrate "$@"
|
||||||
|
cd laravel
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
branch_name=$1
|
||||||
|
|
||||||
|
cd laravel
|
||||||
|
|
||||||
|
if git show-ref --verify --quiet refs/heads/"$branch_name"; then
|
||||||
|
git checkout "$branch_name"
|
||||||
|
else
|
||||||
|
git checkout -b "$branch_name"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
docker compose exec app php artisan migrate:fresh --seed
|
Loading…
Add table
Reference in a new issue