dctl_rb 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +13 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +86 -0
- data/LICENSE.txt +21 -0
- data/README.md +132 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dctl_rb.gemspec +39 -0
- data/exe/dctl +294 -0
- data/lib/dctl/version.rb +3 -0
- data/lib/dctl.rb +5 -0
- metadata +145 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 475f46dfcf9adacd88a19e99b41a27767e616651
|
|
4
|
+
data.tar.gz: b414f9afc62a4e06d67820c6cda649d0bd65441b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 43ad7fe838e3286acf7d1c9f31ee8ba14c4fc586b714bd4424e46c0612a52f08332a4e9806e76e34f7201e1973c2f0537e9dad419751be29229e8ab1148b453a
|
|
7
|
+
data.tar.gz: 323efea1e6cd84f4001e8b62515aee58bb4d7d6bb73d51af2779aa9e02f5a414acfae8680143e0243a9f62a7d6a6bc47dfa738967a2c10420ce7962e4ea79c90
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
sudo: false
|
|
2
|
+
language: ruby
|
|
3
|
+
rvm:
|
|
4
|
+
- 2.4.0
|
|
5
|
+
before_install: gem install bundler -v 1.16.0
|
|
6
|
+
deploy:
|
|
7
|
+
provider: rubygems
|
|
8
|
+
api_key:
|
|
9
|
+
secure: bTcQpJy7Zaaze497OQlrHsgdn+Mmk/FbvxmyapDt/5ItW9yXEWggb+XY/bBUGXeTxtxpufcM4prGpgMnStjdUeKbQRo4dWJHQyN70YsG+GdpwEHKMZiYdO7XRQdL8suFhqrAwYXt9vSgTu0aClPtZ62BbIfZImiMBh5+QRIcFwe1etMuJ1su7trQ00fPm5hElteZhpz4wFWounwigDEG4fnz24rv4z4SyqSVpbH/IrtwJT6le+dguYH73CrjFlSU1Z/uVZXqaOaoNeLSW6e+gXC3sEnitX4d1+7RprK8YwIGrX10ouGO2Qzo2v7X4Pd2DcNyefxy6lC/6K1XkwNOrNJQYEKUezBaSs9dX80Zp09oYoRUA7LwqlTTVPddhV2Isn7MivOfJ/X0UF9D+wHjYscsFu/3NoGeJ7fhbQ9IoArtUL+5Dzn6t9yICS/XMXuhEYXwpfi4xNjvP3sZ/cvlC7JcGkPLspUHTIfihoaOzHTkbLbRop6ENGaaeEKVmYGEtC+PoJJJbAhn9V0BKrLQHVBrILaLti5utO8EfiW9AJ0DZxj2RTlvUeQXnpqwjqvwuxqIuAdaicYTTCbs4/qhoAWdD5FbTfAuhU4PMTjsfbO1LYMK6pf7OJ7u3mkJnlGIVNX/aPd9Tf2JWj/16ynDGAwbggHOu8sPlXglcg8guZc=
|
|
10
|
+
gem: y
|
|
11
|
+
on:
|
|
12
|
+
tags: true
|
|
13
|
+
repo: jutonz/dctl_rb
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at jutonz42@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
dctl_rb (0.2.0.pre)
|
|
5
|
+
config (~> 1.4)
|
|
6
|
+
rainbow (~> 2.2)
|
|
7
|
+
thor (~> 0.20.0)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
activesupport (5.1.4)
|
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
14
|
+
i18n (~> 0.7)
|
|
15
|
+
minitest (~> 5.1)
|
|
16
|
+
tzinfo (~> 1.1)
|
|
17
|
+
concurrent-ruby (1.0.5)
|
|
18
|
+
config (1.6.1)
|
|
19
|
+
activesupport (>= 3.0)
|
|
20
|
+
deep_merge (~> 1.1.1)
|
|
21
|
+
dry-validation (>= 0.10.4)
|
|
22
|
+
deep_merge (1.1.1)
|
|
23
|
+
diff-lcs (1.3)
|
|
24
|
+
dry-configurable (0.7.0)
|
|
25
|
+
concurrent-ruby (~> 1.0)
|
|
26
|
+
dry-container (0.6.0)
|
|
27
|
+
concurrent-ruby (~> 1.0)
|
|
28
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
|
29
|
+
dry-core (0.4.1)
|
|
30
|
+
concurrent-ruby (~> 1.0)
|
|
31
|
+
dry-equalizer (0.2.0)
|
|
32
|
+
dry-logic (0.4.2)
|
|
33
|
+
dry-container (~> 0.2, >= 0.2.6)
|
|
34
|
+
dry-core (~> 0.2)
|
|
35
|
+
dry-equalizer (~> 0.2)
|
|
36
|
+
dry-types (0.12.2)
|
|
37
|
+
concurrent-ruby (~> 1.0)
|
|
38
|
+
dry-configurable (~> 0.1)
|
|
39
|
+
dry-container (~> 0.3)
|
|
40
|
+
dry-core (~> 0.2, >= 0.2.1)
|
|
41
|
+
dry-equalizer (~> 0.2)
|
|
42
|
+
dry-logic (~> 0.4, >= 0.4.2)
|
|
43
|
+
inflecto (~> 0.0.0, >= 0.0.2)
|
|
44
|
+
dry-validation (0.11.1)
|
|
45
|
+
concurrent-ruby (~> 1.0)
|
|
46
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
|
47
|
+
dry-core (~> 0.2, >= 0.2.1)
|
|
48
|
+
dry-equalizer (~> 0.2)
|
|
49
|
+
dry-logic (~> 0.4, >= 0.4.0)
|
|
50
|
+
dry-types (~> 0.12.0)
|
|
51
|
+
i18n (0.9.1)
|
|
52
|
+
concurrent-ruby (~> 1.0)
|
|
53
|
+
inflecto (0.0.2)
|
|
54
|
+
minitest (5.10.3)
|
|
55
|
+
rainbow (2.2.2)
|
|
56
|
+
rake
|
|
57
|
+
rake (10.5.0)
|
|
58
|
+
rspec (3.6.0)
|
|
59
|
+
rspec-core (~> 3.6.0)
|
|
60
|
+
rspec-expectations (~> 3.6.0)
|
|
61
|
+
rspec-mocks (~> 3.6.0)
|
|
62
|
+
rspec-core (3.6.0)
|
|
63
|
+
rspec-support (~> 3.6.0)
|
|
64
|
+
rspec-expectations (3.6.0)
|
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
66
|
+
rspec-support (~> 3.6.0)
|
|
67
|
+
rspec-mocks (3.6.0)
|
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
69
|
+
rspec-support (~> 3.6.0)
|
|
70
|
+
rspec-support (3.6.0)
|
|
71
|
+
thor (0.20.0)
|
|
72
|
+
thread_safe (0.3.6)
|
|
73
|
+
tzinfo (1.2.4)
|
|
74
|
+
thread_safe (~> 0.1)
|
|
75
|
+
|
|
76
|
+
PLATFORMS
|
|
77
|
+
ruby
|
|
78
|
+
|
|
79
|
+
DEPENDENCIES
|
|
80
|
+
bundler (~> 1.16)
|
|
81
|
+
dctl_rb!
|
|
82
|
+
rake (~> 10.0)
|
|
83
|
+
rspec (~> 3.0)
|
|
84
|
+
|
|
85
|
+
BUNDLED WITH
|
|
86
|
+
1.16.0
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Justin Toniazzo
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# dctl
|
|
2
|
+
|
|
3
|
+
Choosing how to organize your application's containers across multiple environments is annoying. `dctl` can help.
|
|
4
|
+
|
|
5
|
+
By using a standardized directory structure across your apps, you can:
|
|
6
|
+
1. Easily onboard new developers
|
|
7
|
+
2. Not reinvent the wheel for every new app
|
|
8
|
+
3. Let other people handle the annoying parts of docker-compose for you.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
Mostly use the same way you would use `docker-compose`, but without specifying a path to the `docker-compose.yaml` file.
|
|
13
|
+
|
|
14
|
+
Each command relies on information in the `docker-compose.yaml` for the given environment to determine things like tag versions.
|
|
15
|
+
|
|
16
|
+
The default environment is `dev`, but you can override this with `--env prod` etc
|
|
17
|
+
|
|
18
|
+
* `dctl up`
|
|
19
|
+
* `dctl down`
|
|
20
|
+
* `dctl build`
|
|
21
|
+
* `dctl push`
|
|
22
|
+
* `dctl pull`
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Targeting specific containers
|
|
26
|
+
|
|
27
|
+
Most commands also allow you to specify a specific image to target (defaulting to all images in your compose file)
|
|
28
|
+
|
|
29
|
+
* `dctl build app`
|
|
30
|
+
* Just build your app container
|
|
31
|
+
* `dctl push psql`
|
|
32
|
+
* Just push psql
|
|
33
|
+
|
|
34
|
+
### Nonstandard commands
|
|
35
|
+
|
|
36
|
+
There are also some non-compose commands to make your life easier
|
|
37
|
+
|
|
38
|
+
* `dctl connect app`
|
|
39
|
+
* Start a new shell in a running `app` container
|
|
40
|
+
* `dctl attach app`
|
|
41
|
+
* Attach your current TTY to that of the running `app` container.
|
|
42
|
+
* This is useful if you've put a debugger or something similar and need to talk directly to a running container's current shell (docker-compose eats stdin/stdout/stderr so normally this isn't possible)
|
|
43
|
+
* `dctl bash app`
|
|
44
|
+
* Spin up a new `app` image and drop you in a shell
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
If using a Gemfile, add `gem 'dctl_rb'` and execute `bundle`. Otherwise just run `gem install dctl_rb`.
|
|
49
|
+
|
|
50
|
+
In your project directory, add a file `.dctl.yaml` like so:
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
project: my_project
|
|
54
|
+
org: my_org
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
where `project` is the name of your current app (e.g. `dctl` for this repo) and `org` is the name of the docker organization where your containers are hosted (e.g. `jutonz`).
|
|
58
|
+
|
|
59
|
+
2. Create a top-level `docker` folder in your app
|
|
60
|
+
|
|
61
|
+
3. Inside `docker`, create a folder for each environment you want to support, e.g. `dev`, `staging`, `prod`
|
|
62
|
+
|
|
63
|
+
4. Inside those environment folders, create a folder for each necessary container, placing the `Dockerfile` and any related information inside
|
|
64
|
+
|
|
65
|
+
5. Inside each of those folders, create a `docker-compose.yaml` file which details how your containers relate.
|
|
66
|
+
|
|
67
|
+
A simple compose file might look like this:
|
|
68
|
+
|
|
69
|
+
```yaml
|
|
70
|
+
version: "3"
|
|
71
|
+
services:
|
|
72
|
+
app:
|
|
73
|
+
image: jutonz/dctl-dev-app:1
|
|
74
|
+
volumes:
|
|
75
|
+
- ../../:/root
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
6. Done! Your `docker` directory will probably look similar:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
docker
|
|
82
|
+
├── dev
|
|
83
|
+
│ ├── app
|
|
84
|
+
│ │ ├── Dockerfile
|
|
85
|
+
│ │ └── init.sh
|
|
86
|
+
│ ├── docker-compose.yml
|
|
87
|
+
│ └── psql
|
|
88
|
+
│ ├── Dockerfile
|
|
89
|
+
│ ├── initdb.sh
|
|
90
|
+
│ └── startdb.sh
|
|
91
|
+
└── prod
|
|
92
|
+
├── app
|
|
93
|
+
│ ├── Dockerfile
|
|
94
|
+
│ └── init.sh
|
|
95
|
+
├── docker-compose.yml
|
|
96
|
+
├── nginx
|
|
97
|
+
│ ├── Dockerfile
|
|
98
|
+
│ ├── default.conf
|
|
99
|
+
│ ├── init.sh
|
|
100
|
+
│ └── nginx.conf
|
|
101
|
+
└── psql
|
|
102
|
+
├── Dockerfile
|
|
103
|
+
├── backup.sh
|
|
104
|
+
└── initdb.sh
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Config
|
|
108
|
+
|
|
109
|
+
### Required keys
|
|
110
|
+
* `org` (required)
|
|
111
|
+
* `project` (required)
|
|
112
|
+
|
|
113
|
+
### Optional keys
|
|
114
|
+
* none yet
|
|
115
|
+
|
|
116
|
+
## Development
|
|
117
|
+
|
|
118
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
119
|
+
|
|
120
|
+
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).
|
|
121
|
+
|
|
122
|
+
## Contributing
|
|
123
|
+
|
|
124
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jutonz/dctl)rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
129
|
+
|
|
130
|
+
## Code of Conduct
|
|
131
|
+
|
|
132
|
+
Everyone interacting in the Dctl::Rb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dctl-rb/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "dctl"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/dctl_rb.gemspec
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "dctl/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "dctl_rb"
|
|
8
|
+
spec.version = Dctl::VERSION
|
|
9
|
+
spec.authors = ["Justin Toniazzo"]
|
|
10
|
+
spec.email = ["jutonz42@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Simple dockerized app config"
|
|
13
|
+
spec.homepage = "https://github.com/jutonz/dctl_rb"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
18
|
+
if spec.respond_to?(:metadata)
|
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
20
|
+
else
|
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
22
|
+
"public gem pushes."
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = "exe"
|
|
29
|
+
spec.executables = ["dctl"]
|
|
30
|
+
spec.require_paths = ["lib"]
|
|
31
|
+
|
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
35
|
+
|
|
36
|
+
spec.add_dependency "thor", "~> 0.20.0"
|
|
37
|
+
spec.add_dependency "config", "~> 1.4"
|
|
38
|
+
spec.add_dependency "rainbow", "~> 2.2"
|
|
39
|
+
end
|
data/exe/dctl
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "dctl"
|
|
4
|
+
require "thor"
|
|
5
|
+
require "pty"
|
|
6
|
+
require "rainbow"
|
|
7
|
+
require "config"
|
|
8
|
+
|
|
9
|
+
module Dctl
|
|
10
|
+
class Cli < Thor
|
|
11
|
+
class_option :env, default: "dev", type: :string
|
|
12
|
+
|
|
13
|
+
desc "build", "Build images. Pass image name to build a specific one; otherwise builds all"
|
|
14
|
+
def build(*images)
|
|
15
|
+
load_config!
|
|
16
|
+
images = versions.keys if images.empty?
|
|
17
|
+
images = Array(images)
|
|
18
|
+
env = options[:env]
|
|
19
|
+
|
|
20
|
+
puts "Generating build script for #{images.join(", ")}"
|
|
21
|
+
commands = []
|
|
22
|
+
|
|
23
|
+
images.each do |image|
|
|
24
|
+
version = versions[image]
|
|
25
|
+
tag = "#{Settings.org}/#{Settings.project}-#{env}-#{image}:#{version}"
|
|
26
|
+
dockerfile = "docker/#{env}/#{image}/Dockerfile"
|
|
27
|
+
|
|
28
|
+
commands << "#{sudo}docker #{docker_opts} build -f #{dockerfile} -t #{tag} ."
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
stream_output commands.join(" && "), exec: true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
desc "push", "Upload locally built images to the remote store"
|
|
35
|
+
def push(*images)
|
|
36
|
+
load_config!
|
|
37
|
+
images = versions.keys if images.empty?
|
|
38
|
+
images = Array(images)
|
|
39
|
+
env = options[:env]
|
|
40
|
+
|
|
41
|
+
push_cmds = []
|
|
42
|
+
|
|
43
|
+
images.each do |image|
|
|
44
|
+
version = versions[image]
|
|
45
|
+
tag_cmd = "#{sudo}docker tag #{Settings.org}/#{Settings.project}-#{env}-#{image}:#{version} #{Settings.org}/#{Settings.project}-#{env}-#{image}:latest"
|
|
46
|
+
puts tag_cmd
|
|
47
|
+
`#{tag_cmd}`
|
|
48
|
+
|
|
49
|
+
push_cmds << "#{sudo}docker push #{Settings.org}/#{Settings.project}-#{env}-#{image}:#{version}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
push_cmd = push_cmds.join " && "
|
|
53
|
+
stream_output push_cmd, exec: true
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
desc "pull", "Pull the latest remote images to your local machine"
|
|
57
|
+
def pull(*images)
|
|
58
|
+
load_config!
|
|
59
|
+
images = versions.keys if images.empty?
|
|
60
|
+
images = Array(images)
|
|
61
|
+
env = options[:env]
|
|
62
|
+
|
|
63
|
+
pull_cmds = []
|
|
64
|
+
|
|
65
|
+
images.each do |image|
|
|
66
|
+
version = versions[image]
|
|
67
|
+
pull_cmds << "#{sudo}docker pull #{Settings.org}/#{Settings.project}-#{env}-#{image}:#{version}"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
pull_cmd = pull_cmds.join " && "
|
|
71
|
+
stream_output pull_cmd, exec: true
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
desc "up", "Start your dockerized app server"
|
|
75
|
+
def up
|
|
76
|
+
load_config!
|
|
77
|
+
|
|
78
|
+
pidfile = "tmp/pids/server.pid"
|
|
79
|
+
FileUtils.rm pidfile if File.exist? pidfile
|
|
80
|
+
|
|
81
|
+
compose_opts = %w(--remove-orphans)
|
|
82
|
+
stream_output "#{sudo}docker-compose -f #{compose_file_path} up #{compose_opts.join(" ")}", exec: true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
desc "down", "Stop one or many containers"
|
|
86
|
+
def down(*args)
|
|
87
|
+
load_config!
|
|
88
|
+
stream_output "#{sudo}docker-compose -f #{compose_file_path} down #{args.join(" ")}", exec: true
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
desc "rm", "Remove one or many containers"
|
|
92
|
+
option :force, type: :boolean, default: false, aliases: %w(f)
|
|
93
|
+
def rm(*args)
|
|
94
|
+
load_config!
|
|
95
|
+
opts = " --force" if options[:force]
|
|
96
|
+
stream_output "#{sudo}docker-compose -f #{compose_file_path} rm#{opts} #{args.join(" ")}", exec: true
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
desc "start", "Start one or many containers"
|
|
100
|
+
def start(*args)
|
|
101
|
+
load_config!
|
|
102
|
+
stream_output "#{sudo}docker-compose -f #{compose_file_path} start #{args.join(" ")}", exec: true
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
desc "stop", "Stop one or many containers"
|
|
106
|
+
def stop(*args)
|
|
107
|
+
load_config!
|
|
108
|
+
stream_output "#{sudo}docker-compose -f #{compose_file_path} stop #{args.join(" ")}", exec: true
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
desc "restart", "Restart one or many containers"
|
|
112
|
+
def restart(*args)
|
|
113
|
+
load_config!
|
|
114
|
+
stream_output "#{sudo}docker-compose -f #{compose_file_path} restart #{args.join(" ")}", exec: true
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
desc "create", "Create one or many containers"
|
|
118
|
+
def create(*args)
|
|
119
|
+
load_config!
|
|
120
|
+
stream_output "#{sudo}docker-compose -f #{compose_file_path} create #{args.join(" ")}", exec: true
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
desc "recreate", "Stop, remove, build, create, and start a container"
|
|
124
|
+
option :build, type: :boolean, default: true, aliases: %w(b)
|
|
125
|
+
def recreate(container)
|
|
126
|
+
operations = ["stop", "rm -f", "build", "create", "start"]
|
|
127
|
+
|
|
128
|
+
operations.delete("build") unless options[:build]
|
|
129
|
+
|
|
130
|
+
commands = operations.map { |op| "dctl #{op} #{container}" }
|
|
131
|
+
stream_output "#{commands.join(" && ")}", exec: true
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
desc "ps", "List running containers for this environment"
|
|
135
|
+
def ps
|
|
136
|
+
load_config!
|
|
137
|
+
stream_output "#{sudo}docker-compose -f #{compose_file_path} ps", exec: true
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
desc "initdb", "Setup initial postgres database"
|
|
141
|
+
def initdb
|
|
142
|
+
load_config!
|
|
143
|
+
env = options[:env]
|
|
144
|
+
local_data_dir = File.expand_path "../tmp/psql-#{env}", __FILE__
|
|
145
|
+
`#{sudo}rm -r #{local_data_dir}` if File.exists? local_data_dir # todo prompt
|
|
146
|
+
|
|
147
|
+
cmd = "#{sudo}docker-compose -f #{compose_file_path} run --rm psql /bin/bash -c /etc/initdb.sh"
|
|
148
|
+
|
|
149
|
+
stream_output cmd, exec: true
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
desc "cleanup", "cleans up dangling docker images"
|
|
153
|
+
def cleanup
|
|
154
|
+
dangling = `#{sudo}docker images --filter dangling=true -q`.split("\n")
|
|
155
|
+
|
|
156
|
+
if dangling.none?
|
|
157
|
+
puts "No images to cleanup. Yay!"
|
|
158
|
+
exit 0
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
stream_output "#{sudo}docker rmi -f #{dangling.join(" ")}", exec: true
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
desc "bash CONTAINER", "Create a new instance of the given image with a bash prompt"
|
|
165
|
+
def bash(container = "app")
|
|
166
|
+
load_config!
|
|
167
|
+
cmd = "#{sudo}docker-compose -f #{compose_file_path} run --rm #{container} /bin/bash"
|
|
168
|
+
|
|
169
|
+
stream_output cmd, exec: true
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
desc "connect CONTAINER", "Connect to a running container."
|
|
173
|
+
def connect(image = "app")
|
|
174
|
+
load_config!
|
|
175
|
+
stream_output "#{sudo}docker-compose -f #{compose_file_path} exec #{image} /bin/bash", exec: true
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
desc "attach CONTAINER", "Connect to a running container."
|
|
179
|
+
option :env, type: :string, default: "dev"
|
|
180
|
+
def attach(image = "app")
|
|
181
|
+
load_config!
|
|
182
|
+
env = options[:env]
|
|
183
|
+
version = versions[image]
|
|
184
|
+
image = "#{Settings.org}/#{Settings.project}-#{env}-#{image}:#{version}"
|
|
185
|
+
|
|
186
|
+
cmd = "#{sudo}docker ps --filter ancestor=#{image} -aq | head -n1"
|
|
187
|
+
puts cmd
|
|
188
|
+
container = `#{cmd}`.chomp
|
|
189
|
+
|
|
190
|
+
if container.empty?
|
|
191
|
+
puts Rainbow("No running containers for image #{image}").red
|
|
192
|
+
exit 1
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
stream_output "#{sudo}docker attach #{container}", exec: true
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
desc "version", "Print version"
|
|
199
|
+
def version
|
|
200
|
+
puts Dctl::VERSION
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
no_commands do
|
|
204
|
+
def stream_output(string, print_command: true, exec: false)
|
|
205
|
+
puts string if print_command
|
|
206
|
+
if exec
|
|
207
|
+
exec string
|
|
208
|
+
else
|
|
209
|
+
PTY.spawn string do |stdout, stdin, pid|
|
|
210
|
+
stdout.each { |line| puts line }
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def sudo
|
|
216
|
+
`uname`.chomp == "Darwin" ? "" : "sudo " # use sudo on linux hosts
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def config_path
|
|
220
|
+
path = File.expand_path ".dctl.yaml", Dir.pwd
|
|
221
|
+
|
|
222
|
+
unless File.exist? path
|
|
223
|
+
error = "Could not find config file at #{path}"
|
|
224
|
+
puts Rainbow(error).red
|
|
225
|
+
exit 1
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
path
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def check_settings!
|
|
232
|
+
required_keys = %w(
|
|
233
|
+
org
|
|
234
|
+
project
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
required_keys.each do |key|
|
|
238
|
+
unless Settings.send key
|
|
239
|
+
error = "Config is missing required key '#{key}'. Please add it " \
|
|
240
|
+
"to #{config_path} and try again."
|
|
241
|
+
error += "\n\nFor more info, see https://github.com/jutonz/dctl#required-keys"
|
|
242
|
+
puts Rainbow(error).red
|
|
243
|
+
exit 1
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def load_config!
|
|
249
|
+
Config.load_and_set_settings(config_path)
|
|
250
|
+
check_settings!
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def docker_opts
|
|
254
|
+
return "" unless ENV["JENKINS"]
|
|
255
|
+
opts = "--tls"
|
|
256
|
+
|
|
257
|
+
if host = ENV["DOCKER_HOST_IP"]
|
|
258
|
+
opts += " --host tcp://#{host}"
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
opts
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def versions(env: options[:env])
|
|
265
|
+
@versions ||= begin
|
|
266
|
+
compose_file = compose_file_path env: env
|
|
267
|
+
parsed = YAML.load_file compose_file
|
|
268
|
+
images = parsed["services"].keys
|
|
269
|
+
version_map = {}
|
|
270
|
+
|
|
271
|
+
images.each do |image|
|
|
272
|
+
version_map[image] = parsed["services"][image]["image"].split(":").last
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
version_map
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def compose_file_path(env: options[:env])
|
|
280
|
+
path = File.expand_path "docker/#{env}/docker-compose.yml"
|
|
281
|
+
|
|
282
|
+
unless File.exist? path
|
|
283
|
+
err = "There is no docker compose file for env #{env} (I expected to find it at #{path})"
|
|
284
|
+
puts Rainbow(err).red
|
|
285
|
+
exit 1
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
path
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
Dctl::Cli.start ARGV
|
data/lib/dctl/version.rb
ADDED
data/lib/dctl.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dctl_rb
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Justin Toniazzo
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-11-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: thor
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.20.0
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.20.0
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: config
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.4'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.4'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rainbow
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '2.2'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '2.2'
|
|
97
|
+
description:
|
|
98
|
+
email:
|
|
99
|
+
- jutonz42@gmail.com
|
|
100
|
+
executables:
|
|
101
|
+
- dctl
|
|
102
|
+
extensions: []
|
|
103
|
+
extra_rdoc_files: []
|
|
104
|
+
files:
|
|
105
|
+
- ".gitignore"
|
|
106
|
+
- ".rspec"
|
|
107
|
+
- ".travis.yml"
|
|
108
|
+
- CODE_OF_CONDUCT.md
|
|
109
|
+
- Gemfile
|
|
110
|
+
- Gemfile.lock
|
|
111
|
+
- LICENSE.txt
|
|
112
|
+
- README.md
|
|
113
|
+
- Rakefile
|
|
114
|
+
- bin/console
|
|
115
|
+
- bin/setup
|
|
116
|
+
- dctl_rb.gemspec
|
|
117
|
+
- exe/dctl
|
|
118
|
+
- lib/dctl.rb
|
|
119
|
+
- lib/dctl/version.rb
|
|
120
|
+
homepage: https://github.com/jutonz/dctl_rb
|
|
121
|
+
licenses:
|
|
122
|
+
- MIT
|
|
123
|
+
metadata:
|
|
124
|
+
allowed_push_host: https://rubygems.org
|
|
125
|
+
post_install_message:
|
|
126
|
+
rdoc_options: []
|
|
127
|
+
require_paths:
|
|
128
|
+
- lib
|
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
|
+
requirements:
|
|
131
|
+
- - ">="
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: '0'
|
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
requirements: []
|
|
140
|
+
rubyforge_project:
|
|
141
|
+
rubygems_version: 2.6.8
|
|
142
|
+
signing_key:
|
|
143
|
+
specification_version: 4
|
|
144
|
+
summary: Simple dockerized app config
|
|
145
|
+
test_files: []
|