Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHA to deploy CLAW [master] #82

Merged
merged 18 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/deploy-claw.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
name: "Test: Ruby"

on:
workflow_dispatch:
push:
branches: [ "master" ]
pull_request:
Expand All @@ -20,9 +21,6 @@ jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6']

steps:
- uses: actions/checkout@v3
Expand All @@ -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
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
ruby '~>2.6'
ruby '~>3.2'

source 'http://rubygems.org'

Expand Down
31 changes: 18 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -40,7 +45,7 @@ DEPENDENCIES
unicorn

RUBY VERSION
ruby 2.6.8p205
ruby 3.2.0p0

BUNDLED WITH
2.1.4
2.4.1
27 changes: 0 additions & 27 deletions claw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions claw_test.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
5 changes: 1 addition & 4 deletions manifest-oss-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-----

Expand Down
7 changes: 2 additions & 5 deletions manifest-oss.yml
Original file line number Diff line number Diff line change
@@ -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-----

Expand Down
Loading