Skip to content

Commit

Permalink
publish 'wordpress' harness
Browse files Browse the repository at this point in the history
  • Loading branch information
g-foster2020 committed Feb 10, 2020
1 parent 04c4c00 commit f7a4adf
Show file tree
Hide file tree
Showing 107 changed files with 2,938 additions and 0 deletions.
73 changes: 73 additions & 0 deletions _twig/docker-compose.yml/application.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{% set blocks = '_twig/docker-compose.yml/' %}
{% set dockersync = false %}
{% if @('host.os') == 'darwin' and @('docker-sync') == 'yes' %}
{% set dockersync = true %}
{% endif %}

console:
{% if @('app.build') == 'dynamic' %}
build:
context: ./
dockerfile: .my127ws/docker/image/console/Dockerfile
entrypoint: [/entrypoint.dynamic.sh]
command: [sleep, infinity]
volumes:
- {{ (dockersync) ? @('workspace.name') ~ '-sync:/app:nocopy' : './:/app:delegated' }}
- ./.my127ws/application:/home/build/application
- ./.my127ws/docker/image/console/root/lib/task:/lib/task
- ./.my127ws:/.my127ws
{% else %}
image: {{ @('docker.repository') ~ ':' ~ @('app.version') ~ '-console' }}
{% endif %}
labels:
- traefik.enable=false
environment:
{{ deep_merge_to_yaml([@('services.php-base.environment'), @('services.console.environment')], 2, 6) | raw }}
{% include blocks ~ 'environment.yml.twig' %}
networks:
- private

nginx:
{% if @('app.build') == 'dynamic' %}
build: .my127ws/docker/image/nginx
volumes:
- {{ (dockersync) ? @('workspace.name') ~ '-sync:/app:nocopy' : './:/app:delegated' }}
{% else %}
image: {{ @('docker.repository') ~ ':' ~ @('app.version') ~ '-nginx' }}
{% endif %}
labels:
- traefik.backend={{ @('workspace.name') }}
- traefik.frontend.rule=Host:{{ @('hostname') }}
- traefik.docker.network=my127ws
- traefik.port=80
{% if @('services.nginx.environment') %}
environment:
{{ to_nice_yaml(@('services.nginx.environment'), 2, 6) | raw }}
{% endif %}
links:
- php-fpm:php-fpm
networks:
private:
aliases:
- {{ @('hostname') }}
shared: {}

php-fpm:
{% if @('app.build') == 'dynamic' %}
build: .my127ws/docker/image/php-fpm
{% if ("cron" in @('app.services')) %}
image: {{ @('workspace.name') ~ '-php-fpm:dev' }}
{% endif %}
volumes:
- {{ (dockersync) ? @('workspace.name') ~ '-sync:/app:nocopy' : './:/app:delegated' }}
- ./.my127ws:/.my127ws
{% else %}
image: {{ @('docker.repository') ~ ':' ~ @('app.version') ~ '-php-fpm' }}
{% endif %}
labels:
- traefik.enable=false
networks:
- private
environment:
{{ deep_merge_to_yaml([@('services.php-base.environment'), @('services.php-fpm.environment')], 2, 6) | raw }}
{% include blocks ~ 'environment.yml.twig' %}
Empty file.
7 changes: 7 additions & 0 deletions _twig/docker-compose.yml/service/chrome.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chrome:
image: yukinying/chrome-headless-browser:latest
command: ["--no-sandbox", "--disable-gpu", "--headless", "--disable-dev-shm-usage", "--remote-debugging-address=0.0.0.0", "--remote-debugging-port=9222", "--user-data-dir=/data"]
labels:
- traefik.enable=false
networks:
- private
18 changes: 18 additions & 0 deletions _twig/docker-compose.yml/service/cron.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cron:
{% if @('app.build') == 'dynamic' %}
build:
context: ./
dockerfile: .my127ws/docker/image/cron/Dockerfile
volumes:
- {{ (dockersync) ? @('workspace.name') ~ '-sync:/app:nocopy' : './:/app:delegated' }}
- ./.my127ws/application:/home/build/application
{% else %}
image: {{ @('docker.repository') ~ ':' ~ @('app.version') ~ '-cron' }}
{% endif %}
environment:
{{ deep_merge_to_yaml([@('services.php-base.environment'),@('services.cron.environment')], 2, 6) | raw }}
{% include blocks ~ 'environment.yml.twig' %}
networks:
- private
labels:
- traefik.enable=false
12 changes: 12 additions & 0 deletions _twig/docker-compose.yml/service/elasticsearch.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
elasticsearch:
image: {{ @('elasticsearch.image') }}:{{ @('elasticsearch.tag') }}
labels:
- traefik.enable=false
environment:
ES_JAVA_OPTS: -Xms512m -Xmx512m
discovery.type: single-node
networks:
- private
ports:
- 9200
- 9300
6 changes: 6 additions & 0 deletions _twig/docker-compose.yml/service/memcached.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
memcached:
image: memcached:1-alpine
labels:
- traefik.enable=false
networks:
- private
17 changes: 17 additions & 0 deletions _twig/docker-compose.yml/service/mysql.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% set command = [] %}
{% for var,value in @('database.var') -%}
{% set command = command|merge(['--' ~ var ~ '=' ~ value]) %}
{% endfor %}
mysql:
image: mysql:5.7
labels:
- traefik.enable=false
{% if command|length %}
command: {{ command|join(' ') }}
{% endif %}
environment:
{{ to_nice_yaml(@('services.mysql.environment'), 2, 6) | raw }}
networks:
- private
ports:
- 3306
10 changes: 10 additions & 0 deletions _twig/docker-compose.yml/service/postgres.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
postgres:
image: postgres:9.6
labels:
- traefik.enable=false
environment:
{{ to_nice_yaml(@('services.postgres.environment'), 2, 6) | raw }}
networks:
- private
ports:
- 5432
8 changes: 8 additions & 0 deletions _twig/docker-compose.yml/service/redis-session.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
redis-session:
image: redis:4-alpine
# 1GB; evict key that would expire soonest
command: redis-server --maxmemory 1073742000 --maxmemory-policy volatile-ttl --save 3600 1 --save 300 100 --save 60 10000
labels:
- traefik.enable=false
networks:
- private
8 changes: 8 additions & 0 deletions _twig/docker-compose.yml/service/redis.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
redis:
image: redis:4-alpine
# 1GB; evict any least recently used key even if they don't have a TTL
command: redis-server --maxmemory 1073742000 --maxmemory-policy allkeys-lru --save 3600 1 --save 300 100 --save 60 10000
labels:
- traefik.enable=false
networks:
- private
8 changes: 8 additions & 0 deletions application/overlay/.dockerignore.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% set build = @('app.build') %}
{% set blocks = 'application/overlay/_twig/.dockerignore/' %}

{% if build == 'dynamic' %}
{% include blocks ~ 'dynamic.twig' %}
{% else %}
{% include blocks ~ 'static.twig' %}
{% endif %}
58 changes: 58 additions & 0 deletions application/overlay/Jenkinsfile.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
pipeline {
agent { label "my127ws" }
environment {
MY127WS_KEY = credentials('{{ @('jenkins.credentials.my127ws_key') }}')
MY127WS_ENV = "pipeline"
}
triggers { cron(env.BRANCH_NAME == '{{ @('git.main_branch') }}' ? 'H H(0-6) * * *' : '') }
stages {
stage('Build') {
steps {
sh 'ws install'
milestone(10)
}
}
stage('Test') {
parallel {
stage('quality') { steps { sh 'ws exec composer test-quality' } }
stage('unit') { steps { sh 'ws exec composer test-unit' } }
stage('acceptance') { steps { sh 'ws exec composer test-acceptance' } }
}
}
{% if @('pipeline.publish.enabled') == 'yes' %}
stage('Publish') {
when { not { triggeredBy 'TimerTrigger' } }
steps {
milestone(50)
sh 'ws app publish'
}
}
{% endif %}
{% if @('pipeline.qa.enabled') == 'yes' %}
stage('Deploy (QA)') {
environment {
{% for key, value in @('pipeline.qa.environment') %}
{{ key }} = {{ value|raw }}
{% endfor %}
}
when {
not { triggeredBy 'TimerTrigger' }
branch '{{ @('pipeline.qa.branch') }}'
}
steps {
milestone(100)
lock(resource: '{{ @('workspace.name') }}-qa-deploy', inversePrecedence: true) {
milestone(101)
sh 'ws app deploy qa'
}
}
}
{% endif %}
}
post {
always {
sh 'ws destroy'
cleanWs()
}
}
}
2 changes: 2 additions & 0 deletions application/overlay/_twig/.dockerignore/dynamic.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.my127ws
1 change: 1 addition & 0 deletions application/overlay/_twig/.dockerignore/static.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# no need for exclusions for now
15 changes: 15 additions & 0 deletions application/overlay/auth.json.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"http-basic": {
{% for repo in @('composer.auth.basic') %}
"{{ repo.path }}": {
"username": "{{ repo.username }}",
"password": "{{ repo.password }}"
}{% if not loop.last %},{% endif %}
{% endfor %}
},
"github-oauth": {
{% if @('composer.auth.github') %}
"github.com": "{{ @('composer.auth.github') }}"
{% endif %}
}
}
119 changes: 119 additions & 0 deletions application/skeleton/README.md.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# {{ @('workspace.name') }}

Please follow the below steps to get started, if you encounter any issues installing the dependencies or provisioning the development environment, please check the [Common Issues](#common-issues) section first.

## Development Environment

### Getting Started

#### Prerequisites

##### General

- Access to LastPass folders
- `Shared-{{ @('workspace.name') }}-Servers` and `Shared-{{ @('workspace.name') }}-Accounts`

##### Docker

- A working Docker setup
- On MacOS, use [Docker for Mac](https://docs.docker.com/docker-for-mac/install/).
- On Linux, add the official Docker repository and install the "docker-ce" package.
You will also need to have a recent [docker-compose](https://docs.docker.com/compose/install/) version - at least `1.24.0`.

#### Setup

1. Install [workspace](https://github.com/my127/workspace)
2. Copy the LastPass entry "{{ @('workspace.name') }}: Development Environment Key" to a new blank file named `workspace.override.yml` in the project root.
3. Run `ws install`

Once installed, the site should be available at [https://{{ @('hostname') }}](https://{{ @('hostname') }}).

### Development environment cleanup

To stop the development environment, run `ws disable`.

To start the development environment again, run `ws enable`.

To remove the development environment, run `ws destroy`.

### Frontend

The frontend build should be automatically done as part of bringing up the environment.

To trigger a rebuild, run `ws frontend build`.

To watch for changes, run `ws frontend watch`.

To gain access to the `console` container where the builds happen: `ws frontend console`.

### Xdebug

Xdebug is turned off by default as it drastically slows down requests for all developers.

To enable, run `ws feature xdebug on`. To turn off again, `ws feature xdebug off`.

To enable on CLI in `ws console`, run `ws feature xdebug cli on`. To turn off again, `ws feature xdebug cli off`.

Xdebug is set up to listen to your computer's 9000 port once enabled, so all you would need to do in your IDE is:
1. Create a mapping from the project root to `/app` for name `workspace`, hostname `localhost` and port 80.
2. Listen for connections.

[Here's a good guide for PhpStorm](https://www.jetbrains.com/help/phpstorm/zero-configuration-debugging.html).

If you have trouble with triggered requests not starting connections to your IDE, check that
`sudo lsof -i :9000 | grep LISTEN` on your host shows process from your IDE.
If it doesn't, stop the indicated process (e.g. `php-fpm`) and toggle the Xdebug listen button off and on again in PhpStorm.

### Performance on MacOS

Page load times with Docker for Mac can vary considerably. This is especially so when there is a large
quantity of small files, such as with a large composer vendor folder.

{% if @('docker-sync') == 'yes' %}
[docker-sync](https://github.com/EugenMayer/docker-sync/) is enabled on this workspace environment to
try to overcome this.
It enables production-like performance at the cost of having to synchronise files with an intermediate
"data" container.
{% else %}
If it takes over 2 seconds to load a page, you can consider enabling
[docker-sync](https://github.com/EugenMayer/docker-sync/) which should enable production-like performance
at the cost of having to synchronise files with an intermediate "data" container.

You can enable docker-sync with `ws feature docker-sync on` - it takes a while to initially sync.
{% endif %}

If you don't like the tradeoff of having to synchronise files, you can turn docker-sync off
with `ws feature docker-sync off`.

{% if @('docker-sync') == 'yes' %}
If your page loads too slowly, you can turn docker-sync back on again with `ws feature docker-sync on`
{% endif %}

### Common Issues

As setup issues are encountered please detail with step by step fix instructions, and where possible update the project or the upstream workspace harness itself to provide a more permanent fix.

* If you use docker-sync and notice that your changes aren't synchronising to the environment:
* Check if your file exists with your changes in `ws console`
* If your file in `ws console` has changed okay, check your project for any caching that
would prevent changes to source code appearing immediately.
* If the file changes do not appear in `ws console` reasonably quickly, it might be that
Docker for Mac is overwhelmed with file change events.
* Restarting Docker for Mac using the system tray icon's menu and then running `ws enable` again
will fix it.

# License

Copyright 2019, Inviqa

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
22 changes: 22 additions & 0 deletions docker-compose.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% set blocks = '_twig/docker-compose.yml/' %}
{% set dockersync = false %}
{% if @('host.os') == 'darwin' and @('docker-sync') == 'yes' %}
{% set dockersync = true %}
{% endif %}
version: '3'
services:
{% include blocks ~ 'application.yml.twig' %}
{% for service in @('app.services') %}
{% include blocks ~ 'service/' ~ service ~ '.yml.twig' %}
{% endfor %}
networks:
private:
external: false
shared:
external:
name: my127ws
{% if dockersync %}
volumes:
{{ @('workspace.name') }}-sync:
external: true
{% endif %}
Loading

0 comments on commit f7a4adf

Please sign in to comment.