diff --git a/.github/workflows/deploy-claw.yml b/.github/workflows/deploy-claw.yml new file mode 100644 index 0000000..bcdfd83 --- /dev/null +++ b/.github/workflows/deploy-claw.yml @@ -0,0 +1,47 @@ +name: "Deploy CLAW" + +on: + push: + branches: + - 'master' + workflow_dispatch: +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout CLAW + uses: actions/checkout@v4 + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Run Tests + run: bundle exec rake test + + deploy: + runs-on: ubuntu-latest + needs: [test] + steps: + - name: Checkout CLAW + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + # Install CLI + # ...first add the Cloud Foundry Foundation public key and package repository to your system + wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add - + echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list + + # ...then, update your local package index, then finally install the cf CLI + sudo apt-get update + sudo apt-get install cf8-cli + + - name: Push CLAW + run: | + cf api ${{ secrets.FOUNDATION_URL }} + export CF_USERNAME=${{ secrets.FOUNDATION_USERNAME }} + export CF_PASSWORD=${{ secrets.FOUNDATION_PASSWORD }} + + cf auth + cf target -o ${{ secrets.APP_ORG }} -s ${{ secrets.APP_SPACE }} + cf push --manifest manifest-oss.yml --vars-file claw-variables.yml --strategy rolling \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f5d328d..0d280e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,6 +8,7 @@ name: "Test: Ruby" on: + workflow_dispatch: push: branches: [ "master" ] pull_request: @@ -20,9 +21,6 @@ jobs: test: runs-on: ubuntu-latest - strategy: - matrix: - ruby-version: ['2.6'] steps: - uses: actions/checkout@v3 @@ -32,7 +30,7 @@ jobs: # uses: ruby/setup-ruby@v1 uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 with: - ruby-version: ${{ matrix.ruby-version }} + ruby-version: 3.2 bundler-cache: true # runs 'bundle install' and caches installed gems automatically - name: Run tests run: bundle exec rake test diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..4fe5631 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.2 \ No newline at end of file diff --git a/Gemfile b/Gemfile index 7197586..fd638c2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ # frozen_string_literal: true -ruby '~>2.6' +ruby '~>3.2' source 'http://rubygems.org' diff --git a/Gemfile.lock b/Gemfile.lock index cc28e47..656d44e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,28 +1,33 @@ GEM remote: http://rubygems.org/ specs: + base64 (0.2.0) gabba (1.0.1) kgio (2.11.4) mustermann (3.0.0) ruby2_keywords (~> 0.0.1) power_assert (2.0.3) - rack (2.2.8.1) - rack-protection (3.0.6) - rack - rack-test (1.1.0) - rack (>= 1.0, < 3) + rack (3.0.10) + rack-protection (4.0.0) + base64 (>= 0.1.0) + rack (>= 3.0.0, < 4) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) raindrops (0.20.1) - rake (13.0.6) + rake (13.2.1) ruby2_keywords (0.0.5) semantic (1.6.1) - sinatra (3.0.6) + sinatra (4.0.0) mustermann (~> 3.0) - rack (~> 2.2, >= 2.2.4) - rack-protection (= 3.0.6) + rack (>= 3.0.0, < 4) + rack-protection (= 4.0.0) + rack-session (>= 2.0.0, < 3) tilt (~> 2.0) - test-unit (3.6.0) + test-unit (3.6.2) power_assert - tilt (2.2.0) + tilt (2.3.0) unicorn (6.1.0) kgio (~> 2.6) raindrops (~> 0.7) @@ -40,7 +45,7 @@ DEPENDENCIES unicorn RUBY VERSION - ruby 2.6.8p205 + ruby 3.2.0p0 BUNDLED WITH - 2.1.4 + 2.4.1 diff --git a/claw.rb b/claw.rb index 71a1b20..2c24db0 100644 --- a/claw.rb +++ b/claw.rb @@ -69,11 +69,6 @@ RPM_REPO = 'https://cf-cli-dev.s3.amazonaws.com/cf-cli-rpm-repo' end -unless ENV.key?('GA_TRACKING_ID') && ENV.key?('GA_DOMAIN') - puts 'Expected a Google Analytics env vars but they were not set' - exit 1 -end - unless ENV.key?('GPG_KEY') puts 'Expected a GPG_KEY env var but it was not set' exit 1 @@ -95,17 +90,6 @@ end class Claw < Sinatra::Base - before do - @google_analytics = Gabba::Gabba.new(ENV['GA_TRACKING_ID'], ENV['GA_DOMAIN'], request.user_agent) - accept_language = request.env['HTTP_ACCEPT_LANGUAGE'] - @google_analytics.utmul = accept_language if accept_language - - @google_analytics.set_custom_var(1, 'ip', request.ip, 3) - @google_analytics.set_custom_var(2, 'source', params['source'], 3) - @google_analytics.set_custom_var(3, 'referer', request.referer, 3) - @google_analytics.set_custom_var(4, 'host', request.host, 3) - end - get '/ping' do 'pong' end @@ -117,48 +101,38 @@ class Claw < Sinatra::Base get '/edge' do redirect_link = get_edge_redirect_link(params['version'], params['arch']) - @google_analytics.page_view('edge', "edge/#{params['arch']}") redirect redirect_link, 302 end get '/stable' do redirect_url = get_stable_redirect_link(params['version'], params['release']) - @google_analytics.page_view('stable', "stable/#{params['release']}/#{params['version']}") redirect redirect_url, 302 end get '/homebrew' do - @google_analytics.set_custom_var(2, 'source', 'homebrew', 3) - unless AVAILABLE_VERSIONS.include?(params['version']) halt 412, "Invalid version, please select one of the following versions: #{AVAILABLE_VERSIONS.join(', ')}" end - @google_analytics.page_view('stable', "stable/#{params['arch']}-binary/#{params['version']}") - redirect get_versioned_release_link(params['version'], release_to_filename("#{params['arch']}-binary", params['version'])), 302 end get '/debian/dists/*' do page = File.join('dists', params['splat'].first) - @google_analytics.page_view('debian', page) redirect File.join(APT_REPO, page), 302 end get '/fedora/cloudfoundry-cli.repo' do - @google_analytics.page_view('fedora', 'cloudfoundry-cli.repo') redirect File.join(RPM_REPO, 'cloudfoundry-cli.repo'), 302 end get '/fedora/repodata/*' do page = File.join('repodata', params['splat'].first) - @google_analytics.page_view('fedora', page) redirect File.join(RPM_REPO, page), 302 end get '/debian/pool/*' do page = File.join('pool', params['splat'].first) - @google_analytics.page_view('debian', page) filename = page.split('/').last version = get_version_from_filename(filename) @@ -172,7 +146,6 @@ class Claw < Sinatra::Base get '/fedora/releases/*' do page = File.join('releases', params['splat'].first) - @google_analytics.page_view('fedora', page) filename = page.split('/').last version = get_version_from_filename(filename) diff --git a/claw_test.rb b/claw_test.rb index 85895d1..c6affad 100644 --- a/claw_test.rb +++ b/claw_test.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true ENV['RACK_ENV'] = 'test' -ENV['GA_TRACKING_ID'] = 'dummy_id' -ENV['GA_DOMAIN'] = 'dummy.domain.example.com' ENV['GPG_KEY'] = 'dummy-key' ENV['AVAILABLE_VERSIONS'] = '["6.12.4", "6.13.0", "7.0.0-beta.24", "8.0.0", "8.0.1"]' ENV['CURRENT_MAJOR_VERSION'] = 'v7' diff --git a/manifest-oss-dev.yml b/manifest-oss-dev.yml index 88b37ed..217086c 100644 --- a/manifest-oss-dev.yml +++ b/manifest-oss-dev.yml @@ -3,13 +3,10 @@ applications: - name: claw-dev buildpack: ruby_buildpack instances: 2 - stack: cflinuxfs3 env: AVAILABLE_VERSIONS: ((AVAILABLE_VERSIONS)) - CURRENT_MAJOR_VERSION: v7 + CURRENT_MAJOR_VERSION: v8 ENVIRONMENT: dev - GA_DOMAIN: pivotal.io - GA_TRACKING_ID: UA-52116311-1 GPG_KEY: | -----BEGIN PGP PUBLIC KEY BLOCK----- diff --git a/manifest-oss.yml b/manifest-oss.yml index 6ff3f13..a8639b7 100644 --- a/manifest-oss.yml +++ b/manifest-oss.yml @@ -1,15 +1,12 @@ --- applications: -- name: claw +- name: claw-test buildpack: ruby_buildpack instances: 2 - stack: cflinuxfs3 env: AVAILABLE_VERSIONS: ((AVAILABLE_VERSIONS)) - CURRENT_MAJOR_VERSION: v6 + CURRENT_MAJOR_VERSION: v8 ENVIRONMENT: prod - GA_DOMAIN: pivotal.io - GA_TRACKING_ID: UA-52116311-1 GPG_KEY: | -----BEGIN PGP PUBLIC KEY BLOCK-----