Skip to content

Commit

Permalink
Merge branch 'rest_client'
Browse files Browse the repository at this point in the history
  • Loading branch information
wr0ngway committed Jul 22, 2021
2 parents 5af1a09 + 602211c commit 5d0ad58
Show file tree
Hide file tree
Showing 52 changed files with 8,018 additions and 8,943 deletions.
2 changes: 1 addition & 1 deletion .app.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org: cloudtruth
name: kubetruth
version: 0.6.0
version: 1.0.0
10 changes: 4 additions & 6 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ jobs:
restore-keys: |
${{ runner.os }}-gems-
- name: Install Ruby version specified in `.ruby-version`
uses: eregon/use-ruby-action@master
- uses: satackey/action-docker-layer-caching@v0.0.11
continue-on-error: true

- run: gem install --no-document bundler
- run: bundle config path vendor/bundle
- run: bundle install --jobs 4 --retry 3
- run: bundle exec rspec
- name: Run the tests
run: rake test

deploy:
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ packaged-chart/
old-index.yaml
# rspec failure tracking
.rspec_status
client
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
1.0.0 (07/22/2021)
------------------

#### Notes on major changes

* \[breaking change] Updated to use the new Cloudtruth REST API

#### Full changelog

* exclude params with nil values from templates [65966f8](../../commit/65966f8)
* latest api schema [079657e](../../commit/079657e)
* fix NPE - values are nil if unset [4c5ac74](../../commit/4c5ac74)
* run console through docker [3ad434b](../../commit/3ad434b)
* Use correct default API host [63a54bc](../../commit/63a54bc)
* check for minikube for rake install [0098866](../../commit/0098866)
* convenience tasks [3b4fe55](../../commit/3b4fe55)
* latest api schema [b76eb58](../../commit/b76eb58)
* yield task in async helper [0b53d64](../../commit/0b53d64)
* use logger for async exceptions [5cf8639](../../commit/5cf8639)
* allow overriding of image name when building docker image [60dd50a](../../commit/60dd50a)
* allow setting ct api url at install time [8561036](../../commit/8561036)
* add tests to validate concurrency for http calls. Use faradat instead of typhoeus in generated client lib to get concurrency for ctapi [d194ac6](../../commit/d194ac6)
* explicit async wait at top level to future proof if sibling asyncs are added [d1d3992](../../commit/d1d3992)
* ignore coverage for generated client lib [2d540c0](../../commit/2d540c0)
* initial conversion to use cloudtruth rest api [22b3584](../../commit/22b3584)
* complete test coverage [366e919](../../commit/366e919)

0.6.0 (07/07/2021)
------------------

Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ RUN apk add --no-cache \
--virtual build_deps \
$BUILD_PACKAGES

COPY client $APP_DIR/client
COPY Gemfile* $APP_DIR/
RUN bundle config --local without 'development test' && \
bundle install --jobs=4
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ gem 'gem_logger'
gem 'logging'
gem 'activesupport'
gem 'clamp'
gem 'graphql-client'
gem 'cloudtruth-client', path: "client"
gem 'kubeclient'
gem 'liquid'
gem 'yaml-safe_load_stream', git: "https://github.com/wr0ngway/yaml-safe_load_stream.git", branch: "ruby_3"
Expand Down
31 changes: 26 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ GIT
specs:
yaml-safe_load_stream (0.1.2)

PATH
remote: client
specs:
cloudtruth-client (1.0.0)
faraday (~> 1.0, >= 1.0.1)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -34,17 +40,30 @@ GEM
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
faraday (1.5.1)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0.1)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
faraday-patron (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
ffi (1.15.3)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
fiber-local (1.0.0)
gem_logger (0.3.0)
activesupport
graphql (1.12.13)
graphql-client (0.16.0)
activesupport (>= 3.0)
graphql (~> 1.8)
hashdiff (1.0.1)
http (4.4.1)
addressable (~> 2.3)
Expand Down Expand Up @@ -77,6 +96,7 @@ GEM
mime-types-data (3.2021.0704)
minitest (5.14.4)
multi_json (1.15.0)
multipart-post (2.1.1)
netrc (0.11.0)
nio4r (2.5.7)
pry (0.14.1)
Expand Down Expand Up @@ -107,6 +127,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
ruby2_keywords (0.0.4)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand All @@ -133,9 +154,9 @@ DEPENDENCIES
activesupport
async
clamp
cloudtruth-client!
codecov
gem_logger
graphql-client
kubeclient
liquid
logging
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,29 @@ interactive prompt that will allow you to experiment.
To install and run via helm in a local cluster:
```
mkdir local
cat > local/values.yml <<-EOF
image:
repository: kubetruth
pullPolicy: Never
tag: latest
appSettings:
debug: true
apiKey: <your_api_key>
EOF

# requires minikube to be installed and running
rake install

# OR

# If using minikube, ensure that docker builds the image into the minikube container
# with the command:
# eval $(minikube docker-env)
#
docker build --release development -t kubetruth . && helm install \
--set image.repository=kubetruth --set image.pullPolicy=Never --set image.tag=latest \
--set appSettings.debug=true --set appSettings.apiKey=$CLOUDTRUTH_API_KEY --set appSettings.environment=development \
--set appSettings.debug=true --set appSettings.apiKey=$CLOUDTRUTH_API_KEY \
kubetruth ./helm/kubetruth/
```
Expand Down
115 changes: 94 additions & 21 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
require 'yaml'
require 'open-uri'

ROOT_DIR = File.expand_path(__dir__)
APP = YAML.load(File.read("#{ROOT_DIR}/.app.yml"), filename: "#{ROOT_DIR}/.app.yml", symbolize_names: true)
TMP_DIR = "#{ROOT_DIR}/tmp"
APP = YAML.load(File.read(".app.yml"), symbolize_names: true)
TMP_DIR = "tmp"
HELMV2_DIR = "#{TMP_DIR}/helmv2"
HELM_PKG_DIR = "#{TMP_DIR}/packaged-chart"
CLIENT_DIR = "client"

require 'rake/clean'
CLEAN << TMP_DIR
CLEAN << TMP_DIR << CLIENT_DIR

def get_var(name, env_name: name.to_s.upcase, yml_name: name.to_s.downcase.to_sym, prompt: true, required: true)
def get_var(name, env_name: name.to_s.upcase, yml_name: name.to_s.downcase.to_sym, default: nil, prompt: true, required: true)
value = ENV[env_name]
value ||= APP[yml_name]
value ||= default

if value.nil? && $stdin.tty? && prompt
print "Enter '#{name}': "
Expand Down Expand Up @@ -41,8 +42,8 @@ end
directory HELMV2_DIR

file "#{HELMV2_DIR}/#{APP[:name]}/Chart.yaml" => [HELMV2_DIR] do
cp_r "#{ROOT_DIR}/helm/#{APP[:name]}", HELMV2_DIR, preserve: true
cp_r "#{ROOT_DIR}/helm/helmv2/.", "#{HELMV2_DIR}/#{APP[:name]}/", preserve: true
cp_r "helm/#{APP[:name]}", HELMV2_DIR, preserve: true
cp_r "helm/helmv2/.", "#{HELMV2_DIR}/#{APP[:name]}/", preserve: true
chart = File.read("#{HELMV2_DIR}/#{APP[:name]}/Chart.yaml")
chart = chart.gsub(/apiVersion: v2/, "apiVersion: v1")
chart = chart.gsub(/version: ([0-9.]*)/, 'version: \1-helmv2')
Expand All @@ -53,7 +54,7 @@ task :generate_helmv2 => ["#{HELMV2_DIR}/#{APP[:name]}/Chart.yaml"]

directory HELM_PKG_DIR

HELM_SRC_DIR = "#{ROOT_DIR}/helm/#{APP[:name]}"
HELM_SRC_DIR = "helm/#{APP[:name]}"
task :helm_build_package => [HELM_PKG_DIR] do
sh "helm package #{HELM_SRC_DIR}", chdir: HELM_PKG_DIR
end
Expand All @@ -80,12 +81,17 @@ end

task :helm_package => [:helm_index]

task :build_development do
sh "docker build --target development -t #{APP[:name]}-development ."
task :build_development => [:client] do
image_name = get_var(:image_name, default: "#{APP[:name]}", prompt: false, required: false)
sh "docker build --target development -t #{image_name}:latest -t #{image_name}:development ."
end

task :test => [:build_development] do
sh "docker run -e CI -e CODECOV_TOKEN #{APP[:name]}-development test"
if ENV['CI'] && ENV['CODECOV_TOKEN']
sh "set -e && ci_env=$(curl -s https://codecov.io/env | bash) && docker run -e CI -e CODECOV_TOKEN ${ci_env} #{APP[:name]} test"
else
sh "docker run -e CI -e CODECOV_TOKEN #{APP[:name]} test"
end
end

task :rspec do
Expand All @@ -94,8 +100,9 @@ task :rspec do
Rake::Task[:spec].invoke
end

task :build_release do
sh "docker build --target release -t #{APP[:name]} ."
task :build_release => [:client] do
image_name = get_var(:image_name, default: "#{APP[:name]}", prompt: false, required: false)
sh "docker build --target release -t #{image_name}:latest -t #{image_name}:release ."
end

task :docker_push do
Expand All @@ -111,11 +118,11 @@ end
task :set_version do
version = get_var('VERSION')

gsub_file("#{ROOT_DIR}/helm/#{APP[:name]}/Chart.yaml",
gsub_file("helm/#{APP[:name]}/Chart.yaml",
/^version:.*/, "version: #{version}")
gsub_file("#{ROOT_DIR}/helm/#{APP[:name]}/Chart.yaml",
gsub_file("helm/#{APP[:name]}/Chart.yaml",
/^appVersion:.*/, "appVersion: #{version}")
gsub_file("#{ROOT_DIR}/.app.yml",
gsub_file(".app.yml",
/version:.*/, "version: #{version}")
end

Expand Down Expand Up @@ -211,9 +218,75 @@ task :changelog do
end

task :console do
$LOAD_PATH.unshift File.expand_path("lib", __dir__)
require "bundler/setup"
require APP[:name]
require "pry"
Pry.start
local = get_var(:local, prompt: false, required: false, default: false)
if local
$LOAD_PATH.unshift File.expand_path("lib", __dir__)
require "bundler/setup"
require APP[:name]
require "pry"
Pry.start
else
Rake::Task["build_development"].invoke
sh "docker run -it kubetruth:development console"
end
end

file "#{CLIENT_DIR}/Gemfile" => "openapi.yml" do

if ENV['MINIKUBE_ACTIVE_DOCKERD']
puts "Cannot generate the rest client in the minikube docker environment"
puts "Run in a shell without 'eval $(minikube docker-env)'"
exit 1
end

rm_rf "client"
# may need --user #{Process.uid}:#{Process.gid} for some Hosts
sh *%W[
docker run --rm
-v #{Dir.pwd}:/data
openapitools/openapi-generator-cli generate
-i /data/openapi.yml
-g ruby
-o /data/client
--library faraday
--additional-properties=gemName=cloudtruth-client
]
end

task :client => "#{CLIENT_DIR}/Gemfile"

task :install do
build_type = get_var(:build_type, prompt: false, required: false, default: "development")
namespace = get_var(:namespace, prompt: false, required: false)
values_file = get_var(:values_file, prompt: false, required: false, default: "local/values.yaml")

system("minikube version", [:out, :err] => "/dev/null") || fail("dev dependency not installed - minikube")
system("minikube status", [:out, :err] => "/dev/null") || fail("dev dependency not running - minikube")

Rake::Task["client"].invoke

minikube_env = Hash[`minikube docker-env --shell bash`.scan(/([^ ]*)="(.*)"/)]
orig_env = ENV.to_hash
minikube_env.each {|k, v| ENV[k] = v }
begin
Rake::Task["build_#{build_type}"].invoke
ensure
(minikube_env.keys - orig_env.keys).each {|k| ENV.delete(k) }
(minikube_env.keys & orig_env.keys).each {|k, v| ENV[k] = orig_env[k] }
end

cmd = "helm install"
cmd << " --create-namespace --namespace #{namespace}" if namespace
cmd << " --values #{values_file}" if File.exist?(values_file)
cmd << " kubetruth helm/kubetruth/"
sh cmd
end

task :clean_install do
namespace = get_var(:namespace, prompt: false, required: false)
cmd = "helm delete"
cmd << " --namespace #{namespace}" if namespace
cmd << " kubetruth"
sh cmd
sh "kubectl delete customresourcedefinition projectmappings.kubetruth.cloudtruth.com"
end
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ case $action in

console)
echo "Starting console"
exec rake console
LOCAL=true exec rake console
;;

test)
Expand Down
4 changes: 2 additions & 2 deletions helm/kubetruth/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.6.0
version: 1.0.0


# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 0.6.0
appVersion: 1.0.0

4 changes: 4 additions & 0 deletions helm/kubetruth/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ spec:
name: {{ include "kubetruth.fullname" . }}
args:
- app
{{- if .Values.appSettings.apiUrl }}
- --api-url
- "{{ .Values.appSettings.apiUrl }}"
{{- end }}
{{- if .Values.appSettings.pollingInterval }}
- --polling-interval
- "{{ .Values.appSettings.pollingInterval }}"
Expand Down
1 change: 1 addition & 0 deletions helm/kubetruth/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ affinity: {}

appSettings:
apiKey:
apiUrl:
pollingInterval:
debug: false

Expand Down
Loading

0 comments on commit 5d0ad58

Please sign in to comment.