From e2dbe409f7152fc004064f458dfdcba2ecc00326 Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Tue, 5 May 2020 12:26:04 -0500 Subject: [PATCH] fix: migrate to common prism setup --- .gitignore | 2 ++ .travis.yml | 31 ++++++++------------- Dockerfile | 14 ++++++++++ Makefile | 8 +++++- test/prism.sh | 42 ----------------------------- test/sendgrid/test_sendgrid-ruby.rb | 28 +------------------ 6 files changed, 35 insertions(+), 90 deletions(-) create mode 100644 Dockerfile delete mode 100755 test/prism.sh diff --git a/.gitignore b/.gitignore index baf1b426..ca57f89c 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ Gemfile.lock # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc + +prism diff --git a/.travis.yml b/.travis.yml index 51e6f0a5..16f544fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,17 @@ language: ruby -rvm: - - ruby-head - - 2.7 - - 2.6 - - 2.5 - - 2.4 - - jruby-9.2 +env: + - version=ruby:2.7 + - version=ruby:2.6 + - version=ruby:2.5 + - version=ruby:2.4 + - version=jruby:9.2 + gemfile: - gemfiles/Sinatra_1.gemfile - gemfiles/Sinatra_2.gemfile -before_script: - - mkdir prism - - mkdir prism/bin - - export PATH=$PATH:$PWD/prism/bin/ - - "./test/prism.sh" -install: make install -script: make test -matrix: - allow_failures: - - rvm: ruby-head - fast_finish: true + +script: make test-docker + deploy: provider: rubygems api_key: @@ -27,8 +19,7 @@ deploy: gem: sendgrid-ruby on: tags: true - rvm: '2.4' - condition: '$BUNDLE_GEMFILE == *"gemfiles/Sinatra_1.gemfile"' + condition: $version=ruby:2.4 AND '$BUNDLE_GEMFILE == *"gemfiles/Sinatra_1.gemfile"' notifications: slack: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..fbf713b1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +ARG version=ruby:latest +FROM $version + +# Needed for jruby +RUN apt-get update \ + && apt-get install -y make git + +COPY prism/prism/nginx/cert.crt /usr/local/share/ca-certificates/cert.crt +RUN update-ca-certificates + +WORKDIR /app +COPY . . + +RUN make install diff --git a/Makefile b/Makefile index 202ee13f..ee9cec77 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,13 @@ -.PHONY: install test +.PHONY: install test test-integ test-docker install: gem install bundler:2.1.2; bundle install test: bundle exec rake spec + +test-integ: test + +version ?= ruby:latest +test-docker: + curl -s https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/prism/prism.sh | version=$(version) bash diff --git a/test/prism.sh b/test/prism.sh deleted file mode 100755 index 57fc467e..00000000 --- a/test/prism.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -install () { - -set -eu - -UNAME=$(uname) -ARCH=$(uname -m) -if [ "$UNAME" != "Linux" ] && [ "$UNAME" != "Darwin" ] && [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "i686" ]; then - echo "Sorry, OS/Architecture not supported: ${UNAME}/${ARCH}. Download binary from https://github.com/stoplightio/prism/releases" - exit 1 -fi - -if [ "$UNAME" = "Darwin" ] ; then - OSX_ARCH=$(uname -m) - if [ "${OSX_ARCH}" = "x86_64" ] ; then - PLATFORM="darwin_amd64" - fi -elif [ "$UNAME" = "Linux" ] ; then - LINUX_ARCH=$(uname -m) - if [ "${LINUX_ARCH}" = "i686" ] ; then - PLATFORM="linux_386" - elif [ "${LINUX_ARCH}" = "x86_64" ] ; then - PLATFORM="linux_amd64" - fi -fi - -#LATEST=$(curl -s https://api.github.com/repos/stoplightio/prism/tags | grep -Eo '"name":.*?[^\\]",' | head -n 1 | sed 's/[," ]//g' | cut -d ':' -f 2) -LATEST="v0.2.7" -URL="https://github.com/stoplightio/prism/releases/download/$LATEST/prism_$PLATFORM" -DEST=./prism/bin/prism - -if [ -z $LATEST ] ; then - echo "Error requesting. Download binary from ${URL}" - exit 1 -else - curl -L $URL -o $DEST - chmod +x $DEST -fi -} - -install diff --git a/test/sendgrid/test_sendgrid-ruby.rb b/test/sendgrid/test_sendgrid-ruby.rb index 02d4246e..986fd42d 100644 --- a/test/sendgrid/test_sendgrid-ruby.rb +++ b/test/sendgrid/test_sendgrid-ruby.rb @@ -5,34 +5,8 @@ class TestAPI < MiniTest::Test - unless File.exist?('/usr/local/bin/prism') || File.exist?(File.join(Dir.pwd, 'prism/bin/prism')) - if RUBY_PLATFORM =~ /mswin|mingw/ - puts 'Please download the Windows binary (https://github.com/stoplightio/prism/releases) and place it in your /usr/local/bin directory' - else - puts 'Installing Prism' - IO.popen(['curl', '-s', 'https://raw.githubusercontent.com/stoplightio/prism/master/install.sh']) do |io| - out = io.read - unless system(out) - puts "Error downloading the prism binary, you can try downloading directly here (https://github.com/stoplightio/prism/releases) and place in your /usr/local/bin directory, #{out}" - exit - end - end - end - end - - puts 'Activating Prism (~20 seconds)' - @@prism_pid = spawn('prism run --mock --list --spec https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json', [:out, :err] => '/dev/null') - sleep(15) - puts 'Prism started' - def setup - host = "http://localhost:4010" - @sg = SendGrid::API.new(api_key: "SENDGRID_API_KEY", host: host) - end - - Minitest.after_run do - Process.kill('TERM', @@prism_pid) - puts 'Prism shut down' + @sg = SendGrid::API.new(api_key: "SENDGRID_API_KEY") end def test_init