aide 0.1.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 913b87b1b83f1ddbfc8d738b14e80fa2f8c20cf4
4
- data.tar.gz: 2601657bfb9457f09d2fedfbfb3adb82956bad21
2
+ SHA256:
3
+ metadata.gz: 16ee63237abd5377a1cd568f5b2b02fa86a6a8b1e83a3afebc5cf785146b8071
4
+ data.tar.gz: 56f88a4269a3e36646bcf89a65c219403a506189924e39a3640eb784b445ebe3
5
5
  SHA512:
6
- metadata.gz: fd22e13b823f658d3dc8e795a2535e5e8f5b579736507ace32a1db6668d262a87eac6c23a30cd0aa3720019c37264c029aa01748a7a9ef1a22eecc7b014705d1
7
- data.tar.gz: f0dc8b980e0b17a68b8914975cec967bc8a0ed6d3ad12c6e20e525f752fc136407a1dc01e82425ce41e5bed74f2e383b86d27366d6043de0ccfad6482e9eca70
6
+ metadata.gz: b2f53cdf68945d364acbff07f40a75220698bbf2cfdab469b21911588fc3ada2ec894fc9fc828ee1ca583bc7d8bf7a3245f0a0ea6b1eb251016e16e159ec9ba8
7
+ data.tar.gz: c5841984bd8895c7a6a255008744315ba2eda0d48e0a508014559b0426f33c4ab32b3e0fd7a3700a057f866db609ab16768327eeab211df1afd708abae576ea9
data/Deskfile ADDED
@@ -0,0 +1,15 @@
1
+ rspec() {
2
+ dev run --rm aide rspec "$@"
3
+ }
4
+
5
+ rake() {
6
+ dev run --rm aide rake "$@"
7
+ }
8
+
9
+ bundle() {
10
+ dev run --rm aide bundle "$@"
11
+ }
12
+
13
+ release_gem() {
14
+ dev run --rm release_gem
15
+ }
data/Dockerfile ADDED
@@ -0,0 +1,21 @@
1
+ FROM 786715713882.dkr.ecr.us-east-1.amazonaws.com/fixuid as fixuid
2
+
3
+ FROM 786715713882.dkr.ecr.us-east-1.amazonaws.com/ruby-test:3.1.2
4
+ LABEL maintainer="Ryan Schlesinger <ryan@outstand.com>"
5
+
6
+ COPY --from=fixuid /usr/local/bin/fixuid /usr/local/bin/fixuid
7
+ COPY --from=fixuid /etc/fixuid/config.yml /etc/fixuid/config.yml
8
+ RUN chmod 4755 /usr/local/bin/fixuid
9
+
10
+ RUN groupadd -g 1000 deploy && \
11
+ useradd -u 1000 -g deploy -ms /bin/bash deploy
12
+
13
+ COPY --chown=deploy:deploy docker/irbrc /home/deploy/.irbrc
14
+
15
+ COPY docker/tools-entrypoint.sh /tools-entrypoint.sh
16
+ COPY docker/entrypoint.sh /docker-entrypoint.sh
17
+
18
+ EXPOSE 3000
19
+ EXPOSE 7787
20
+ ENTRYPOINT ["/sbin/tini", "-g", "--", "/docker-entrypoint.sh"]
21
+ CMD ["rails", "server", "-b", "0.0.0.0"]
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in aide.gemspec
4
4
  gemspec
5
+
6
+ gem "standard", group: [:development, :test]
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Aide
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aide`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Glue between consul and your rails app.
6
4
 
7
5
  ## Installation
8
6
 
@@ -20,17 +18,14 @@ Or install it yourself as:
20
18
 
21
19
  $ gem install aide
22
20
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
21
  ## Development
28
22
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- 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).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aide.
23
+ - `desk go`
24
+ - `dev build --pull aide`
25
+ - `rspec specs` to run specs
26
+ - Set the application path in the volumes section in `compose.yml`.
36
27
 
28
+ To release a new version:
29
+ - Update the version number in `version.rb` and commit the result.
30
+ - `dev build --pull aide`
31
+ - `release_gem`
data/aide.gemspec CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.10"
22
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "bundler", "~> 2.3"
22
+ spec.add_development_dependency "rake", "~> 13"
23
23
 
24
24
  spec.add_runtime_dependency 'diplomat'
25
25
  end
data/compose.yml ADDED
@@ -0,0 +1,35 @@
1
+ services:
2
+ aide:
3
+ build:
4
+ context: .
5
+ image: outstand/aide:dev
6
+ working_dir: ${WORKSPACE_DIR}
7
+ volumes:
8
+ - bundler-data:/usr/local/bundle
9
+ - .:${WORKSPACE_DIR}
10
+ ports:
11
+ - "3000"
12
+ environment:
13
+ FIXUID:
14
+ FIXGID:
15
+ WORKSPACE_DIR:
16
+
17
+ release_gem:
18
+ image: outstand/aide:dev
19
+ command: rake release
20
+ working_dir: ${WORKSPACE_DIR}
21
+ environment:
22
+ FIXUID:
23
+ FIXGID:
24
+ WORKSPACE_DIR:
25
+ volumes:
26
+ - bundler-data:/usr/local/bundle
27
+ - .:${WORKSPACE_DIR}
28
+ - ~/.dotfiles/config/git/gitconfig:/home/deploy/.gitconfig
29
+ - ~/.dotfiles/config/git/gitconfig.user:/home/deploy/.gitconfig.user
30
+ - ~/.config/gh/hosts.yml:/home/deploy/.config/gh/hosts.yml
31
+ - ~/.local/share/gem/credentials:/home/deploy/.local/share/gem/credentials
32
+ - ~/.local/share/gem/credentials:/home/deploy/.gem/credentials
33
+
34
+ volumes:
35
+ bundler-data:
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env bash
2
+
3
+ chown_dir() {
4
+ dir=$1
5
+ if [[ -d "${dir}" ]] && [[ "$(stat -c %u:%g "${dir}")" != "${FIXUID}:${FIXGID}" ]]; then
6
+ echo chown "$dir"
7
+ chown deploy:deploy "$dir"
8
+ fi
9
+ }
10
+
11
+ chown_r_dir() {
12
+ dir=$1
13
+ if [[ -d "${dir}" ]] && [[ "$(stat -c %u:%g "${dir}")" != "${FIXUID}:${FIXGID}" ]]; then
14
+ echo chown -R "$dir"
15
+ chown -R deploy:deploy "$dir"
16
+ fi
17
+ }
18
+
19
+ ensure_dir() {
20
+ dir=$1
21
+ mkdir -p "$dir"
22
+
23
+ chown_dir "$dir"
24
+ }
25
+
26
+ chown_r_dir "${WORKSPACE_DIR}"
27
+
28
+ chown_dir /usr/local/bundle
29
+ ensure_dir /home/deploy/.config/irb
@@ -0,0 +1,33 @@
1
+ #!/bin/bash
2
+
3
+ set -euo pipefail
4
+
5
+ su-exec "${FIXUID:?Missing FIXUID var}:${FIXGID:?Missing FIXGID var}" fixuid
6
+
7
+ "${WORKSPACE_DIR}/docker/chown-dirs.sh"
8
+ set +e
9
+ su-exec deploy touch /home/deploy/.config/irb/irb_history
10
+ su-exec deploy ln -s /home/deploy/.config/irb/irb_history /home/deploy/.irb_history
11
+ set -e
12
+
13
+ install_tls_certs() {
14
+ if [ -n "$(ls -A /usr/local/share/ca-certificates)" ]; then
15
+ echo "Updating ca-certificates"
16
+ update-ca-certificates
17
+ fi
18
+ }
19
+ install_tls_certs
20
+
21
+ if [[ "$1" = 'bundle' ]] || [[ "$1" = 'yarn' ]]; then
22
+ set -- su-exec deploy "$@"
23
+ exec "$@"
24
+ elif [ "$1" = 'rake' ] && [ "$2" = 'release' ]; then
25
+ set -- su-exec deploy "$@"
26
+ exec "$@"
27
+ fi
28
+
29
+ set -- su-exec deploy bundle exec "$@"
30
+
31
+ rm -f "${WORKSPACE_DIR}/tmp/pids/server.pid"
32
+
33
+ exec "$@"
data/docker/irbrc ADDED
@@ -0,0 +1,9 @@
1
+ IRB.conf[:SAVE_HISTORY] = 1000
2
+ IRB.conf[:USE_AUTOCOMPLETE] = false
3
+
4
+ if Reline
5
+ Reline.dialog_default_bg_color = :black
6
+ Reline.dialog_default_fg_color = :red
7
+ Reline.dialog_highlight_bg_color = :blue
8
+ Reline.dialog_highlight_fg_color = :white
9
+ end
@@ -0,0 +1,33 @@
1
+ #!/bin/bash
2
+
3
+ set -euo pipefail
4
+
5
+ su-exec "${FIXUID:?Missing FIXUID var}:${FIXGID:?Missing FIXGID var}" fixuid > /dev/null 2>&1
6
+
7
+ "${WORKSPACE_DIR}/docker/chown-dirs.sh" > /dev/null
8
+
9
+ chown_r_dir() {
10
+ dir="$1"
11
+ if [[ -d "${dir}" ]] && [[ "$(stat -c %u:%g "${dir}")" != "${FIXUID}:${FIXGID}" ]]; then
12
+ echo chown -R "$dir"
13
+ chown -R deploy:deploy "$dir"
14
+ fi
15
+ }
16
+
17
+ ensure_dir() {
18
+ dir=$1
19
+ mkdir -p "$dir"
20
+
21
+ chown_r_dir "$dir"
22
+ }
23
+
24
+ ensure_dir /home/deploy/.solargraph/cache > /dev/null
25
+
26
+ if [ "${1:-}" = "bash" ]; then
27
+ exec "$@"
28
+ elif [ "${1:-}" = "exit" ]; then
29
+ exit 0
30
+ fi
31
+
32
+ set -- su-exec deploy "$@"
33
+ exec "$@"
data/lib/aide/config.rb CHANGED
@@ -25,10 +25,23 @@ module Aide
25
25
  self.service_address_method = SERVICE_ADDRESS_METHOD
26
26
  end
27
27
 
28
- def add_service(name:, url:nil, auth:nil, user_key:nil, password_key:nil, protocol_key:nil, multi_url:nil, node:nil, database_key:nil, allow_missing:false)
28
+ def add_service(
29
+ name:,
30
+ url: nil,
31
+ url_env_key: nil,
32
+ auth: nil,
33
+ user_key: nil,
34
+ password_key: nil,
35
+ protocol_key: nil,
36
+ multi_url: nil,
37
+ node: nil,
38
+ database_key: nil,
39
+ allow_missing: false
40
+ )
29
41
  services[name] = {
30
42
  name: name,
31
43
  url: url,
44
+ url_env_key: url_env_key,
32
45
  multi_url: multi_url,
33
46
  auth: auth,
34
47
  user_key: user_key,
data/lib/aide/service.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'uri'
2
+
1
3
  module Aide
2
4
  class Service
3
5
  attr_accessor :name
@@ -15,7 +17,13 @@ module Aide
15
17
  alias port ServicePort
16
18
 
17
19
  def url(filtered: false)
18
- template = config[:url]
20
+ template =
21
+ if !config[:url_env_key].nil?
22
+ ENV[config[:url_env_key]]
23
+ else
24
+ config[:url]
25
+ end
26
+
19
27
  return if template.nil?
20
28
 
21
29
  return if empty? && !config[:allow_missing]
@@ -55,7 +63,7 @@ module Aide
55
63
  end
56
64
 
57
65
  def multi_url!
58
- self.multi_url.tap do |orig_url|
66
+ multi_url.tap do |orig_url|
59
67
  raise MissingService.new(name) if orig_url.nil?
60
68
  end
61
69
  end
@@ -68,6 +76,12 @@ module Aide
68
76
  end
69
77
  end
70
78
 
79
+ def host
80
+ return address if url.nil?
81
+
82
+ URI.parse(url).host
83
+ end
84
+
71
85
  def auth(filtered: false)
72
86
  template = config[:auth]
73
87
 
@@ -113,7 +127,7 @@ module Aide
113
127
  end
114
128
 
115
129
  def node!
116
- self.node.tap do |orig_node|
130
+ node.tap do |orig_node|
117
131
  raise MissingService.new(name) if orig_node.nil?
118
132
  end
119
133
  end
@@ -124,12 +138,14 @@ module Aide
124
138
 
125
139
  def user
126
140
  return if user_key.nil?
141
+ return @user if defined?(@user)
127
142
 
128
- @user ||= begin
129
- user = Diplomat::Kv.get(user_key, {}, :return)
130
- user = nil if user == ""
131
- user
132
- end
143
+ @user =
144
+ begin
145
+ user = Diplomat::Kv.get(user_key, {}, :return)
146
+ user = nil if user == ""
147
+ user
148
+ end
133
149
  end
134
150
 
135
151
  def password_key
@@ -138,12 +154,14 @@ module Aide
138
154
 
139
155
  def password
140
156
  return if password_key.nil?
157
+ return @password if defined?(@password)
141
158
 
142
- @password ||= begin
143
- password = Diplomat::Kv.get(password_key, {}, :return)
144
- password = nil if password == ""
145
- password
146
- end
159
+ @password =
160
+ begin
161
+ password = Diplomat::Kv.get(password_key, {}, :return)
162
+ password = nil if password == ""
163
+ password
164
+ end
147
165
  end
148
166
 
149
167
  def protocol_key
@@ -152,12 +170,14 @@ module Aide
152
170
 
153
171
  def protocol
154
172
  return if protocol_key.nil?
173
+ return @protocol if defined?(@protocol)
155
174
 
156
- @protocol ||= begin
157
- protocol = Diplomat::Kv.get(protocol_key, {}, :return)
158
- protocol = nil if protocol == ""
159
- protocol
160
- end
175
+ @protocol =
176
+ begin
177
+ protocol = Diplomat::Kv.get(protocol_key, {}, :return)
178
+ protocol = nil if protocol == ""
179
+ protocol
180
+ end
161
181
  end
162
182
 
163
183
  def database_key
@@ -166,12 +186,14 @@ module Aide
166
186
 
167
187
  def database
168
188
  return if database_key.nil?
189
+ return @database if defined?(@database)
169
190
 
170
- @database ||= begin
171
- database = Diplomat::Kv.get(database_key, {}, :return)
172
- database = nil if database == ""
173
- database
174
- end
191
+ @database =
192
+ begin
193
+ database = Diplomat::Kv.get(database_key, {}, :return)
194
+ database = nil if database == ""
195
+ database
196
+ end
175
197
  end
176
198
 
177
199
  def empty?
@@ -179,16 +201,23 @@ module Aide
179
201
  end
180
202
 
181
203
  private
204
+
182
205
  def service
183
- @service ||= Diplomat::Service.get(name)
206
+ return @service if defined?(@service)
207
+
208
+ @service = Diplomat::Service.get(name)
184
209
  end
185
210
 
186
211
  def services
187
- @services || Diplomat::Service.get(name, :all)
212
+ return @services if defined?(@services)
213
+
214
+ @services = Diplomat::Service.get(name, :all)
188
215
  end
189
216
 
190
217
  def config
191
- @config ||= Aide.config.get_service(name: name)
218
+ return @config if defined?(@config)
219
+
220
+ @config = Aide.config.get_service(name: name)
192
221
  end
193
222
  end
194
223
  end
data/lib/aide/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Aide
2
- VERSION = '0.1.6'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/aide.rb CHANGED
@@ -11,7 +11,7 @@ module Aide
11
11
  attr_writer :services
12
12
 
13
13
  def service(name)
14
- self.services[name] ||= Aide::Service.new(name: name)
14
+ services[name] ||= Aide::Service.new(name: name)
15
15
  end
16
16
 
17
17
  def config
@@ -19,23 +19,32 @@ module Aide
19
19
  end
20
20
 
21
21
  def configure(&block)
22
- self.config.instance_eval(&block)
22
+ config.instance_eval(&block)
23
+ load_services
23
24
  end
24
25
 
25
26
  def display_services
26
- load_services
27
-
28
27
  puts "Aide Services (Using #{config.service_address_key}):"
29
- self.services.each do |name, service|
30
- puts "==> #{name}: #{service.address}#{service.port.nil? ? '' : ":#{service.port}"} #{service.display_url(filtered: true)}".strip
28
+
29
+ services.each do |name, service|
30
+ puts "==> #{name}: #{formatted_service(service: service)}"
31
31
  end
32
32
  end
33
33
 
34
34
  private
35
+
35
36
  def load_services
36
- self.config.services.keys.each do |name|
37
+ config.services.each_key do |name|
37
38
  service(name)
38
39
  end
39
40
  end
41
+
42
+ def service_port(service:)
43
+ service.port.nil? ? '' : ":#{service.port}"
44
+ end
45
+
46
+ def formatted_service(service:)
47
+ "#{service.address}#{service_port(service: service)} #{service.display_url(filtered: true)}".strip
48
+ end
40
49
  end
41
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aide
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Schlesinger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-24 00:00:00.000000000 Z
11
+ date: 2022-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '2.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '2.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: diplomat
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -60,12 +60,19 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
+ - Deskfile
64
+ - Dockerfile
63
65
  - Gemfile
64
66
  - README.md
65
67
  - Rakefile
66
68
  - aide.gemspec
67
69
  - bin/console
68
70
  - bin/setup
71
+ - compose.yml
72
+ - docker/chown-dirs.sh
73
+ - docker/entrypoint.sh
74
+ - docker/irbrc
75
+ - docker/tools-entrypoint.sh
69
76
  - lib/aide.rb
70
77
  - lib/aide/config.rb
71
78
  - lib/aide/error.rb
@@ -89,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
96
  - !ruby/object:Gem::Version
90
97
  version: '0'
91
98
  requirements: []
92
- rubyforge_project:
93
- rubygems_version: 2.5.1
99
+ rubygems_version: 3.3.7
94
100
  signing_key:
95
101
  specification_version: 4
96
102
  summary: A configuration helper for Diplomat