chbuild 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66317c7b76fd467dd5b6506a9a2e5b5cb77a2d5c
4
+ data.tar.gz: 599e67c26453942029511828b2154e155f20bff0
5
+ SHA512:
6
+ metadata.gz: 6f41562f0add9e39659440ad43a8c31f258a0e4bb82269bed0c8cc4b96334110d0232675dab70fe270f7e4d9d0a69e76ac582ab343f337371c3753830030fae0
7
+ data.tar.gz: 13f5d4ffe2a64ce182488043d597317148f0a774e4a7174f707a3b9e5d928fbb4ed83a34fa322c8d4e6f019d4281a834646c3133d3e4749c9f81c976b7a1d784
@@ -0,0 +1,15 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.{sh,markdown,md}]
12
+ indent_size = 4
13
+
14
+ [*.{markdown,md}]
15
+ trim_trailing_whitespace = false
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /webroot/
11
+ /iniscripts/
12
+ .chbuild.yml
13
+ .chbuild.yaml
14
+ erl_crash.dump
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'templates/**/*'
4
+ - 'vendor/**/*'
5
+ TargetRubyVersion: 2.3
6
+
7
+ Metrics/LineLength:
8
+ Max: 100
9
+
10
+ Metrics/MethodLength:
11
+ Max: 50
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,9 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This CHANGELOG follows [Keep a CHANGELOG](http://keepachangelog.com/).
4
+
5
+ ## [0.0.1] - 2016-10-20
6
+ ### First open-source release
7
+
8
+ ## [0.0.1] - 2016-10-10
9
+ ### First internal release
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at gabor.takacs@cheppers.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify your gem's dependencies in chbuild.gemspec
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Cheppers Ltd. <info@cheppers.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,152 @@
1
+ # chbuild
2
+ chbuild is an open-source command line application written in Ruby. It's main purpose is to simplify web app development by running a site using Docker containers so you don't have to install Apache, PHP and PHP extensions on your own machine.
3
+
4
+ ## Requirements
5
+ * Ruby 2.3.0+
6
+ * Docker (for Mac see [this](https://docs.docker.com/engine/installation/mac/#/docker-for-mac))
7
+
8
+ ## Installation
9
+ 1. Install requirements (see above)
10
+ 2. `gem install chbuild`
11
+
12
+ ## Usage
13
+ 1. Create a `.chbuild.yml` file in the root of your repository
14
+ 2. Launch docker
15
+ 3. Run `$ chbuild start` to build the image, launch the MySQL container and the chbuild container
16
+ 4. Run `$ chbuild restart` to restart the chbuild container
17
+
18
+ When you run the `start` command the following will happen:
19
+
20
+ 1. chbuild builds a docker image with apache, php-fpm and a couple of PHP extensions and configure them to work together
21
+ 2. chbuild downloads and starts a MySQL container (of your choice or the latest one if undefined in the YAML)
22
+ 3. chbuild starts the chbuild container
23
+ 4. chbuild runs the init script
24
+ 5. You can access the site on `localhost:8088`
25
+ 6. If your root directory is empty chbuild will create an index.php file with a phpinfo inside
26
+
27
+ When you run the `restart` command the following will happen:
28
+
29
+ 1. chbuild checks if your image is up-to-date and builds a new one if needed
30
+ 2. chbuild kills the currently running chbuild container
31
+ 3. chbuild starts a new container and reruns the init script
32
+
33
+ ## The container
34
+ The following happens in the container when you start it:
35
+
36
+ 1. Export the specified envrionment variables (`env` section)
37
+ 2. Runs the commands from the `before` section
38
+ 3. Starts apache
39
+ 4. Starts php-fpm to keep alive the container
40
+
41
+ ## The .chbuild.yml
42
+ The build file consists of sections: `version`, `use`, `before`, `env`.
43
+ The minimal YAML file for chbuild to work properly:
44
+ ```yaml
45
+ ---
46
+ version: 1.0
47
+ ```
48
+
49
+ ## Sections of the build file
50
+ ### version - [required]
51
+ Version of the build file. Currently this is the only required section.
52
+
53
+ Allowed values: `1.0`
54
+
55
+ **Example**
56
+ ```yaml
57
+ ---
58
+ version: 1.0
59
+ ```
60
+
61
+ ### use - [optional]
62
+ Specify the MySQL and PHP versions you want to use.
63
+
64
+ #### PHP
65
+ Current default PHP version: **5.6.25**
66
+
67
+ At the moment specifying a PHP version is not working (to be implemented soon).
68
+
69
+ #### MySQL
70
+ Default is the latest from Dockerhub
71
+
72
+ To connect:
73
+
74
+ * no username
75
+ * password is 'admin'
76
+ * host address: $MYSQL_PORT_3306_TCP_ADDR
77
+
78
+ **Example**
79
+ ```yaml
80
+ ---
81
+ version: 1.0
82
+ use:
83
+ mysql: 5.6.20
84
+ ```
85
+
86
+ ### env - [optional]
87
+ Specify environment variables to use them in the `before` script or in your site
88
+
89
+ **Example**
90
+ ```yaml
91
+ ---
92
+ version: 1.0
93
+ env:
94
+ THE_ANSWER: 42
95
+ DOCTOR: Who
96
+ ```
97
+
98
+ ### before - [optional]
99
+ Run scrips before starting php-fpm.
100
+
101
+ **Example**
102
+ ```yaml
103
+ ---
104
+ version: 1.0
105
+ before:
106
+ - composer install
107
+ ```
108
+
109
+ ## Example .chbuild.yml
110
+ ```yaml
111
+ ---
112
+ version: 1.0
113
+ use:
114
+ mysql: 5.6.20
115
+ env:
116
+ YAML_DEFINED: envvar
117
+ ANOTHER_ENV_VAR: CHBuild
118
+ before:
119
+ - echo "Hello, $ANOTHER_ENV_VAR!<br />Generated at $(date)<br /> MySQL version $MYSQL_ENV_MYSQL_VERSION" > /www/index.php
120
+ ```
121
+
122
+ ## Commands
123
+ ```bash
124
+ $ chbuild help
125
+ Commands:
126
+ chbuild --version, -V # Current version
127
+ chbuild delete [-CIM] # Delete container, image or MySQL container(s)
128
+ chbuild help [COMMAND] # Describe available commands or one specific command
129
+ chbuild log # Get container log
130
+ chbuild restart # Restart chbuild container
131
+ chbuild start # Build and start everything
132
+ chbuild validate # Validate build definition file
133
+
134
+ Options:
135
+ -v, [--verbose], [--no-verbose]
136
+ -f, [--force]
137
+ ```
138
+
139
+ ## Development
140
+ After checking out the repo, run `bin/setup` to install dependencies.
141
+
142
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
143
+
144
+ ## Contributing
145
+ 1. Fork the repo
146
+ 2. Commit your changes to your own repo on a separate branch
147
+ 3. Submit pull request
148
+
149
+ If you can, please use the provided [EditorConfig](http://editorconfig.org/) file!
150
+
151
+ ## License
152
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). See more in LICENSE.txt
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'chbuild'
5
+ require 'colorize'
6
+ require 'pp'
7
+ require 'thor'
8
+
9
+ # rubocop:disable Metrics/AbcSize, Metrics/ClassLength
10
+ # CHBuild CLI
11
+ class CHBuildCLI < Thor
12
+ no_commands do
13
+ def build_image(options: {})
14
+ if CHBuild::Controller.image_exist?
15
+ puts 'Image already exists, skipping image build' if options[:verbose]
16
+ return
17
+ end
18
+ if options[:verbose]
19
+ CHBuild::Controller.build { |message| puts message }
20
+ else
21
+ start = Time.now
22
+ CHBuild::Controller.build do |message|
23
+ message.match(/step \d{1,2}/i) do |match|
24
+ num = match.to_s.split[1].to_i
25
+ step = '['.green + "#{(Time.now - start).round(2)}s".rjust(6) + ']'.green
26
+ text = "Building your image#{'.' * num}".green
27
+ print "#{step} #{text}\r"
28
+ $stdout.flush
29
+ end
30
+ end
31
+ end
32
+ print "\n"
33
+ $stdout.flush
34
+ puts 'Image build successfully'.green
35
+ end
36
+
37
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
38
+ def run_container(restart: false, options: {})
39
+ if (c = CHBuild::Controller.container?) && restart
40
+ CHBuild::Controller.delete_container
41
+ puts 'Container killed'.green
42
+ elsif c
43
+ puts "Container already exists, run 'chbuild restart' to relaunch it" if options[:verbose]
44
+ return
45
+ end
46
+
47
+ controller_run = CHBuild::Controller.run(webroot: Dir.pwd) do |log|
48
+ puts log if options[:verbose]
49
+ end
50
+
51
+ unless controller_run
52
+ puts 'Could not start container :('.red
53
+ exit 1
54
+ end
55
+
56
+ puts 'Container started'.green
57
+ puts "Container id: #{CHBuild::Controller.container_id}" if options[:verbose]
58
+ end
59
+
60
+ def delete_mysql_containers
61
+ if CHBuild::Controller.delete_mysql_containers
62
+ 'MySQL container(s) killed'.green
63
+ else
64
+ 'MySQL container(s) not found'.yellow
65
+ end
66
+ end
67
+
68
+ def delete_image
69
+ if CHBuild::Controller.delete_image
70
+ 'Image deleted'.green
71
+ else
72
+ 'Image not found'.yellow
73
+ end
74
+ end
75
+
76
+ def delete_container
77
+ if CHBuild::Controller.delete_container
78
+ 'Container killed'.green
79
+ else
80
+ 'Container not found'.yellow
81
+ end
82
+ end
83
+ end
84
+
85
+ class_option :verbose, type: :boolean, aliases: '-v'
86
+ class_option :force, type: :boolean, aliases: '-f'
87
+
88
+ map %w(--version -V) => :__print_version
89
+ desc '--version, -V', 'Current version'
90
+ def __print_version
91
+ puts CHBuild::VERSION
92
+ end
93
+
94
+ desc 'start', 'Build and start everything'
95
+ def start
96
+ build_image(options: options)
97
+
98
+ run_container(options: options)
99
+
100
+ puts "Build environment up and running; run 'chbuild restart' to relaunch container".green
101
+ end
102
+
103
+ desc 'restart', 'Restart chbuild container'
104
+ def restart
105
+ build_image(options: options)
106
+
107
+ run_container(restart: true, options: options)
108
+
109
+ puts "Build environment up and running; run 'chbuild restart' to relaunch container".green
110
+ end
111
+
112
+ desc 'log', 'Get container log'
113
+ def log
114
+ puts CHBuild::Controller.container_logs
115
+ end
116
+
117
+ desc 'delete [-C] [-I] [-M]', 'Delete container, image or MySQL container(s)'
118
+ method_option :container, aliases: '-C', type: :boolean, default: false, desc: 'Delete container'
119
+ method_option :image, aliases: '-I', type: :boolean, default: false, desc: 'Delete image'
120
+ method_option 'mysql-container',
121
+ aliases: '-M',
122
+ type: :boolean,
123
+ default: false,
124
+ desc: 'Delete MySQL container(s)'
125
+ def delete
126
+ puts delete_container if options[:container]
127
+
128
+ puts delete_image if options[:image]
129
+
130
+ puts delete_mysql_containers if options['mysql-container']
131
+
132
+ rescue => e
133
+ puts e.message.red
134
+ exit 1
135
+ end
136
+
137
+ desc 'validate', 'Validate build definition file'
138
+ method_option :path,
139
+ aliases: '-p',
140
+ default: File.join(Dir.pwd, '.chbuild.yml'),
141
+ desc: 'Build definition file path'
142
+ def validate
143
+ config = CHBuild::Controller.config(options[:path])
144
+
145
+ puts "Config path: #{config.path}".green
146
+
147
+ if options[:verbose]
148
+ puts 'Config from file:'.yellow
149
+ pp config.raw
150
+ puts 'Final config:'.yellow
151
+ pp config
152
+ end
153
+
154
+ if config.errors.length.zero?
155
+ puts 'Looks good'.green
156
+ return
157
+ end
158
+
159
+ puts "Errors:\n".red
160
+ config.errors.each do |err|
161
+ puts err.red
162
+ end
163
+ exit 1
164
+ end
165
+ end
166
+
167
+ CHBuildCLI.start(ARGV)