Skip to content

Commit

Permalink
publish 'magento2' harness
Browse files Browse the repository at this point in the history
  • Loading branch information
David Cole committed Apr 2, 2019
1 parent a799afa commit cb4b165
Show file tree
Hide file tree
Showing 60 changed files with 1,083 additions and 0 deletions.
62 changes: 62 additions & 0 deletions _twig/docker-compose.yml/application.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{% 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
volumes:
- {{ (dockersync) ? @('workspace.name') ~ '-sync:/app:nocopy' : '../:/app:delegated' }}
- ./application:/home/build/application
- ./docker/image/console/root/lib/task:/lib/task
{% else %}
image: {{ @('docker.repository') ~ ':' ~ @('app.version') ~ '-console' }}
{% endif %}
labels:
- traefik.enable=false
environment: &APP_ENV_VARS
{% include blocks ~ 'environment.yml.twig' %}
networks:
- private

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

php-fpm:
{% if @('app.build') == 'dynamic' %}
build: docker/image/php-fpm
entrypoint: /entrypoint.dynamic.sh
volumes:
- {{ (dockersync) ? @('workspace.name') ~ '-sync:/app:nocopy' : '../:/app:delegated' }}
{% else %}
image: {{ @('docker.repository') ~ ':' ~ @('app.version') ~ '-php-fpm' }}
{% endif %}
labels:
- traefik.enable=false
networks:
- private
environment:
<<: *APP_ENV_VARS
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
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
13 changes: 13 additions & 0 deletions _twig/docker-compose.yml/service/mysql.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mysql:
image: mysql:5.7
labels:
- traefik.enable=false
environment:
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASS}
- MYSQL_DATABASE=${DB_NAME}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASS}
networks:
- private
ports:
- 3306
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
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
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 %}
25 changes: 25 additions & 0 deletions application/overlay/Jenkinsfile.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pipeline {
agent { label "my127ws" }
environment {
MY127WS_KEY = credentials('{{ @('workspace.name') }}-my127ws-key')
MY127WS_ENV = "pipeline"
}
stages {
stage('Build') {
steps { sh 'ws install' }
}
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' } }
}
}
}
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 %}
}
}
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 %}
16 changes: 16 additions & 0 deletions docker-sync.yml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '2'
options:
compose-file-path:
- .my127ws/docker-compose.yml
syncs:
{{ @('workspace.name') }}-sync:
src: ../
sync_userid: '1000'
sync_excludes_type: BelowPath
sync_excludes: &IGNORE
- .docker-sync
- .idea
- .my127ws
- .git
- var
watch_excludes: *IGNORE
1 change: 1 addition & 0 deletions docker/image/console/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.twig
31 changes: 31 additions & 0 deletions docker/image/console/Dockerfile.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM {{ @('docker.image.console') }}

COPY .my127ws/docker/image/console/root /
RUN chown -R build:build /home/build

ENV APP_MODE={{ @('app.mode') }} \
ASSETS_DIR={{ @('assets.local') }}

{% if @('node.version') is not null %}
USER build
RUN . /home/build/.nvm/nvm.sh \
&& nvm install {{ @('node.version') }} \
&& nvm use {{ @('node.version') }} \
&& nvm alias default {{ @('node.version') }} \
&& npm install -g yarn
USER root
{% endif %}

{% if @('app.build') == 'static' %}
RUN chown build:build /app
COPY --chown=build:build .my127ws/application /home/build/application
COPY --chown=build:build ./ /app
USER build
RUN app build
USER root
{% else %}
VOLUME /app
VOLUME /home/build/application
{% endif %}

ENTRYPOINT /entrypoint.sh
Empty file.
18 changes: 18 additions & 0 deletions docker/image/console/root/bin/app
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

main()
{
task "$@"
}

bootstrap()
{
export NVM_DIR="$HOME/.nvm"
# shellcheck source=/home/build/nvm.sh
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
. /lib/sidekick.sh
}

bootstrap
main "$@"
54 changes: 54 additions & 0 deletions docker/image/console/root/entrypoint.dynamic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

main()
{
source /entrypoint.sh
}

setup_app_volume_permissions()
{
case "$STRATEGY" in
"host-linux-normal")
usermod -u "$(stat -c '%u' /app)" build
groupmod -g "$(stat -c '%g' /app)" build
;;
"host-osx-normal")
usermod -u 1000 build
groupmod -g 1000 build
;;
"host-osx-dockersync")
usermod -u 1000 build
groupmod -g 1000 build
;;
*)
exit 1
esac

chown build:build /app
}

resolve_volume_mount_strategy()
{
if [ "${HOST_OS_FAMILY}" = "linux" ]; then
STRATEGY="host-linux-normal"
elif [ "${HOST_OS_FAMILY}" = "darwin" ]; then
if (mount | grep "/app type fuse.osxfs") &2>1 > /dev/null; then
STRATEGY="host-osx-normal"
elif (mount | grep "/app type ext4") &2>1 > /dev/null; then
STRATEGY="host-osx-dockersync"
else
exit 1
fi
else
exit 1
fi
}

bootstrap()
{
resolve_volume_mount_strategy
setup_app_volume_permissions
}

bootstrap
main
27 changes: 27 additions & 0 deletions docker/image/console/root/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

main()
{
su - build
sh -c 'while sleep 3600; do :; done'
}

setup_app_networking()
{
# make linux consistent with docker-for-mac
if [ "${HOST_OS_FAMILY}" = "linux" ]; then
DOCKER_INTERNAL_HOST="host.docker.internal"
if ! grep $DOCKER_INTERNAL_HOST /etc/hosts > /dev/null ; then
DOCKER_INTERNAL_IP=$(/sbin/ip route|awk '/default/ { print $3 }')
echo -e "$DOCKER_INTERNAL_IP $DOCKER_INTERNAL_HOST" | tee -a /etc/hosts > /dev/null
fi
fi
}

bootstrap()
{
setup_app_networking
}

bootstrap
main
3 changes: 3 additions & 0 deletions docker/image/console/root/home/build/.my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[client]
host=mysql
user=root
Loading

0 comments on commit cb4b165

Please sign in to comment.