Commit f63fe819 authored by Tobias Munk's avatar Tobias Munk

various guide updates

parent 025cb747
......@@ -5,17 +5,22 @@ Configuration
phd uses an environment variables based configuration, see also [Dev/prod parity](http://12factor.net/dev-prod-parity) for more information about this topic.
There are two level of environment configurations.
There are two levels of environment configurations.
**Variables for controlling the application stacks *(outside on your host)* with `docker-compose`, are defined in `.env` files.**
Variables for controlling the application stacks *(outside on your host)* with `docker-compose`, are defined in
- `.env` files.
**Environment settings used within the application services *(inside a container)* are defined in `*.yml` files and `src/app.env`.**
## Basic configuration
Environment settings used within the application services *(inside a container)* are defined in
- `docker-compose.yml`, `docker-compose.<ENV>.yml` files (environment specific)
- `Dockerfile` and/or `src/app.env` (application defaults).
:exclamation: Before starting the application the first time, update your `.env-dist`, `tests/.env-dist` and `src/app.env` files with sane defaults for the new project.
See also hierarchy & scopes below for more information about variables.
## Host environment
:exclamation: Before starting the application the first time, run `make init` to create your `.env` and `tests/.env` from `.dist`-files.
### Development stack
......@@ -25,25 +30,24 @@ There are two level of environment configurations.
### Testing stack
COMPOSE_PROJECT_NAME=test-myapp
COMPOSE_PROJECT_NAME=testmyapp
STACK_PHP_IMAGE=local/namespace/myapp_php
> Windows users, use a semicolon as path separator `COMPOSE_FILE=./docker-compose.yml;./docker-compose.dev.yml`
### Application environment
## Application environment
> `app.env-dist` should be adjusted and committed to reflect basic application settings, but we strongly recommend **not to add secrets** like passwords or tokens to the repository.
> Note: The `app.env-dist` file is intentionally copied as `app.env` onto the image. If you want to make changes during runtime, you also need to create a local file and mount this into the container.
Initial configuration adjustments should be made for the following values
Initial configuration adjustments should be made for the following values:
APP_NAME=myapp
APP_TITLE="MyApp"
APP_LANGUAGES=en,fr,zh
> :build: Within a `phd5-app` we recommend to update `app.env-dist` settings, while in a `phd5-template` we usually update the `Dockerfile`.
> `app.env-dist` should be adjusted and committed to reflect basic application settings, but we strongly recommend **not to add secrets** like passwords or tokens to the repository.
> Note: The `app.env-dist` file is intentionally copied as `app.env` onto the image. If you want to make changes during runtime, you also need to create a local file and mount this into the container.
> To be able to use translatemanager every defined/used language must be present in the app_language table.
> You can insert new languages in backend:
> http://<YOUR_DOMAIN>/translatemanager/language/create
## Advanced configuration
......@@ -58,6 +62,10 @@ Further important settings
For all available environment settings, see `src/app.env`.
> To be able to use translatemanager every defined/used language must be present in the app_language table.
> You can insert new languages in backend:
> http://<YOUR_DOMAIN>/translatemanager/language/create
### Development & debugging
During **local development** it is recommended to enable debug settings in `src/app.env`.
......@@ -72,10 +80,11 @@ You find the config files for an application in `src/config`, those can also be
- `config/main.php` - main application configuration entrypoint
- `config/common.php` - configuration for web and console applcations
-
> :exclamation: An important difference between application and environment configuration is that
> ENV variables are immutable by default, but values in PHP arrays can be overwritten.
> ENV variables are usually immutable by convention.
## Hierarchy & scopes
......@@ -102,4 +111,3 @@ ENV variable are immutable by convention, so if a value is set in a `Dockerfile`
Only values in `app.env` can be changed while the containers are running. If you change environment variables in
`docker-compose.yml` you need to restart your containers.
## Code conventions
# Code conventions
Branches
--------
## Source-Code
### Git branches
The phd repository contains the following main branches:
- master (development, unstable)
- 4.0 (alpha, beta, RC, stable releases)
- 3.0 (alpha, beta, RC, stable releases)
- DO not add secrets....
- x.y (alpha, beta, RC, stable releases)
### Source-Code
### PHP
- PSR-2
- all code, variables, tables, databases, constants - everything in the source code **MUST BE** written and named in English
- resources **SHOULD NOT** be loaded from a server or CDN during development & testing
- migrations **MUST NOT** be changed after they are comitted and pushed
- migrations **MUST NOT** use model classes
- committed code **MUST NOT** contain secrets
- classes **MUST** use English names
- variables in code **SHOULD** use `camelCase`
- database properties **SHOULD** use `$this->table_field`
#### PHP
- PSR-2
### Yii
##### Console
- MUST add `Tester` classes to the repository
- SHOULD use `Yii::info()` or `Yii::trace()`, NOT `Yii::getLogger->(..., ..., ...)`
- SHOULD NOT use `application.language = null` with `codemix/yii2-localeurls`
- SHOULD NOT use static `::className()` calls in application configuration
- Console commands **SHOULD** print a newline at the end of their output `$this->stdout("Done".PHP_EOL)`
end of command:
### Widgets
$this->stdout("Done.\n");
- references **SHOULD NOT** use absolute URLs
### Twig
#### LESS
- If attributes in *Twig* templates need to be translated and scanned by the **Translatemanager** module you need to use the following syntax
- CSS framework core classes, eg. `container`, `row`, `col-*` **MUST NOT** be modified
data-content={{ t('catalogue', '__TOOLTIP_TEXT__' | escape('html_attr')) }}
#### docker-compose
### LESS/CSS
##### Production
- CSS framework core classes, eg. `container`, `row`, `col-*` **MUST NOT** be modified
- SHOULD use hyphens for CSS classes and ID's i.e. `.my-class` and `#my-id`
- https://github.com/CSSLint/csslint/wiki/disallow-ids-in-selectors
- nginx web services in production **SHOULD** define a `VIRTUAL_HOST` environment variable, which is used by the reverse-proxy
### Giiant (Backend CRUD)
- providers **MUST NOT** be copied into the project, may can extend a new class
- SHOULD contain `Id` columns
### Documentation
- `README.md` in project root (max. 300 lines)
- `docs/` detailed project documentation
- `docs/README.md` index
- `docs/troubleshooting.md` "Esoteric features"
- Source-code docblocks
## Docker
-----
### Volumes
# Coding conventions
- host-volumes **MUST NOT** overlap
- host-volumes **SHOULD NOT** contain single files
> **Heads up!** This section is under development.
### Images
- DO NOT repeat yourself
- USE PSR-2
- All production images **MUST BE** tagged
## Confiuration
- MUST NOT contain secrects
## Documentation
## Docker
- `README.md` in project root (max. 300 lines)
- `docs/` detailed project documentation
- `docs/README.md` index
- `docs/troubleshooting.md` "Esoteric features"
- Source-code docblocks
- host-volumes MUST NOT overlap
- all containers SHOULD keep running, eg. data-containers with `tail -f /dev/null`
## Database (MySQL)
- camelCase_id
- MUST USE non-project specific default values
- SHOULD have an idempotent setup (see `BaseAppCommand`)
## PHP
### Classes
- MUST USE English names
### Variables
- camelCase
- $this->table_field;
### Yii
- **MUST USE** non-project specific default values
- **SHOULD** have an idempotent setup (see `AppCommand`)
- MUST add `Tester` classes to the repository
- SHOULD use `Yii::info()` or `Yii::trace()`, NOT `Yii::getLogger->(..., ..., ...)`
- SHOULD NOT use `application.language = null` with `codemix/yii2-localeurls`
- SHOULD NOT use static `::className()` calls in application configuration
### Giiant (Backend CRUD)
- providers MUST NOT be copied into the project, may can extend a new class
- SHOULD contain `Id` columns
## CSS
- SHOULD use hyphens for CSS classes and ID's i.e. `.my-class` and `#my-id`
- https://github.com/CSSLint/csslint/wiki/disallow-ids-in-selectors
## JavaScript
## bash
......@@ -31,7 +31,7 @@ View files can be found in `src/views/layouts`.
## Debugging application
- /debug
- `/debug`
Events
......@@ -39,26 +39,5 @@ Events
### Context menu items
Module: Prototype
--------
This module has very limited features and has been mainly developed to create tiny static sites. It basically allows
you to add HTML and LESS files to your site.
### Create asset bundle for LESS from the database
See [Online help](https://github.com/dmstr/docs-phd5/blob/master/help/frontend-less.md)
- go to `/prototype/less`
- create key `main`
- add example LESS content
- save
### Create widget for view contents
See [Online help](https://github.com/dmstr/docs-phd5/blob/master/help/frontend-twig.md)
TBD
......@@ -5,6 +5,10 @@ Installation
> You can run phd also with [composer](../6-tutorials/installation-composer.md)
> for example within a Vagrant VM.
## Choosing the right boilerplate
TBD
## phd5-app
When starting a new project it is recommended to **download the [latest release](https://github.com/dmstr/phd5-app/releases)**
......@@ -39,6 +43,9 @@ very easy.
composer install --ignore-platform-reqs -o
---
TBD: Note about dev-packages
---
......
......@@ -27,6 +27,12 @@ Sitemap
HTML-Validator
--------------
docker run --rm magnetikonline/html5validator \
java -jar /root/build/validator.nu/vnu.jar \
URL
Run via `docker-compose.yml`
validator:
image: magnetikonline/html5validator
entrypoint: ["java", "-jar", "/root/build/validator.nu/vnu.jar"]
......
......@@ -141,3 +141,27 @@ Console vs. Web config
----
TBD: VersionCept: Check application versioning
----
### Speedup MySQL
db:
tmpfs:
- /var/lib/mysql
---
- [Codeception Page load helper](https://gist.github.com/schmunk42/d0a388bc3562bf9bb8eafe153b9b7870)
---
### Testing with different images using triggers
curl -X POST \
-F token=${TOKEN} \
-F "ref=tests/mysql" \
-F "variables[STACK_MYSQL_IMAGE]=mysql:5.5" \
https://gitlab.com/api/v3/projects/2370540/trigger/builds
\ No newline at end of file
Troubleshooting
FAQ/Troubleshooting
===============
For more frequently asked questions (FAQ) see [GitHub](https://github.com/dmstr/docker-phd5-app/issues) and [Stackoverflow](http://stackoverflow.com/questions/tagged/phundament)
......@@ -39,11 +39,9 @@ You need to use https://getcomposer.org/doc/articles/aliases.md, see also https:
"asset-pattern-skip-version": "(-build|-patch)"
Docker
------
#### Port is already allocated
ERROR: Cannot start container 88b754d7e46aca58961ef0a049216f0e7331e35ba905d84fab01016a4797a779: failed to create endpoint appdev_mariadb_1 on network bridge: Bind for 0.0.0.0:43306 failed: port is already allocated
......@@ -66,7 +64,6 @@ See https://github.com/chadoe/docker-cleanup-volumes
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes
#### Service 'php' failed to build
Pulling repository docker.io/phundament/php-one
......@@ -108,6 +105,24 @@ Login docker CLI
> Note! Check if Docker saves the credentials locally in `~/.docker`
#### Slow running tests
- check DNS settings
- check shared memory settings for *Selenium* container (`/dev/shm`)
- removed unnecessary host-volumes
#### `chown` commands in Dockefile
For every file, which is "chownd" a copy is created...
> The filesystem has to copy up the the file into the new layer so that it can be chowned.
- https://github.com/moby/moby/issues/22810
## Alpine
- https://wiki.alpinelinux.org/wiki/Upgrading_Alpine#Upgrading_to_Edge
### Gitlab CI Server
......@@ -126,6 +141,8 @@ In case of weird errors you have the following workaround options, which you sho
- Reboot the runner-host (runners should have `restart=always` policy)
- Recreate the runner-host (**last resort**)
#### Pushing
$ bash build/scripts/deploy.sh
......
# Requirements
## On your host-system
To run **phd** you need Docker, on your host-system. While older versions should also work, here are the minimum versions which are actively tested and supported.
- [`docker >=1.10.0`](https://docs.docker.com)
- [`docker-compose >=1.8.0`](https://github.com/docker/compose) *included in Docker for Mac and Windows*,
on Linux the fastest way to get it is probably `sudo pip install docker-compose`.
- `git` (optional)
- `make` (optional)
- [`docker >=1.11.0`](https://docs.docker.com)
- [`docker-compose >=1.8.0`](https://github.com/docker/compose)
You can create your Docker environment with *Docker for Mac/Windows* or with `docker-machine` from *Docker Toolbox*.
Optional but recommended
- `git`
- `make`
- `composer`
> :bangbang: Due to disk performance issues like ... it's currently a recommended workaround to run composer from your host system for
> updates.
>
> `composer global require fxp/composer-asset-plugin wikimedia/composer-merge-plugin`
### Docker
You can create your *Docker* environment with
- *Docker for Mac/Windows* or a package-manager on Linux | [Docs](https://docs.docker.com)
- `docker-machine` from *Docker Toolbox* as a VM or cloud-based host | [Docs](https://docs.docker.com)
- *Vagrant* with a customized VM setup | [Source-Code](https://github.com/dmstr/vado-ligure)
### Compose
On Linux the fastest way to get it is probably `sudo pip install docker-compose`.
## Testing your requirements
To test if your environment is ready, simply run the following status commands, if you do not see any errors, you are good to go!
......@@ -17,10 +39,6 @@ To test if your environment is ready, simply run the following status commands,
docker info
docker ps
> :bangbang: Due to disk performance issues like ... it's currently a recommended workaround to run composer from your host system for
> updates.
composer global require fxp/composer-asset-plugin wikimedia/composer-merge-plugin
## Non-dockerized installation
......
### GitLab CI
- :blue_book: http://docs.gitlab.com/ce/ci/yaml/README.html
#### Setup
Add variable `REGISTRY_HOST`
### Setup
Set **Variables**
- `PHP_IMAGE_NAME` registry.example.com/namespace/project_php
- `GITHUB_API_TOKEN` abcd1234
-----
### Travis
Push example
```
after_success: |
docker login -u="$REGISTRY_USER" -p="$REGISTRY_PASS" $REGISTRY_HOST
if [ "${TRAVIS_BRANCH}" = "release" ]; then
docker tag ${STACK_PHP_IMAGE} ${STACK_PHP_IMAGE_LATEST}
docker-compose push || exit 1
docker push ${STACK_PHP_IMAGE_LATEST} || exit 1
fi
docker logout
```
---
Example trigger for [`stacks-staging`](https://git.hrzg.de/dangerzone/stacks-staging)
```
deploy:latest:
stage: deploy
script:
- curl -X POST -F token=${PROJECT_TOKEN} -F ref=${PROJECT_REF} -F "variables[REDEPLOY_STACK_DIR]=${STACK_DIR}" https://git.hrzg.de/api/v3/projects/256/trigger/builds
only:
- latest
```
\ No newline at end of file
......@@ -35,7 +35,11 @@ To add it to your application adjust configuration in `src/config/common.php`.
]
];
You should now be able to access to module default page via `/frontend` in your browser.
You should now be able to access to module default page via `/frontend` in your browser.
> :information_source: Please note that standard Yii modules do not have access control enabled by default.
The generated source-files, like controllers and views can be found in `src/modules/frontend`.
Backend CRUD module
-------------------
......
......@@ -16,7 +16,7 @@ Enter your docker-host IP and the mapped host-port of the database container int
Or you can add an web-based management interface like `clue/adminer` or `phpmyadmin/phpmyadmin`. Usually these
containers can be linked to the database server.
> Note! Links will become deprecated in a future version of Docker.
> Note! Links will become deprecated in a future version of Docker.
Using a PostgreSQL database
......@@ -68,3 +68,7 @@ Run migrations and create an admin
$ yii migrate
$ yii app/setup-admin-user
----
TBD: Table prefix info
\ No newline at end of file
......@@ -7,15 +7,11 @@ Custom configuration `build/container-files/etc/nginx/conf.d/app.conf`.
### Customizing startup and webserver configuration
You can build your custom container image on top of the [phd Docker container](https://registry.hub.docker.com/u/phundament/app/) ([repository](https://github.com/phundament/docker)).
Just use the `FROM` instruction in your `Dockerfile`
You can add your custom configuration to he container image on top of `dmstr/php-yii2` or `phd5-app`
Grab the file from a running container by copying it into the `image-files` directory.
FROM phundament/app
Start or use a running container to copy the startup files into your `build/` directory.
docker cp app_web_1:/root/run.sh build/
docker cp app_web_1:/etc/nginx/sites-available/default build/
mkdir -p image-files/etc/nginx/nginx.conf
docker cp app_php_1:/etc/nginx/nginx.conf image-files/etc/nginx/nginx.conf
#### BASIC_AUTH example
......
......@@ -117,3 +117,8 @@ Set constraint to `@dev` before starting code modifications and run
> into the package folder. `git status` should now your changes now.
### Forking asset repositories
TBD
See also https://github.com/dmstr-forks
......@@ -40,6 +40,14 @@ Set admin password
docker-compose run --rm php yii user/password admin admin1
```
Create initial users
$ yii user/create dev@example.com dev Passw0rd
$ yii rbac/assign FrontendDeveloper dev
$ yii user/create editor@example.com editor Passw0rd
$ yii rbac/assign Editor editor
Start stack
```
......
......@@ -19,9 +19,12 @@
- docker
- docker-compose
- docker-swarm
- docker-roj
---
- https://github.com/pwaller/docker-show-context
### Docker images
- PHP
......@@ -102,6 +105,8 @@
- https://github.com/neam/docker-stack/tree/master/stacks/schmunk42/elk-v2
- phpservermon
- https://github.com/nicolaka/netshoot (Troubleshooting)
### QA
- https://packagist.org
......@@ -129,6 +134,7 @@
- http://fontcdn.org/
- http://bootstrap-live-customizer.com/
- https://startbootstrap.com/
### Applications
......
......@@ -6,3 +6,16 @@ Running `composer update` updates the application packages.
Adjust `migrationPaths` if needed.
Run `yii migrate`.
----
update base image
check composer.json merge
make upgrade
----
If you can not build the image, ie. due to a broken `composer.lock` file, revert its changes
and run the update again.
\ No newline at end of file
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