Commit fb9fb9d4 authored by Manuel Christlieb's avatar Manuel Christlieb
Browse files

git init

parents
.DS_STORE
*.sql
.php_cs.cache
build/config.local.yml
build/docker-compose.override.yml
# Laravel specific files
/web/public/.htaccess
/web/public/css
/web/public/js
# Deployment
# About
This skeleton is a starting point for laravel installations running in docker and using b5.
It can be used with b5-init to quickly start new projects.
On init a lot of stuff happens:
* download and build docker containers
* ask you to edit the new projects config.yml
* create required configuration from templates
# Install
## Install with b5-init (recommended)
```
b5-init -s <skeleton> <path>
```
where **skeleton** is a skeleton git repository (like this) and the **path** you want the project installed to.
If the skeleton git has this url-format: git@git.team23.de:build/b5-skel-*.git, then you might save yourself some
time by just typing
```
b5-init -s laravel <path>
```
During project init you will be asked to configure the project's config.yml.
## Clone and run (for dev)
First clone this repository and change into it's path. then run:
```
b5 --run-path init --config config.yml --config config.init.yml --config config.local.yml project:init
```
Note how this uses init/ as run-path for b5 and then calls the project:init task.
# Enable traefik
Because you want to enable traefik there is a task for it:
```
b5 enable_traefik
```
# Running the project
As with every other docker and b5 project:
Start the containers with **b5 run** or **b5 run -d** for running in background.
# Housekeeping
To update the project:
```bash
b5 update
```
# Notes
b5-init -s laravel yeah && b5 run && und alle so: yeah!
# pre-commit.sh
b5 composer lint:show
RESULT=$?
[ $RESULT -ne 0 ] && exit 1
exit 0
#!/usr/bin/env bash
# b5 Taskfile, see https://git.team23.de/build/b5 for details
# global vars for all Tasks
WEBROOT="${CONFIG_paths_web:-../web/}"
PROJECT_NAME="${CONFIG_project_name:-'I have no name'}"
DB_HOST="${CONFIG_application_database_host:-db}"
DB_USERNAME="${CONFIG_application_database_username:-docker}"
DB_PASSWORD="${CONFIG_application_database_password:-docker}"
DB_DATABASE="${CONFIG_application_database_database:-docker}"
DB_PORT="${CONFIG_application_database_port:-3306}"
DB_DUMP_LOCAL_PATTERN="${CONFIG_paths_db}/$( date "+%Y-%m-%d" )-${CONFIG_project_key}-local.sql.gz"
task:install() {
setup-git-hooks
setup-env
setup-htaccess
docker:install
composer install
artisan key:generate
template:render --overwrite ask-if-older templates/config.local.yml.jinja2 config.local.yml
}
task:update() {
setup-git-hooks
setup-env
setup-htaccess
docker:update
composer install
template:render --overwrite ask-if-older templates/config.local.yml.jinja2 config.local.yml
}
task:run() {
docker:docker-compose up "$@"
}
task:halt() {
docker:docker-compose down "$@"
}
task:shell() {
docker:container_run "${1:-php}" /bin/bash
}
task:docker-compose() {
docker:docker-compose "$@"
}
task:css() {
npm run dev
}
task:watch() {
npm run watch
}
##################################################
# Helper Tasks to copy .env if needed or run cli #
# tools in the docker container. These cli #
# commands are defined in config.yml #
##################################################
setup-env() {
(
if [ -f ${WEBROOT}/.env ]; then
echo ".env file exists."
else
cp ${WEBROOT}/.env.example ${WEBROOT}/.env
echo ".env file created."
fi
)
}
setup-htaccess() {
(
if [ -f ${WEBROOT}/public/.htaccess ]; then
echo ".htaccess file exists."
else
cp ${WEBROOT}/public/_.htaccess ${WEBROOT}/public/.htaccess
echo ".htaccess file created."
fi
)
}
setup-git-hooks() {
git config core.hooksPath build/.githooks
echo "Set build/.githooks as hooks path"
}
composer() {
docker:command:composer "$@"
}
task:composer() {
composer "$@"
}
artisan() {
docker:command:artisan "$@"
}
task:artisan() {
artisan "$@"
}
npm() {
docker:command:npm "$@"
}
task:npm() {
npm "$@"
}
phpunit() {
docker:command:phpunit "$@"
}
task:phpunit() {
phpunit "$@"
}
task:db:export() {
mkdir -p "${CONFIG_paths_db}" && \
docker:container_run --pipe-out --force-exec db mysqldump --default-character-set=utf8 --set-charset --single-transaction \
--disable-keys -h db --protocol=TCP -u "docker" \
"-pdocker" \
"docker" \
| gzip \
> "$DB_DUMP_LOCAL_PATTERN"
}
task:db:import() {
local DUMPNAME=${1:-}
if [ -z "$DUMPNAME" ]
then
DUMPNAME="live"
fi
case "${DUMPNAME}" in
# live)
# DUMPNAME="stw_live_$( date "+%Y-%m-%d" ).sql.gz"
# ;;
local)
DUMPNAME="$DB_DUMP_LOCAL_PATTERN"
;;
esac
if [ ! -e "${CONFIG_paths_db}/${DUMPNAME}" ]
then
echo "Dump does not exist"
echo "(${CONFIG_paths_db}/${DUMPNAME})"
return 1
fi
cat "${CONFIG_paths_db}/${DUMPNAME}" | gunzip \
| docker:container_run --pipe-in --force-exec db mysql -h db --protocol=TCP \
-u "docker" \
"-pdocker" \
-D "docker"
}
version: '3'
services:
phpmyadmin:
ports:
- "8001:80"
web:
ports:
- "8000:80"
mail:
ports:
- "8025"
version: '3'
services:
phpmyadmin:
networks:
- default
- traefik_gateway
labels:
- traefik.enable=true
- traefik.docker.network=traefik_gateway
web:
networks:
- default
- traefik_gateway
labels:
- traefik.enable=true
- traefik.frontend.passHostHeader=true
- traefik.docker.network=traefik_gateway
mail:
networks:
- default
- traefik_gateway
labels:
- traefik.enable=true
- traefik.port=8025
- traefik.docker.network=traefik_gateway
networks:
default:
traefik_gateway:
external: true
version: '3'
services:
db:
image: docker.team23.de/docker/mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: "Testen23!"
MYSQL_DATABASE: docker
MYSQL_USER: docker
MYSQL_PASSWORD: docker
volumes:
- db:/var/lib/mysql/:delegated
php:
image: docker.team23.de/docker/php:7.2
volumes:
- ../:/app:cached
- ~/.composer:/var/www/.composer
environment:
UMASK: 0002
links:
- redis
depends_on:
- db
- redis
redis:
image: redis
node:
image: node:10-stretch
volumes:
- ../:/app:cached
phpmyadmin:
image: phpmyadmin/phpmyadmin:4.7
environment:
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: Testen23!
depends_on:
- db
web:
image: docker.team23.de/docker/apache:2.4-php
environment:
APACHE_DOCUMENT_ROOT: /app/web/public
volumes:
- ../:/app:cached
depends_on:
- php
- db
mail:
image: mailhog/mailhog
volumes:
db:
# Place ssh configuration here for hosts used in this project.
# DO NOT INPUT CREDENTIALS, this file is shared in git.
# Example:
#
# Host hostnameOrAlias
# HostName realHostNameOrIP
# User team23
# Using traefik:
#modules:
# docker:
# docker_compose_config_overrides:
# - traefik
# Using traefik:
modules:
docker:
docker_compose_config_overrides:
- traefik
#!/usr/bin/env bash
### First install tasks
# Run after checking out the project for initial project setup
# After that: run cleanup:inittasks to remove this Taskfile and files which were only needed for the first install
PROJECT_KEY=""
PROJECT_NAME=""
WEBROOT="../web/"
DB_HOST="${DB_HOST:-db}"
DB_USERNAME="${DB_USERNAME:-docker}"
DB_PASSWORD="${DB_PASSWORD:-docker}"
DB_DATABASE="${DB_DATABASE:-docker}"
DB_PORT="${DB_PORT:-3306}"
SETUP_TYPE=""
ALLOWED_SETUP_TYPES=("traefik" "localhost")
DEFAULT_SETUP_TYPE="traefik"
init:questions() {
# PROJECT NAME
while [ -z "$PROJECT_NAME" ]; do
read -e -p "Enter the project name: " PROJECT_NAME
done
# PROJECT KEY
while [ -z "$PROJECT_KEY" ]; do
read -e -p "Enter the project key (alphanumeric and hyphen, no leading or trailing hyphen): " PROJECT_KEY
case $PROJECT_KEY in
-* ) echo "Illegal Input, must not start with hyphen."; unset PROJECT_KEY;;
*- ) echo "Illegal Input, must not end with hyphen."; unset PROJECT_KEY;;
*[^a-zA-Z0-9-]* ) echo "Illegal input, only alphanumeric and - allowed.";unset PROJECT_KEY;;
esac
done
# SETUP TYPE
while [ -z "$SETUP_TYPE" ]; do
read -e -p "Enter the setup type (traefik or localhost) [traefik]: " SETUP_TYPE
[ -z "$SETUP_TYPE" ] && SETUP_TYPE="$DEFAULT_SETUP_TYPE"
case $SETUP_TYPE in
traefik ) echo "Use traefik setup";;
localhost ) echo "Use localhost setup";;
* ) echo "Illegal input, only localhost or traefik allowed";unset SETUP_TYPE;;
esac
done
}
init:summary() {
echo "Project name: $PROJECT_NAME"
echo "Project key: $PROJECT_KEY"
echo "SETUP_TYPE: $SETUP_TYPE"
}
init:export-vars() {
# we need to export the vars, else they are not available in forked shells
export PROJECT_NAME="$PROJECT_NAME"
export PROJECT_KEY="$PROJECT_KEY"
export SETUP_TYPE="$SETUP_TYPE"
}
init:build:render() {
template:render templates/config.yml.jinja2 ../build/config.yml
template:render templates/config.local.yml.jinja2 ../build/config.local.yml
}
task:project:init() {
ln -s ../build/docker-compose.yml .
ln -s ../build/docker-compose.traefik.yml .
ln -s ../build/docker-compose.localhost.yml .
init:questions
init:summary
init:export-vars
init:build:render
docker:container_run -w /app php "composer create-project --prefer-dist laravel/laravel web"
cp ${WEBROOT}/public/.htaccess ${WEBROOT}/public/_.htaccess
template:render templates/.env.jinja2 ../web/.env
b5 install
b5 update
b5 run -d
# # now setup the project
#
# # stop running docker again
b5 halt
rm -rf ../init
}
modules:
docker:
template:
APP_NAME="{{ env.PROJECT_NAME }}"
APP_ENV=local
APP_KEY=base64:bMjWTLMjKAMIY/VlD/YuauVkSuS4CiVqZFhVR16xaRs=
APP_DEBUG=true
APP_URL=http://{% if env.SETUP_TYPE == 'localhost' %}localhost:8000{% else %}web.{{ env.PROJECT_KEY }}.t23dev{% endif %}
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST={{ env.DB_HOST }}
DB_PORT={{ env.DB_PORT }}
DB_DATABASE={{ env.DB_DATABASE }}
DB_USERNAME={{ env.DB_USERNAME }}
DB_PASSWORD={{ env.DB_PASSWORD }}
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
modules:
docker:
docker_compose_config_overrides:
- {% if env.SETUP_TYPE == 'localhost' %}localhost{% else %}traefik{% endif %}
# This is the central configuration for all tools we use/execute.
# It is parsed inside the Taskfile, too. See $CONFIG_project_name
# for example.
project:
name: {{ env.PROJECT_NAME }}
key: {{ env.PROJECT_KEY }}
url: https://not.existing.yet/
env:
httpd_group: 33
paths:
web: ../web
db: ../_db
application:
database:
username: docker
password: docker
database: docker
host: db
modules:
template:
docker:
# This allows for configuration switching. Use "traefik" when switching over to traefik. Put this
# into your config.local.yml, DO NOT CHANGE IT HERE.
docker_compose_config_overrides:
- localhost
commands:
composer:
bin: composer
service: php
workdir: /app/web/
no_deps: true
user: www-data
npm:
bin: npm
service: node
workdir: /app/web/
no_deps: true
artisan:
bin: ["php", "./artisan"]
service: php
workdir: /app/web/
no_deps: true
user: www-data
phpunit:
bin: ["php", "./vendor/bin/phpunit"]
service: php
workdir: /app/web/
no_deps: true
user: www-data
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment