farmstead 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ # Tinman - the Fertilizer
2
+ #
3
+ # Tinman is responsible for analyzing a site for changes
4
+ # and updating site configs
5
+ #
6
+ # None of the logic has actually been built and
7
+ # this may require some AI but for now it's
8
+ # just responding that everything is OK
9
+ #
10
+ # Tinman is running as a Consumer to the Wood topic and it will automatically
11
+ # pick up the message, do it's job and then send a message
12
+ # as a Producer to the Field topic
13
+ #
14
+ # Every micro-service inherits the Service class
15
+ module Farmstead
16
+ class Tinman < Service
17
+ # Doing nothing...for now
18
+ # thi is handled by magic_work
19
+ def producer
20
+ loop do
21
+ puts 'Doing nothing'
22
+ sleep 300
23
+ end
24
+ end
25
+
26
+ # Subscribed to the Wood topic
27
+ # Works on message
28
+ def consumer
29
+ @consumer.subscribe('Wood')
30
+ trap('TERM') { @consumer.stop }
31
+ @consumer.each_message do |message|
32
+ puts "Received: #{message.value}"
33
+ magic_work(message.value)
34
+ @consumer.mark_message_as_processed(message)
35
+ end
36
+ end
37
+
38
+ # Do the magic work to determine if the site has changed
39
+ # and update the config
40
+ # Returns JSON String
41
+ def magic_work(site)
42
+ hash = JSON.parse(site)
43
+ hash['tinman'] = 'true'
44
+ json = hash.to_json
45
+ puts "Writing: #{json}"
46
+ write_message(json, topic: 'Field')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Farmstead
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,6 @@
1
+ vendor/
2
+ .env
3
+ README.md
4
+ Dockerfile
5
+ docker-compose.yml
6
+ kafka
@@ -0,0 +1,9 @@
1
+ MYSQL_ROOT_PASSWORD=Rc2$NE99p5%^
2
+ MYSQL_DATABASE=farmstead
3
+ MYSQL_USER=farmstead
4
+ MYSQL_PASSWORD=farmstead
5
+ MYSQL_HOST=mysql
6
+ RAILS_ENV=development
7
+ KAFKA_ADVERTISED_HOST_NAME=192.168.1.139
8
+ KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
9
+ KAFKA_CREATE_TOPICS=Wood:1:1,Field:1:1,Forest:1:1,Road:1:1
@@ -0,0 +1,24 @@
1
+ FROM ruby:2.4.1
2
+
3
+ RUN apt-get update -qq && \
4
+ apt-get install -y build-essential \
5
+ libpq-dev \
6
+ nodejs \
7
+ telnet \
8
+ bash \
9
+ supervisor \
10
+ vim \
11
+ xterm \
12
+ ca-certificates \
13
+ unzip && \
14
+ rm -rf /var/cache/apk/*
15
+
16
+ ## Setup Rails
17
+
18
+ RUN gem install rails && rails new <%= @name %> <% if @database %>-d <%= @database %><% end %>
19
+ WORKDIR /<%= @name %>
20
+ ADD app/* /<%= @name %>/app
21
+
22
+ EXPOSE 3000
23
+
24
+ CMD /<%= @name %>/bin/rails s -b 0.0.0.0
@@ -0,0 +1,25 @@
1
+ FROM ruby:2.4.1
2
+
3
+ RUN apt-get update -qq && \
4
+ apt-get install -y build-essential \
5
+ libpq-dev \
6
+ nodejs \
7
+ telnet \
8
+ bash \
9
+ supervisor \
10
+ vim \
11
+ xterm \
12
+ ca-certificates \
13
+ unzip && \
14
+ rm -rf /var/cache/apk/*
15
+
16
+ ## Setup Ruby
17
+ RUN mkdir /myapp
18
+ WORKDIR /myapp
19
+ ADD Gemfile* /myapp/
20
+ RUN gem install bundler && bundle install --jobs 20 --retry 5
21
+ ADD . /myapp
22
+
23
+ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
24
+
25
+ CMD /usr/bin/supervisord
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
6
+
7
+ gemspec
8
+
9
+ gem "coffee-rails", "~> 4.2"
10
+ gem "httparty", "~> 0.15.6"
11
+ gem "jbuilder", "~> 2.5"
12
+ gem "jquery-rails", "~> 4.3.1"
13
+ gem "mechanize", "~> 2.7.5"
14
+ gem "mysql2", "~> 0.4.10"
15
+ gem "nokogiri", "~> 1.8.1"
16
+ gem "omniauth-auth0", "~> 2.0.0"
17
+ gem "puma", "~> 3.0"
18
+ gem "rails", "~> 5.0.0"
19
+ gem "ruby-kafka", "~> 0.5.1"
20
+ gem "sass-rails", "~> 5.0"
21
+ gem "turbolinks", "~> 5"
22
+ gem "uglifier", ">= 1.3.0"
23
+ gem "watir", "~> 6.10"
24
+
25
+ group :development, :test do
26
+ gem "byebug", platform: :mri
27
+ end
28
+
29
+ group :development do
30
+ gem "dotenv", "~> 0.11.1"
31
+ gem "listen", "~> 3.0.5"
32
+ gem "pry"
33
+ gem "spring"
34
+ gem "spring-watcher-listen", "~> 2.0.0"
35
+ gem "web-console"
36
+ end
@@ -0,0 +1,6 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
6
+
@@ -0,0 +1,72 @@
1
+ version: '3'
2
+
3
+ services:
4
+ mysql:
5
+ image: 'mysql:5.7'
6
+ env_file:
7
+ - '.env'
8
+ ports:
9
+ - '3306:3306'
10
+
11
+ zookeeper:
12
+ image: wurstmeister/zookeeper
13
+ ports:
14
+ - '2181:2181'
15
+
16
+ kafka:
17
+ depends_on:
18
+ - 'zookeeper'
19
+ image: wurstmeister/kafka:0.10.2.1
20
+ ports:
21
+ - '9092:9092'
22
+ env_file:
23
+ - '.env'
24
+ volumes:
25
+ - /var/run/docker.sock:/var/run/docker.sock
26
+
27
+ dorothy:
28
+ depends_on:
29
+ - 'mysql'
30
+ build:
31
+ context: .
32
+ dockerfile: Dockerfile-dorothy
33
+ ports:
34
+ - '3000:3000'
35
+ env_file:
36
+ - '.env'
37
+
38
+ glenda:
39
+ depends_on:
40
+ - 'dorothy'
41
+ build: .
42
+ environment:
43
+ SERVICE: glenda
44
+ env_file:
45
+ - '.env'
46
+
47
+ tinman:
48
+ depends_on:
49
+ - 'dorothy'
50
+ build: .
51
+ environment:
52
+ SERVICE: tinman
53
+ env_file:
54
+ - '.env'
55
+
56
+ scarecrow:
57
+ depends_on:
58
+ - 'dorothy'
59
+ build: .
60
+ environment:
61
+ SERVICE: scarecrow
62
+ env_file:
63
+ - '.env'
64
+
65
+ cowardlylion:
66
+ depends_on:
67
+ - 'dorothy'
68
+ build: .
69
+ environment:
70
+ SERVICE: cowardlylion
71
+ env_file:
72
+ - '.env'
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Script to start Farmstead on Docker
4
+
5
+ echo "Cleaning up old environment"
6
+ docker-compose stop > /dev/null 2>&1
7
+ docker-compose rm -f > /dev/null 2>&1
8
+
9
+ echo "Building new environment"
10
+ docker-compose build > /dev/null 2>&1
11
+
12
+ echo "Starting MySQL and Zookeeper"
13
+ docker-compose up -d mysql zookeeper > /dev/null 2>&1
14
+
15
+ echo "Sleeping"
16
+ sleep 10
17
+
18
+ echo "Starting dorothy"
19
+ docker-compose up -d dorothy > /dev/null 2>&1
20
+
21
+ echo "Create and Seed MySQL DB"
22
+ docker-compose exec dorothy rails db:setup > /dev/null 2>&1
23
+
24
+ echo "Starting everything else"
25
+ docker-compose up -d > /dev/null 2>&1
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Script to start Farmstead on Docker
4
+
5
+ trap mytrap ERR #0 #EXIT 0 HUP INT QUIT PIPE TERM
6
+
7
+ mytrap() {
8
+ excode=$?
9
+ if [ $excode -ne 0 ]; then
10
+ printf "\tFailed!\n"
11
+ exit 1
12
+ fi
13
+ }
14
+
15
+ success() {
16
+ printf "\tSucceeded\n"
17
+ }
18
+
19
+ # Counts down a number of seconds
20
+ countdown() {
21
+ secs=$1
22
+ while [ $secs -gt 0 ]; do
23
+ echo -ne "$secs\033[0K\r"
24
+ sleep 1
25
+ : $((secs--))
26
+ done
27
+ }
28
+
29
+ echo "Cleaning up old environment"
30
+ docker-compose stop > /dev/null 2>&1
31
+ docker-compose rm -f > /dev/null 2>&1
32
+ #docker stop $(docker ps -a -q) > /dev/null 2>&1
33
+ #docker rm $(docker ps -a -q) > /dev/null 2>&1
34
+ success
35
+
36
+ echo "Building new environment"
37
+ docker-compose build > /dev/null 2>&1
38
+ success
39
+
40
+ echo "Starting MySQL and Zookeeper"
41
+ docker-compose up -d mysql zookeeper > /dev/null 2>&1
42
+ success
43
+
44
+ echo "Sleeping"
45
+ countdown 10
46
+
47
+ echo "Starting dorothy"
48
+ docker-compose up -d dorothy > /dev/null 2>&1
49
+ success
50
+
51
+ echo "Create and Seed MySQL DB"
52
+ docker-compose exec dorothy rails db:setup > /dev/null 2>&1
53
+ success
54
+
55
+ echo "Starting everything else"
56
+ docker-compose up -d > /dev/null 2>&1
57
+ success
@@ -0,0 +1,10 @@
1
+ [supervisord]
2
+ nodaemon=true
3
+
4
+ [program:producer]
5
+ command=/usr/local/bin/ruby /myapp/app/lib/farmstead.rb %(ENV_SERVICE)s producer
6
+ redirect_stderr=true
7
+
8
+ [program:consumer]
9
+ command=/usr/local/bin/ruby /myapp/app/lib/farmstead.rb %(ENV_SERVICE)s consumer
10
+ redirect_stderr=true
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: farmstead
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ken Jenney
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-28 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
+ description: Farmstead is a modular data pipeline platform. Farmstead makes creating
56
+ and deploying a fully-functional data pipeline a snap. It is built on top of Rails/Ruby
57
+ and uses Docker. This combination allows for a super-fast deployment and prototyping
58
+ process.
59
+ email:
60
+ - mastermindg@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".rubocop.yml"
68
+ - ".travis.yml"
69
+ - ".yardopts"
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - examples/myproject.yml
77
+ - farmstead.gemspec
78
+ - lib/farmstead.rb
79
+ - lib/farmstead/cli.rb
80
+ - lib/farmstead/cowardlylion.rb
81
+ - lib/farmstead/glenda.rb
82
+ - lib/farmstead/project.rb
83
+ - lib/farmstead/scarecrow.rb
84
+ - lib/farmstead/service.rb
85
+ - lib/farmstead/tinman.rb
86
+ - lib/farmstead/version.rb
87
+ - scaffold/.dockerignore.erb
88
+ - scaffold/.env.erb
89
+ - scaffold/Dockerfile-dorothy.erb
90
+ - scaffold/Dockerfile.erb
91
+ - scaffold/Gemfile.erb
92
+ - scaffold/app/controllers/application_controller.rb.erb
93
+ - scaffold/docker-compose.yml.erb
94
+ - scaffold/exec.sh.erb
95
+ - scaffold/exec.sh.erb.old
96
+ - scaffold/supervisord.conf.erb
97
+ homepage:
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.6.11
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Farmstead is a modular data pipeline platform.
121
+ test_files: []