diff --git a/README.md b/README.md new file mode 100644 index 0000000..bdb685b --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +Intro +===== + +This is a very basic example of how one can build the foreman from sources and make a container out of it. +The mariadb container is not even used in this example, but you can use it on your own. + + +Running the Foreman +=================== + +``` +cd foreman/ +docker-compose run -d +``` + +Foreman credentials +=================== + +You can get the foreman "Login credentials" when the container foreman-data is running seeds on built. +It will look like this +``` +Login credentials: admin / PassWoRd +``` + +Connecting to the Foreman Web +============================= + +Get the IP of the nginx-passenger container +``` +docker exec -ti foreman_nginx-passenger_1 ip a +``` + +Add the following line to your `/etc/hosts` file +``` +172.21.0.3 foreman-web +``` + +In my case the nginx-passenger's IP was 172.21.0.3 + +After that run your favorite browser and access the `http://foreman-web` :-) + + + +Working inside the container +============================ + +``` +docker exec -ti foreman_foreman-data_1 /bin/sh +$ cd /src/foreman +/src/foreman $ bundle exec rake -T +``` + +After you have changed something, don't forget to kill -HUP in the foreman_nginx-passenger_1 container. + + +Logs +==== + +Logs stored at the `/src/foreman/log/production.log` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..700a291 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '2' + +services: + foreman-data: + build: foreman + networks: + - net + tty: true + # stdin_open: true + + nginx-passenger: + hostname: foreman-web + build: passenger + networks: + - net + volumes_from: + - foreman-data + + mysql: + build: mariadb + networks: + - net + +networks: + net: + driver: bridge + diff --git a/foreman/Dockerfile b/foreman/Dockerfile new file mode 100644 index 0000000..8baa84c --- /dev/null +++ b/foreman/Dockerfile @@ -0,0 +1,44 @@ +# Run Foreman v1.6 stable in a container + +# Foreman v1.6 http://www.theforeman.org/manuals/1.6/#3.4InstallFromSource + +FROM alpine:3.3 +MAINTAINER Andrey Arapov + +ENV USER foreman +ENV UID 30000 +ENV HOME /home/$USER +ENV WORKDIR /src +# ENV RAILS_ENV development +ENV RAILS_ENV production + +COPY foreman-patch.diff /tmp/foreman-patch.diff + +RUN apk update \ + && apk add git gcc g++ make \ + ruby-dev ruby-bundler ruby-io-console libxml2-dev libxslt-dev \ + libffi-dev mariadb-dev postgresql-dev libvirt-dev sqlite-dev \ + ruby-bigdecimal ruby-irb nodejs \ + && adduser -D -h $HOME -u $UID $USER \ + && mkdir $WORKDIR \ + && chown $USER:$USER $WORKDIR + +RUN su $USER -c "cd $WORKDIR \ + && git clone https://github.com/theforeman/foreman.git foreman -b 1.6-stable \ + && cd foreman/ \ + && cp -p config/settings.yaml.example config/settings.yaml \ + && cp -p config/database.yml.example config/database.yml \ + && bundle config build.nokogiri --use-system-libraries \ + && patch -p1 < /tmp/foreman-patch.diff \ + && bundle install --standalone --path vendor/bundle \ + && bundle install --deployment --path vendor/bundle \ + && bundle exec rake db:migrate \ + && bundle exec rake db:seed assets:precompile locale:pack" + +# && bundle config --global DISABLE_SHARED_GEMS "1" \ + +VOLUME [ "/src/foreman" ] + +WORKDIR $HOME +USER $USER +CMD [ "/bin/sh" ] diff --git a/foreman/foreman-patch.diff b/foreman/foreman-patch.diff new file mode 100644 index 0000000..6a452f2 --- /dev/null +++ b/foreman/foreman-patch.diff @@ -0,0 +1,69 @@ +diff --git a/Gemfile b/Gemfile +index b86d9ec..0e3e75e 100644 +--- a/Gemfile ++++ b/Gemfile +@@ -5,7 +5,7 @@ require File.expand_path('../lib/regexp_extensions', FOREMAN_GEMFILE) + + source 'https://rubygems.org' + +-gem 'rails', '3.2.18' ++gem 'rails', '3.2.22.2' + gem 'json' + gem 'rest-client', '> 1.6.2', '< 1.7', :require => 'rest_client' + gem "audited-activerecord", "3.0.0" +@@ -34,8 +34,9 @@ if RUBY_VERSION =~ /^1\.8/ + gem 'rake', '< 10.2.0' + else + # Newer version of safemode contains fixes for Ruby 1.9 +- gem 'safemode', '~> 1.2.1' +- gem 'ruby_parser', '~> 3.0.0' ++ gem 'test-unit', '~> 3.1.7' ++ gem 'safemode', '~> 1.2.2' ++ gem 'ruby_parser', '~> 3.2.0' + end + + Dir["#{File.dirname(FOREMAN_GEMFILE)}/bundler.d/*.rb"].each do |bundle| +diff --git a/bundler.d/assets.rb b/bundler.d/assets.rb +index 2319190..b525fbd 100644 +--- a/bundler.d/assets.rb ++++ b/bundler.d/assets.rb +@@ -4,7 +4,7 @@ group :assets do + gem 'execjs', '< 2.1.0' + gem "jquery-rails", "2.0.3" + gem 'jquery-ui-rails', '< 5.0.0' +- gem "therubyracer", '0.11.3', :require => 'v8' ++ gem "therubyracer", '0.11.3' + gem 'bootstrap-sass', '~> 3.0.3.0' + gem "spice-html5-rails" + gem "flot-rails", '0.0.3' +diff --git a/bundler.d/i18n.rb b/bundler.d/i18n.rb +index a5847d4..29d6a8c 100644 +--- a/bundler.d/i18n.rb ++++ b/bundler.d/i18n.rb +@@ -3,4 +3,5 @@ group :i18n do + gem 'gettext_i18n_rails', '~> 0.10' + gem 'gettext_i18n_rails_js', '>= 0.0.8' + gem 'i18n_data', '>= 0.2.6', :require => 'i18n_data' ++ gem 'i18n', '~> 0.6.11' + end +diff --git a/bundler.d/mysql2.rb b/bundler.d/mysql2.rb +index 44fe73f..3069dab 100644 +--- a/bundler.d/mysql2.rb ++++ b/bundler.d/mysql2.rb +@@ -1,3 +1,3 @@ + group :mysql2 do +- gem 'mysql2', '> 0.3.0' ++ gem 'mysql2', '~> 0.3.20' + end +diff --git a/bundler.d/fog.rb b/bundler.d/fog.rb +index 596555e..7edcd8c 100644 +--- a/bundler.d/fog.rb ++++ b/bundler.d/fog.rb +@@ -1,5 +1,5 @@ + group :fog do +- gem 'fog', '~> 1.23.0' +- gem 'fog-core', '~> 1.23.0' ++ gem 'fog', '~> 1.25.0' ++ gem 'fog-core', '~> 1.25.0' + gem 'unf' + end diff --git a/mariadb/Dockerfile b/mariadb/Dockerfile new file mode 100644 index 0000000..081420e --- /dev/null +++ b/mariadb/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:3.3 +MAINTAINER Andrey Arapov + +RUN apk update \ + && apk add mariadb \ + && mysql_install_db --user=mysql --rpm + +COPY my.cnf /etc/mysql/my.cnf + +CMD /bin/sh -c "/usr/bin/mysqld_safe --pid-file=/run/mysqld/mysqld.pid" diff --git a/mariadb/my.cnf b/mariadb/my.cnf new file mode 100644 index 0000000..7a2a79b --- /dev/null +++ b/mariadb/my.cnf @@ -0,0 +1,36 @@ +[client] +port = 3306 +socket = /run/mysqld/mysqld.sock + +[mysqld] +port = 3306 +bind-address = 0.0.0.0 +socket = /run/mysqld/mysqld.sock +skip-external-locking +key_buffer_size = 16M +max_allowed_packet = 1M +table_open_cache = 64 +sort_buffer_size = 512K +net_buffer_length = 8K +read_buffer_size = 256K +read_rnd_buffer_size = 512K +myisam_sort_buffer_size = 8M +log-bin=mysql-bin +binlog_format=mixed +server-id = 1 + +[mysqldump] +quick +max_allowed_packet = 16M + +[mysql] +no-auto-rehash + +[myisamchk] +key_buffer_size = 20M +sort_buffer_size = 20M +read_buffer = 2M +write_buffer = 2M + +[mysqlhotcopy] +interactive-timeout diff --git a/passenger/Dockerfile b/passenger/Dockerfile new file mode 100644 index 0000000..2fced49 --- /dev/null +++ b/passenger/Dockerfile @@ -0,0 +1,32 @@ +# Run passenger in a container + +FROM alpine:3.3 +MAINTAINER Andrey Arapov + +ENV WORKDIR /src + +RUN echo '@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories \ + && apk update \ + && apk add git perl gcc g++ curl-dev \ + ruby ruby-rake ruby-rack ruby-dev \ + libexecinfo-dev@testing linux-headers make \ + ruby-bundler ruby-bigdecimal ruby-io-console ruby-irb nodejs \ + sqlite-dev mariadb-dev postgresql-dev procps \ + && echo "PATH=$WORKDIR/passenger/bin:$WORKDIR/nginx/sbin:$PATH" >> /etc/profile \ + && mkdir $WORKDIR \ + && cd $WORKDIR \ + && git clone https://github.com/phusion/passenger.git \ + && cd passenger/ \ + && git submodule update --init --recursive \ + && EXTRA_CXX_LDFLAGS="-lexecinfo" ./bin/passenger-install-nginx-module --prefix=$WORKDIR/nginx --auto + +COPY nginx.conf $WORKDIR/nginx/conf/nginx.conf + +ENV USER foreman +ENV UID 30000 +ENV HOME $WORKDIR/$USER +ENV SHELL /bin/true +RUN adduser -D -s $SHELL -h $HOME -u $UID $USER +## ENV BUNDLE_PATH ".bundle" + +ENTRYPOINT [ "/bin/sh", "-c", "$WORKDIR/nginx/sbin/nginx" ] diff --git a/passenger/nginx.conf b/passenger/nginx.conf new file mode 100644 index 0000000..8974544 --- /dev/null +++ b/passenger/nginx.conf @@ -0,0 +1,60 @@ +daemon off; +error_log /dev/stdout info; + +user foreman; +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + passenger_root /src/passenger; + passenger_ruby /usr/bin/ruby; + + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + + server { + listen 80; + server_name localhost; + + location / { + root html; + index index.html index.htm; + } + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + } + + server { + listen 80; + server_name foreman-web; + root /src/foreman/public; + + # You must explicitly set 'passenger_enabled on', otherwise + # Passenger won't serve this app. + passenger_enabled on; + rails_env production; + } +}