Commit 13758650 authored by Tobias Munk's avatar Tobias Munk

updated deployment

parent 86bd84db
Continuous integration
======================
> TODO: build -> version only in test
*phd* is designed to easily run in various CI/CD tools supporting *Docker*.
## Using *Git* branches to build releases and trigger deployments
make latest
make release
Example: Gitlab CI
- build
- test
- report
- deploy
- cleanup
> http://docs.gitlab.com/ce/ci/yaml/README.html
## Introduction
### GitLab CI
Add variable `REGISTRY_HOST`
### Workflow diagram
<div class="mermaid">
---
graph LR;
build(Build)
test(Testing)
release(Release)
image((Image))
subgraph CI
build
test
release
end
subgraph Registry
image
end
Example trigger for [`stacks-staging`](https://git.hrzg.de/dangerzone/stacks-staging)
build==>test
test==>release
test-->report
release-->image
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
</div>
Variables:
- Clone application from local repository
- Start application `make all`
- Make changes in local development stack
- Run tests in isolated local testing stack `make TEST up setup run-tests`
- Commit (triggers CI)
- CI builds images
- CI starts isolated stacks (by setting custom `COMPOSE_PROJECT_NAME`s) from built images and performs setup operations
- CI runs tests (also acceptance tests with Selenium containers)
- CI creates reports
- CI performs cleanup of isolated stacks
- CI tags images and pushes them to a registry (if tests were successful)
- `PROJECT_TOKEN` - token from `stacks-staging` project
- `PROJECT_REF` - branch, usually `master`
- `PROJECT_DIR` - location of `docker-compose.yml`, eg. `auto/cusomter/www.example.com`
### Setup
Set **Variables**
## Configuration
- `PHP_IMAGE_NAME` registry.example.com/namespace/project_php
- `GITHUB_API_TOKEN` abcd1234
During local development the images build for the application stack are named by `docker-compose`, if not specified otherwise. For testing they are by default named `registry/namespace/phd5` via setting the `STACK_PHP_IMAGE` variable used in `docker-compose.test.yml`.
In the CI we override this variable by setting it in the configuration to the actual image name we want to push later, eg. `registry.example.com/mycomany/the-project` for private registries or `vendor/image` for usage with *DockerHub*.
---
### Workflow
1. Clone application from local repository
2. Start application `make all`
3. Make changes in local development stack
4. (optional) Run tests in isolated local testing stack `make TEST up setup run-tests`
5. Commit (triggers CI)
6. CI builds images
7. CI starts isolated stacks (by setting custom `COMPOSE_PROJECT_NAME`s) from built images and performs setup operations
8. CI runs tests (also acceptance tests with Selenium containers)
9. CI creates reports
10. CI performs cleanup of isolated stacks
11. CI tags images and pushes them to a registry (if tests were successful)
## Usage
### Using *Git* branches to build releases and trigger deployments
Run the test suites from build scripts
Build, test and push a `:latest` image
$ sh build/scripts/build.sh
$ sh build/scripts/test.sh
```
make latest
```
Build, test and push a `:1.2.3-4-gfedcba98` image
#### Building the `:production` image
```
make release
```
Adjust your `Dockerfile` and build `FROM phundament/app:production`.
---
make build
Setup ENv variables in roj PROJECT_TOKEN
-----
Setup ENv variables in roj
PROJECT_TOKEN
----
### Travis
## Deployment
Push example
Variables:
```
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
```
- `PROJECT_TOKEN` - token from `stacks-staging` project
- `PROJECT_REF` - branch, usually `master`
- `PROJECT_DIR` - location of `docker-compose.yml`, eg. `auto/cusomter/www.example.com`
Production
----------
- All images MUST BE tagged
<div class="mermaid">
graph LR;
deploy(Deployment)
image((Image))
Push to branch `foo` results in Docker image `appsrc:foo`.
image---server
deploy-->server
---
subgraph CI
deploy
end
subgraph Registry
image
end
<div class="mermaid">
graph LR;
Local-->Repository;
Repository-->Image;
Image-->Registry;
</div>
## Staging/Production
# Staging and production environments
### Virtual-host
TBD
- CAN USE a wildcard OR CAN USE a comma separated virtual-host list
- SHOULD use `www.` as default
See also [roj](https://github.com/dmstr/docker-roj) - Portable environments for Docker swarms and stacks
to setup Docker hosts.
### Export database
make bash
$ yii db/x-dump-data
### Import database
#### Manually
#### Via migrations
Staging
=======
:warning: This section is under development.
### Local staging
make STAGE all
See also `build/compose`.
### GitLab trigger
deploy:staging:
type: deploy
environment: staging-2
script:
- curl -X POST -F token=${TOKEN_STACKS_STAGING_2} -F "ref=master" -F "variables[TRIGGER_STACK_DIR]=projects/${CI_PROJECT_PATH}" ${ROJ_REPO_URL}
only:
- latest
---
Transfer data from staging to migrations
- Go to `/resque`
- `yii db/x-dump/data`
- Download (via Moxiemanager or Filyfly)
- Create file migration, place into tests/codeception/_migrations/VERSION
- cd tests
- make clean all
- make run-tests (or make bash $ codecept run)
Production
==========
:warning: This section is under development.
### Migrate production data sets
- Do not export the schema (experimental: use `yii db/x-dump-data`)
- Don't export the data of tables such as
- log
- migration
- language
- auth
- Use correct time in migration history
- minimize the number of `dev-master` packages
## ENV variables
### Mailer config
APP_MAILER_HOST=mailcatcher
APP_MAILER_USERNAME=smtp-user
APP_MAILER_PASSWORD=secret
```
APP_MAILER_HOST=mailcatcher
APP_MAILER_USERNAME=smtp-user
APP_MAILER_PASSWORD=secret
```
\ 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