From c9b51bface6a093f901a84572733ef106e644d86 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Mon, 16 Feb 2015 20:34:40 -0800 Subject: [PATCH] Docker kinda-sorta working, and documentation --- .dockerignore | 6 ++ Dockerfile | 98 +++++++++++++++++++++++++++++++ docker/000-default.conf | 41 +++++++++++++ docker/README.md | 49 ++++++++++++++++ docker/app_install.exp | 73 +++++++++++++++++++++++ docker/app_start.patch | 20 +++++++ docker/database.php | 125 ++++++++++++++++++++++++++++++++++++++++ docker/develop.sh | 3 + 8 files changed, 415 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker/000-default.conf create mode 100644 docker/README.md create mode 100644 docker/app_install.exp create mode 100644 docker/app_start.patch create mode 100755 docker/database.php create mode 100644 docker/develop.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..d6c5a4cf01 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +Dockerfile +.dockerignore +app/storage/logs/* +app/storage/views/* +vendor/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..3cf09e1ce7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,98 @@ +FROM ubuntu +MAINTAINER Brady Wetherington + +# Merging all apt-stuff together +####RUN apt-get install -y apache2-bin libapache2-mod-php5 php5-mysql + +RUN apt-get update && apt-get install -y \ +apache2-bin \ +libapache2-mod-php5 \ +php5-mysql \ +patch \ +curl \ +git \ +php5-mcrypt \ +expect + +RUN php5enmod mcrypt + +#RUN echo "include_path=/var/www/html/include" >> /etc/php5/apache2/php.ini + +RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php5/apache2/php.ini +RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php5/cli/php.ini + +RUN useradd --uid 1000 --gid 50 docker + +RUN echo export APACHE_RUN_USER=docker >> /etc/apache2/envvars +RUN echo export APACHE_RUN_GROUP=staff >> /etc/apache2/envvars + +#COPY httpd.conf /etc/apache2/apache2.conf + +COPY docker/000-default.conf /etc/apache2/sites-enabled/000-default.conf + +COPY . /var/www/html + +#apachectl start + +RUN a2enmod rewrite + +#RUN apt-get install -y patch + +############ INITIAL APPLICATION SETUP ##################### + +COPY docker/app_start.patch /tmp/app_start.patch + +WORKDIR /var/www/html + +#Patch bootstrap file +RUN patch -p1 < /tmp/app_start.patch + +#DB create? +# mysqladmin -u root create snipeit_laravel + +#DB create user, grant access to new DB? +# grant all privileges on snipeit_laravel.* TO snipeit; + +#DB config file init? (NEVER overwrite!) +#RUN cp -n /var/www/html/app/config/production/database.example.php /var/www/html/app/config/production/database.php +COPY docker/database.php /var/www/html/app/config/production/database.php + +#change DB file user +#RUN sed -i s/travis/snipe_it/ /var/www/html/app/config/production/database.php + +#init app config file (DO NOT overwrite!) +RUN cp -n /var/www/html/app/config/production/app.example.php /var/www/html/app/config/production/app.php + +# Change default hostname to blank...I guess? +RUN sed -i s%http://staging.yourserver.com%% /var/www/html/app/config/production/app.php + +RUN chown -R docker /var/www/html + +############## DEPENDENCIES via COMPOSER ################### + +# get curl (this feels yucky, doesn' it?) +#RUN apt-get install -y curl + +#global install of composer +RUN cd /tmp;curl -sS https://getcomposer.org/installer | php;mv /tmp/composer.phar /usr/local/bin/composer + +# Composer won't install without git (doctrine/inflector specifically?) +#RUN apt-get install -y git + +# Get dependencies +RUN cd /var/www/html;composer install + +############### APPLICATION INSTALL/INIT ################# + +#RUN php artisan app:install +# too interactive! Try something else + +#COPY docker/app_install.exp /tmp/app_install.exp +#RUN chmod +x /tmp/app_install.exp +#RUN /tmp/app_install.exp + +##### START SERVER + +CMD . /etc/apache2/envvars ;apache2 -DFOREGROUND + +EXPOSE 80 \ No newline at end of file diff --git a/docker/000-default.conf b/docker/000-default.conf new file mode 100644 index 0000000000..290df69d26 --- /dev/null +++ b/docker/000-default.conf @@ -0,0 +1,41 @@ + + # The ServerName directive sets the request scheme, hostname and port that + # the server uses to identify itself. This is used when creating + # redirection URLs. In the context of virtual hosts, the ServerName + # specifies what hostname must appear in the request's Host: header to + # match this virtual host. For the default virtual host (this file) this + # value is not decisive as it is used as a last resort host regardless. + # However, you must set it for any further virtual host explicitly. + #ServerName www.example.com + + ServerAdmin webmaster@localhost + + DocumentRoot "/var/www/html/public" + DirectoryIndex index.php index.html + # php_value include_path "/var/www/html/include" + + Options All +MultiViews -ExecCGI -Indexes + + DAV Off + + AllowOverride All + + LogLevel warn + # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, + # error, crit, alert, emerg. + # It is also possible to configure the loglevel for particular + # modules, e.g. + #LogLevel info ssl:warn + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + # For most configuration files from conf-available/, which are + # enabled or disabled at a global level, it is possible to + # include a line for only one particular virtual host. For example the + # following line enables the CGI configuration for this host only + # after it has been globally disabled with "a2disconf". + #Include conf-available/serve-cgi-bin.conf + + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000000..8e6bc4b5ea --- /dev/null +++ b/docker/README.md @@ -0,0 +1,49 @@ +#### How to use the Snipe-IT docker image ##### + +### How to get up and running ### + +* First get a MySQL container running + +Figure out what you want for your: + +* MySQL root password +* MySQL Database name for Snipe-IT +* MySQL User name for the user who will access Snipe-IT +* MySQL Password for that user + +```sh +docker run --name mysql -e MYSQL_ROOT_PASSWORD=SUPERDUPERSECRETPASSWORD -e MYSQL_DATABASE=snipeit -e MYSQL_USER=snipeit -e MYSQL_PASSWORD=tinglewingler -d -p $(boot2docker ip):33060:3306 mysql +``` + +That should set you up with your database to use. + +Now you can start your Snipe-IT container - +```sh +docker run -d -p $(boot2docker ip):8000:80 --name="snipeit" --link mysql:mysql snipeit +``` + +And finally, you can initialize the application and database like this: + +```sh +docker exec -i -t snipeit php artisan app:install +``` + +(Go ahead and answer the questions however you like. Type 'yes' when asked whether or not you want to run migrations.) + +# If you want to seed # + +You can load out some initial data into the DB if you like by doing this: + +```sh +docker -p $(boot2docker ip):8000:80 --link mysql:mysql php artisan db:seed +``` + +### For Development ### + +When you call ```docker run``` - make sure to mount your own snipe-it directory *over* the /var/www/html directory. Something like: + +```sh +docker run -v /Path/To/My/snipe-it/checkout:/var/www/html +``` + +Then your local changes to the code will be reflected. \ No newline at end of file diff --git a/docker/app_install.exp b/docker/app_install.exp new file mode 100644 index 0000000000..37b1dc88b2 --- /dev/null +++ b/docker/app_install.exp @@ -0,0 +1,73 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Mon Feb 16 23:58:34 2015 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + + +set timeout -1 +spawn php artisan app:install --no-ansi +match_max 100000 +expect -exact "=====================================\r +\r + Step: 1\r +\r + Please follow the following\r + instructions to create your\r + default user.\r +\r +-------------------------------------\r +\r +Please enter your first name: " +send -- "Sample\r" +expect -exact "Sample\r +Please enter your last name: " +send -- "User\r" +expect -exact "User\r +Please enter your user email: " +send -- "snipeit@example.com" +expect -exact "snipeit@example.com" +send -- "\r" +expect -exact "\r +Please enter your user password (at least 8 characters): " +send -- "example1" +expect -exact "example1" +send -- "\r" +expect eof diff --git a/docker/app_start.patch b/docker/app_start.patch new file mode 100644 index 0000000000..6bec1b337a --- /dev/null +++ b/docker/app_start.patch @@ -0,0 +1,20 @@ +diff --git a/bootstrap/start.php b/bootstrap/start.php +index 300ba10..92b6bcd 100755 +--- a/bootstrap/start.php ++++ b/bootstrap/start.php +@@ -24,12 +24,9 @@ $app = new Illuminate\Foundation\Application; + | + */ + +-$env = $app->detectEnvironment(array( +- +- 'local' => array('YourLocalDevHostname','AlisonMBP'), +- 'staging' => array('staging.yourserver.com'), +- 'production' => array('www.yourserver.com') +-)); ++$env = $app->detectEnvironment(function () { ++ return "production"; //always be 'production' as environment ++}); + + /* + |-------------------------------------------------------------------------- diff --git a/docker/database.php b/docker/database.php new file mode 100755 index 0000000000..f2b0f92a30 --- /dev/null +++ b/docker/database.php @@ -0,0 +1,125 @@ + PDO::FETCH_CLASS, + + /* + |-------------------------------------------------------------------------- + | Default Database Connection Name + |-------------------------------------------------------------------------- + | + | Here you may specify which of the database connections below you wish + | to use as your default connection for all database work. Of course + | you may use many connections at once using the Database library. + | + */ + + 'default' => 'mysql', + + /* + |-------------------------------------------------------------------------- + | Database Connections + |-------------------------------------------------------------------------- + | + | Here are each of the database connections setup for your application. + | Of course, examples of configuring each database platform that is + | supported by Laravel is shown below to make development simple. + | + | + | All database work in Laravel is done through the PHP PDO facilities + | so make sure you have the driver for your particular database of + | choice installed on your machine before you begin development. + | + */ + + 'connections' => array( + + 'sqlite' => array( + 'driver' => 'sqlite', + 'database' => __DIR__.'/../database/production.sqlite', + 'prefix' => '', + ), + + 'mysql' => array( + 'driver' => 'mysql', + 'host' => $_ENV['MYSQL_PORT_3306_TCP_ADDR'], + 'port' => $_ENV['MYSQL_PORT_3306_TCP_PORT'], + 'database' => $_ENV['MYSQL_ENV_MYSQL_DATABASE'], + 'username' => $_ENV['MYSQL_ENV_MYSQL_USER'], + 'password' => $_ENV['MYSQL_ENV_MYSQL_PASSWORD'], + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', + ), + + 'pgsql' => array( + 'driver' => 'pgsql', + 'host' => 'localhost', + 'database' => 'database', + 'username' => 'root', + 'password' => '', + 'charset' => 'utf8', + 'prefix' => '', + 'schema' => 'public', + ), + + 'sqlsrv' => array( + 'driver' => 'sqlsrv', + 'host' => 'localhost', + 'database' => 'database', + 'username' => 'root', + 'password' => '', + 'prefix' => '', + ), + + ), + + /* + |-------------------------------------------------------------------------- + | Migration Repository Table + |-------------------------------------------------------------------------- + | + | This table keeps track of all the migrations that have already run for + | your application. Using this information, we can determine which of + | the migrations on disk have not actually be run in the databases. + | + */ + + 'migrations' => 'migrations', + + /* + |-------------------------------------------------------------------------- + | Redis Databases + |-------------------------------------------------------------------------- + | + | Redis is an open source, fast, and advanced key-value store that also + | provides a richer set of commands than a typical key-value systems + | such as APC or Memcached. Laravel makes it easy to dig right in. + | + */ + + 'redis' => array( + + 'cluster' => true, + + 'default' => array( + 'host' => '127.0.0.1', + 'port' => 6379, + 'database' => 0, + ), + + ), + +); diff --git a/docker/develop.sh b/docker/develop.sh new file mode 100644 index 0000000000..b94d14e0d1 --- /dev/null +++ b/docker/develop.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker run -v \ No newline at end of file