stack_car 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stack_car/cli.rb +48 -13
- data/lib/stack_car/version.rb +1 -1
- data/logo.jpg +0 -0
- data/stack_car.gemspec +1 -0
- data/templates/.env.erb +6 -2
- data/templates/Dockerfile.erb +3 -1
- data/templates/docker-compose-prod.yml.erb +2 -4
- data/templates/docker-compose.yml.erb +1 -1
- data/templates/hosts.erb +20 -0
- data/templates/ops/deploy.yml +49 -0
- data/templates/ops/provision.yml +17 -0
- data/templates/ops/roles/docker/README.md +27 -0
- data/templates/ops/roles/docker/tasks/main.yml +20 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9d04628829fcc7fc074d53702f0e4f6acad9932
|
4
|
+
data.tar.gz: c0d4c2c775f285b1ec6286ee97f953f8a6378838
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec12a14454db553476d6e1dd12db5ec5582484798a9a685e23542c0f7de4d678c69a53e2046c1b1f76245ee5c080159b929fdea11457257f4690a04ea9f6ddb4
|
7
|
+
data.tar.gz: 26e0b108b5fb96fec106e2210986977c01a4fe30dcef258e3421dfe97a23cc5ad232b502a951ef8208d15a10b764f4ad540eb4c11fb6b6f9a1aea16545d664d3
|
data/lib/stack_car/cli.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'erb'
|
3
|
+
require 'dotenv/load'
|
4
|
+
|
3
5
|
module StackCar
|
4
6
|
class HammerOfTheGods < Thor
|
5
7
|
include Thor::Actions
|
6
8
|
|
9
|
+
def self.source_root
|
10
|
+
File.join(File.dirname(__FILE__), '..', '..', 'templates')
|
11
|
+
end
|
12
|
+
|
7
13
|
method_option :service, default: 'web', type: :string, aliases: '-s'
|
8
14
|
desc "up", "starts docker-compose with rebuild and orphan removal, defaults to web"
|
9
15
|
def up
|
@@ -43,12 +49,34 @@ module StackCar
|
|
43
49
|
end
|
44
50
|
map rc: :console
|
45
51
|
|
52
|
+
desc "release ENVIRONTMENT", "tag and push and image to the registry"
|
53
|
+
def release(environment)
|
54
|
+
registry = "ENV['REGISTRY_HOST']ENV['REGISTRY_URI']"
|
55
|
+
run("docker login #{ENV['REGISTRY_HOST']}")
|
56
|
+
run("docker tag #{registry} #{registry}:#{environment}-#{Time.now.strftime("%Y%m%d%I%M%S")}")
|
57
|
+
run("docker push #{registry}:#{environment}-#{Time.now.strftime("%Y%m%d%I%M%S")}")
|
58
|
+
run("docker tag #{registry} #{registry}:#{environment}-latest")
|
59
|
+
run("docker push #{registry}:#{environment}-latest")
|
60
|
+
end
|
61
|
+
|
62
|
+
desc "provision ENVIRONMENT", "configure the servers for docker and then deploy an image"
|
63
|
+
def provision(environment)
|
64
|
+
run("cd ops && ansible-playbook -i hosts #{environment} provision.yml")
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "deploy ENVIRONMENT", "deploy an image from the registry"
|
68
|
+
def deploy(environment)
|
69
|
+
run("cd ops && ansible-playbook -i hosts #{environment} deploy.yml")
|
70
|
+
end
|
71
|
+
|
46
72
|
method_option :elasticsearch, default: false, type: :boolean, aliases: '-e'
|
47
73
|
method_option :solr, default: false, type: :boolean, aliases: '-s'
|
48
74
|
method_option :postgres, default: false, type: :boolean, aliases: '-p'
|
49
75
|
method_option :mysql, default: false, type: :boolean, aliases: '-m'
|
50
76
|
method_option :redis, default: false, type: :boolean, aliases: '-r'
|
51
77
|
method_option :fcrepo, default: false, type: :boolean, aliases: '-f'
|
78
|
+
method_option :deploy, default: false, type: :boolean, aliases: '-d'
|
79
|
+
method_option :rancher, default: false, type: :boolean, aliases: '-dr'
|
52
80
|
method_option :sidekiq, default: false, type: :boolean, aliases: '-sq' # TODO
|
53
81
|
method_option :mongodb, default: false, type: :boolean, aliases: '-mg' # TODO
|
54
82
|
desc 'dockerize DIR', 'Will copy the docker tempates in to your project, see options for supported dependencies'
|
@@ -61,21 +89,28 @@ module StackCar
|
|
61
89
|
def dockerize(dir=nil)
|
62
90
|
if dir
|
63
91
|
Dir.chdir(dir)
|
92
|
+
else
|
93
|
+
dir = '.'
|
64
94
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
['.dockerignore', 'Dockerfile', 'docker-compose.yml', 'docker-compose-prod.yml', '.gitlab-ci.yml', '.env'].each do |
|
74
|
-
|
75
|
-
renderer = ERB.new(File.read(File.join(template_path, template + '.erb')), 0, '-')
|
76
|
-
File.write(template, renderer.result(binding))
|
95
|
+
@project_name = File.basename(File.expand_path(dir))
|
96
|
+
@db_libs = []
|
97
|
+
@db_libs << "libpq-dev postgresql-client" if options[:postgres]
|
98
|
+
@db_libs << "mysql-client" if options[:mysql]
|
99
|
+
@db_libs << "libc6-dev libreoffice imagemagick unzip" if options[:fcrepo]
|
100
|
+
@db_libs = @db_libs.join(' ')
|
101
|
+
|
102
|
+
|
103
|
+
['.dockerignore', 'Dockerfile', 'docker-compose.yml', 'docker-compose-prod.yml', '.gitlab-ci.yml', '.env'].each do |template_file|
|
104
|
+
template("#{template_file}.erb", template_file)
|
77
105
|
end
|
78
|
-
end
|
79
106
|
|
107
|
+
if options[:deploy] || options[:rancher]
|
108
|
+
directory('ops')
|
109
|
+
['hosts'].each do |template_file|
|
110
|
+
template("#{template_file}.erb", "ops/#{template_file}")
|
111
|
+
end
|
112
|
+
say 'Please update ops/hosts with the correct server addresses'
|
113
|
+
end
|
114
|
+
end
|
80
115
|
end
|
81
116
|
end
|
data/lib/stack_car/version.rb
CHANGED
data/logo.jpg
ADDED
Binary file
|
data/stack_car.gemspec
CHANGED
data/templates/.env.erb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
<% if options[:postgres] -%>
|
2
|
-
POSTGRES_DB=<%= project_name %>
|
2
|
+
POSTGRES_DB=<%= @project_name %>
|
3
3
|
POSTGRES_USER=postgres
|
4
4
|
POSTGRES_PASSWORD=DatabaseFTW
|
5
5
|
<% end -%>
|
6
6
|
<% if options[:mysql] -%>
|
7
|
-
MYSQL_DATABASE=<%= project_name %>
|
7
|
+
MYSQL_DATABASE=<%= @project_name %>
|
8
8
|
MYSQL_ROOT_PASSWORD=DatabaseFTW
|
9
9
|
<% end -%>
|
10
|
+
<% if options[:deploy] || options[:rancher] -%>
|
11
|
+
REGISTRY_HOST=registry.gitlab.com
|
12
|
+
REGISTRY_URI /TODO/<%= @project_name %>
|
13
|
+
<% end -%>
|
data/templates/Dockerfile.erb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
FROM ruby:2.3.0
|
2
2
|
|
3
|
-
RUN apt-get update -qq && apt-get install -y build-essential nodejs pv libsasl2-dev <%= db_libs %> && \
|
3
|
+
RUN apt-get update -qq && apt-get install -y build-essential nodejs pv libsasl2-dev <%= @db_libs %> && \
|
4
4
|
apt-get clean && \
|
5
5
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
|
6
6
|
|
@@ -23,3 +23,5 @@ ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \
|
|
23
23
|
|
24
24
|
ADD Gemfile* $APP_HOME/
|
25
25
|
RUN bundle install
|
26
|
+
|
27
|
+
COPY . $APP_HOME
|
@@ -1,13 +1,11 @@
|
|
1
1
|
version: '2'
|
2
2
|
services:
|
3
3
|
web:
|
4
|
-
image: <%= project_name %>:latest
|
5
|
-
command: bundle exec rails s -p 3000 -b '0.0.0.0'
|
4
|
+
image: <%= @project_name %>:latest
|
5
|
+
command: bundle exec rake assets:precompile && bundle exec rails s -p 3000 -b '0.0.0.0'
|
6
6
|
environment:
|
7
7
|
- RAILS_ENV=production
|
8
8
|
- RACK_ENV=production
|
9
9
|
restart: unless-stopped
|
10
10
|
ports:
|
11
11
|
- "3000:3000"
|
12
|
-
volumes:
|
13
|
-
- .:/app
|
data/templates/hosts.erb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
[staging]
|
2
|
+
XX.XXX.XXX.XXX ansible_user=centos
|
3
|
+
|
4
|
+
[production]
|
5
|
+
XX.XXX.XXX.XXX ansible_user=ubuntu
|
6
|
+
|
7
|
+
[servers:children]
|
8
|
+
staging
|
9
|
+
production
|
10
|
+
|
11
|
+
[servers:vars]
|
12
|
+
registry_host=registry.gitlab.com
|
13
|
+
compose_dir=/var/www
|
14
|
+
project_name=<%= @project_name %>
|
15
|
+
|
16
|
+
[staging:vars]
|
17
|
+
tag=staging-latest
|
18
|
+
|
19
|
+
[production:vars]
|
20
|
+
tag=production-latest
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
- name: Deploy
|
3
|
+
hosts: all
|
4
|
+
become: true
|
5
|
+
vars_prompt:
|
6
|
+
- name: "registry_user"
|
7
|
+
prompt: "What is your registry email?"
|
8
|
+
- name: "registry_password"
|
9
|
+
prompt: "What is your registry password?"
|
10
|
+
|
11
|
+
tasks:
|
12
|
+
- file:
|
13
|
+
path: "{{ compose_dir }}"
|
14
|
+
state: directory
|
15
|
+
|
16
|
+
- name: Upload docker-compose files
|
17
|
+
synchronize:
|
18
|
+
src: ../docker-compose-prod.yml
|
19
|
+
dest: "{{ compose_dir }}/{{ project_name }}.yml"
|
20
|
+
|
21
|
+
- name: Login to registry
|
22
|
+
docker_login:
|
23
|
+
registry: "{{ registry_host }}"
|
24
|
+
username: "{{ registry_user }}"
|
25
|
+
password: "{{ registry_password }}"
|
26
|
+
register: authout
|
27
|
+
|
28
|
+
- debug: var=authout
|
29
|
+
|
30
|
+
- name: Restart service
|
31
|
+
command: "cd {{ compose_dir }} && docker-compose -f {{ project_name }}.yml pull web && docker-compose -f {{ project_name }}.yml up -d web"
|
32
|
+
environment:
|
33
|
+
TAG: "{{ tag }}"
|
34
|
+
register: output
|
35
|
+
# TODO - ansible docker-service doesn't work with custom registery right now
|
36
|
+
# - name: Restart service
|
37
|
+
# docker_service:
|
38
|
+
# project_name: "{{ project_name }}"
|
39
|
+
# project_src: "{{ compose_dir }}"
|
40
|
+
# files:
|
41
|
+
# - "{{ project_name }}.yml"
|
42
|
+
# pull: yes
|
43
|
+
# services: web
|
44
|
+
# debug: yes
|
45
|
+
# environment:
|
46
|
+
# TAG: "{{ tag }}"
|
47
|
+
# register: output
|
48
|
+
#
|
49
|
+
- debug: var=output
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
- name: Set up Docker on host
|
3
|
+
hosts: all
|
4
|
+
become: true
|
5
|
+
roles:
|
6
|
+
- docker
|
7
|
+
tasks:
|
8
|
+
- name: Install Compose Module
|
9
|
+
pip: name=docker-compose
|
10
|
+
- name: Upload docker-compose files
|
11
|
+
synchronize:
|
12
|
+
src: ../.env
|
13
|
+
dest: "{{ compose_dir }}/{{ project_name }}_env"
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
- include: deploy.yml
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Docker Installation - Ansible Role
|
2
|
+
Install [Docker](http://docker.com) on CentOS and Red Hat hosts. Used to make sure that docker is installed
|
3
|
+
and running to enable the use of [Ansible's docker module](http://docs.ansible.com/docker_module.html)
|
4
|
+
|
5
|
+
### Installation
|
6
|
+
Add this repository as a submodule of your git with:
|
7
|
+
|
8
|
+
```
|
9
|
+
git submodule add git@github.com:Vinelab/ansible-docker roles/docker
|
10
|
+
```
|
11
|
+
|
12
|
+
Or simply clone this repository directly into your *roles* directory:
|
13
|
+
|
14
|
+
```
|
15
|
+
git clone git@github.com:Vinelab/ansible-docker roles/docker
|
16
|
+
```
|
17
|
+
|
18
|
+
### Usage
|
19
|
+
|
20
|
+
```yaml
|
21
|
+
- hosts: all
|
22
|
+
- roles:
|
23
|
+
- docker
|
24
|
+
```
|
25
|
+
|
26
|
+
#### Tags
|
27
|
+
All tasks have the tag `docker`
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
- name: Install python setup tools
|
3
|
+
yum: name=python-setuptools
|
4
|
+
tags: docker
|
5
|
+
|
6
|
+
- name: Install Pypi
|
7
|
+
easy_install: name=pip
|
8
|
+
tags: docker
|
9
|
+
|
10
|
+
- name: Install docker-py
|
11
|
+
pip: name=docker-py
|
12
|
+
tags: docker
|
13
|
+
|
14
|
+
- name: Install Docker
|
15
|
+
yum: name=docker state=latest
|
16
|
+
tags: docker
|
17
|
+
|
18
|
+
- name: Make sure Docker is running
|
19
|
+
service: name=docker state=running
|
20
|
+
tags: docker
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stack_car
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Kaufman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dotenv
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: thor
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,6 +131,7 @@ files:
|
|
117
131
|
- lib/stack_car.rb
|
118
132
|
- lib/stack_car/cli.rb
|
119
133
|
- lib/stack_car/version.rb
|
134
|
+
- logo.jpg
|
120
135
|
- public/.gitkeep
|
121
136
|
- public/logo.jpg
|
122
137
|
- public/logo.pxm
|
@@ -127,6 +142,11 @@ files:
|
|
127
142
|
- templates/Dockerfile.erb
|
128
143
|
- templates/docker-compose-prod.yml.erb
|
129
144
|
- templates/docker-compose.yml.erb
|
145
|
+
- templates/hosts.erb
|
146
|
+
- templates/ops/deploy.yml
|
147
|
+
- templates/ops/provision.yml
|
148
|
+
- templates/ops/roles/docker/README.md
|
149
|
+
- templates/ops/roles/docker/tasks/main.yml
|
130
150
|
homepage: https://gitlab.com/notch8/stack_car
|
131
151
|
licenses: []
|
132
152
|
metadata: {}
|