nyeholt / docker-silverstripe-app-server

Base SilverStripe friendly app server docker definition
1 stars 1 forks source link

Apache based SilverStripe app container

Ubuntu based (for convenience...)

Contains the tools for development. NOTE - this will change in future to better support separation into production environments. This is a really temporary solution.

Usage

Build an image

docker build -t "symbiote/ss-dev" .

NOTE: Don't forget the "." at the end, this is to build in the current directory.

Configure your docker-compose YML

Uncomment the "volumes" config options best suited to your operating sytem. Replace the text "your_username_here" with your username.

For Linux users, if you want to use SSH from within the container, run ssh-agent on your host and bind the socket in.

Once the below file is configured, simply run:

docker-compose up

You will get something like:

Starting nyeholt_webserver_1 ...
Starting nyeholt_mysql_1 ...

You can use these names to use CLI in the container like so:

docker exec -it nyeholt_webserver_1 bash

or

docker exec -it nyeholt_mysql_1 bash
version: '2'
services:
  webserver:
    image: "symbiote/ss-dev"
    ports:
      - "80:80"
    environment:
      # *nix /.ssh/ folder location
      - SSH_AUTH_SOCK
    volumes:
      # Example *nix configuration
      #- /home/your_username_here/www:/var/www/dynamic
      #- $(dirname $SSH_AUTH_SOCK):$(dirname $SSH_AUTH_SOCK)

      # Example Windows configuration
      #- /c/Users/your_username_here/www:/var/www/dynamic
      #- /c/Users/your_username_here/AppData/Local/Composer:/root/.composer/cache
  mysql:
    # MySQL 5.6
    # https://github.com/docker-library/mysql/tree/master/5.6
    image: "mysql:5.6"
    #volumes:
      # Sync folder with .sql dumps
      #- /c/MySQLDatabases/unzipped:/docker-entrypoint-initdb.d
    environment:
        MYSQL_ROOT_PASSWORD: "password"

Debugging php cli in the container

NOTE: if you experience CLI or web requests hanging, it may be due to xdebug starting and locking out another process (session file lock maybe?). Haven't resolved this yet, in which case you'll need to manually run the export XDEBUG\_CONFIG etc on the cli each time you want to debug a CLI app

XHProf

The xhprof module is installed, but not directly enabled. To do so, grab https://github.com/gajus/xhprof.io and follow its instructions for installing and running.

Windows-specific Information

Example of directories mapping to host:

C:\Users\your_username_here\www\projects\facebook  -> facebook.projects.symlocal
C:\Users\your_username_here\www\tools\adminer      -> adminer.tools.symlocal

Example hosts file in C:\Windows\System32\drivers\etc\hosts

127.0.0.1     facebook.projects.symlocal
127.0.0.1     adminer.tools.symlocal

INSECURE: Share SSH keys from host to container: (ie. Support private Git repos)

First thing to note, this isn't at all very secure AND you should definitely not build any images from a container that contains your SSH keys. This is a stopgap solution until we find something better.

The SSH keys will get copied out of /root/.ssh/keys to /root/.ssh and the permissions will be fixed.

version: '2'
services:
  webserver:
    volumes:
      # -/c/Users/your_username_here/.ssh:/root/.ssh/keys

Warnings:

Configure MySQL

In your local.conf.php files, set it up like so below.

<?php

/*
 * Include any local instance specific configuration here - typically
 * this includes any database settings, email settings, etc that change
 * between installations. 
 */

global $databaseConfig;
$databaseConfig = array(
    "type" => "MySQLDatabase",
    "server" => "mysql", // The MySQL containers hostname
    "username" => "root",
    "password" => "password",
    "database" => "silverstripe",
);

Security::setDefaultAdmin('admin', 'admin');
// Email::setAdminEmail('admin@example.org');
define('SS_LOG_FILE', dirname(__FILE__).'/'.basename(dirname(dirname(__FILE__))).'.log');
Director::set_environment_type('dev');

Solr

To access the Solr collection interface, go to:

http://127.0.0.1:8983/solr

Import large MySQL databases

You may get an error like "MySQL server has gone away" or similar if you try to import a database with something like:

mysql -u root -p mydatabasenamehere < "/var/www/dynamic/databases/my_database_dump.sql"

The easiest way to work around this is to connect to the server and import via that interface.

Step 1: Connect

mysql -u root -p

Step 2: Set database

USE mydatabasenamehere;

Step 3: Import database

SOURCE /var/www/dynamic/databases/my_database_dump.sql;

Old Information (needs to be re-written)

Volume mappings

The one required mapping is your host file system's project directory to /var/www/dynamic in the container. In addition, the following are useful for improved performance

Then hit http://sub-folder.projectdir.symlocal/ from the host.

Configuration

The container is configured to execute a script that creates a user mapped to the user that started the container, and sets apache to run as that user. This means that all things created by the webserver are owned by user that started the container.