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

Use REDIS_SYSTEM_URL instead of REDIS_HOST and REDIS_PORT #1649

Open
wants to merge 86 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
bd42455
SRCH-5358: Add Capistrano Deployment.
luismetzger Jul 10, 2024
b758038
SRCH-5358: Update Capistrano script to deploy.
luismetzger Jul 12, 2024
3fe9f1d
Merge branch 'main' into SRCH-5358
luisgmetzger Jul 12, 2024
a678093
SRCH-5358: Linter and skip failing test.
luismetzger Jul 12, 2024
67595f1
latest updates to capistrano.
luismetzger Jul 17, 2024
8e337dd
SRCH-5358: Add comment.
luismetzger Jul 17, 2024
5d60f31
SRCH-5358: Update dpeloyment configurations.
luismetzger Jul 20, 2024
ea514f0
SRCH-5358: Update Gemfile.
luismetzger Jul 20, 2024
d41fd32
SRCH-5358: Update Capistrano configurations.
luismetzger Jul 20, 2024
5dd4052
SRCH-5358: Add explicit binding to puma config.
luismetzger Jul 22, 2024
940d12c
SRCH-5358: Remove explicit bind.
luismetzger Jul 22, 2024
adc3c45
SRCH-5358: Revert commit for binding on puma server.
luismetzger Jul 22, 2024
13ed044
Add missing puma plugin.
luismetzger Jul 22, 2024
3c831d8
SRCH-5358: Add config for puma.
luismetzger Jul 22, 2024
276e621
SRCH-5358: Update configs.
luismetzger Jul 23, 2024
84b8500
SRCH-5358: Add new rails script to capistrano.
luismetzger Jul 23, 2024
c9f954e
SRCH-5358: Fix spacing.
luismetzger Jul 23, 2024
214dda9
Update environment variable.
luismetzger Jul 24, 2024
48db190
Revert binding.
luismetzger Jul 24, 2024
1a4118f
Add bind and logs.
luismetzger Jul 24, 2024
a5546b2
Remove log files
luismetzger Jul 24, 2024
c3660b3
Update puma config file.
luismetzger Jul 25, 2024
b17eed2
SRCH-5358: Update deploy script.
luismetzger Jul 25, 2024
3ec9a31
Update ES configs.
luismetzger Jul 25, 2024
dac358f
SRCH-5358: Set SSL to false.
luismetzger Jul 29, 2024
288a630
Rever SSL force change for production.
luismetzger Jul 29, 2024
3262872
SRCH-5358: Add SSL config to bind in puma config.
luismetzger Jul 29, 2024
e8d8c10
Update port for SSL bind.
luismetzger Jul 29, 2024
0b9cd2c
Revert binding back.
luismetzger Jul 29, 2024
df3834b
Reset force ssl false.
luismetzger Jul 29, 2024
8b166b8
Setup branch as staging
stevenbarragan Jul 30, 2024
fe2637c
Enable assets compilation
stevenbarragan Jul 30, 2024
d8078ac
Hardcode SECRET_KEY_BASE for assets compilation
stevenbarragan Jul 31, 2024
4733249
Setup RAILS_SERVE_STATIC_FILES
stevenbarragan Jul 31, 2024
57cfd3b
Setup json logs for production
stevenbarragan Jul 31, 2024
3a2a32c
SRCH-5389 setup dotenv gem
stevenbarragan Aug 1, 2024
a004a4b
Use .env.production because .env is a directory already
stevenbarragan Aug 1, 2024
42f2040
Remove .env folder
stevenbarragan Aug 1, 2024
4e1fc8e
Set user=search and environment cleanup
stevenbarragan Aug 1, 2024
6bf5c60
Setup capistrano-resque
stevenbarragan Aug 7, 2024
882ceff
Fix resque worker
stevenbarragan Aug 7, 2024
fdaa85c
Setup workers
stevenbarragan Aug 7, 2024
2b14da5
Update resque worker to take an array of addresses
stevenbarragan Aug 8, 2024
ab3fcc5
Add .env to gitignore
stevenbarragan Aug 8, 2024
2ae79c6
Setup workers for all environments
stevenbarragan Aug 8, 2024
acb9513
Setup deployment to cron servers
stevenbarragan Aug 14, 2024
4fb7c4b
Automate the creation of .env EMPTY
stevenbarragan Aug 15, 2024
c9c101c
Setup cron task
stevenbarragan Aug 15, 2024
30da264
SRCH-5407 Setup cron tasks
stevenbarragan Aug 21, 2024
fb4d730
Merge branch 'main' into staging
stevenbarragan Aug 27, 2024
c9790ff
Remove .env directory
stevenbarragan Aug 28, 2024
0ba3460
SRCH-5479 Add /up route for health endpoint
stevenbarragan Aug 29, 2024
6fa51d4
Srch-5391 codepipeline (#1638)
sb-ebukaanene Aug 29, 2024
4409bd6
Refactor capistrano setup
stevenbarragan Sep 5, 2024
1a13078
Setup assets compilation on multiple servers
stevenbarragan Sep 5, 2024
7f0e7b3
Run migrations during deployment.
stevenbarragan Sep 6, 2024
e1095c3
Update buildspec_searchgov.yml (#1640)
sb-ebukaanene Sep 6, 2024
f60fad8
Remove extra configurations
stevenbarragan Sep 10, 2024
761348c
Setup puma logs
stevenbarragan Sep 10, 2024
853bad0
Fix rubocop offences
stevenbarragan Sep 10, 2024
98e64f1
Use the same environment variable acrosss apps
stevenbarragan Sep 10, 2024
d69156a
Refactor lib/es.rb
stevenbarragan Sep 10, 2024
3b63e95
Merge branch 'main' into staging
stevenbarragan Sep 10, 2024
8fd4499
Remove aws-sdk-ssm gem
stevenbarragan Sep 10, 2024
88c6173
Update buildspec_searchgov.yml (#1643)
sb-ebukaanene Sep 10, 2024
7ce3a85
Deploy branch from environment variable
stevenbarragan Sep 10, 2024
11e8902
Make sure number of resque workers is an integer
stevenbarragan Sep 11, 2024
7bfddf6
Use DB_USER instead of DB_USERNAME
stevenbarragan Sep 11, 2024
075e00a
Setup consider_all_requests_local for staging
stevenbarragan Sep 11, 2024
f25e18c
Capfile comments cleanup
stevenbarragan Sep 11, 2024
2b8a588
Remove specific production capistrano config
stevenbarragan Sep 11, 2024
c6dbe69
Put back resque_scheduler
stevenbarragan Sep 11, 2024
b8b521c
Put back /app/assets/builds/.keep file
stevenbarragan Sep 11, 2024
3ae3a9c
Cicd fix bundler (#1645)
sb-ebukaanene Sep 11, 2024
bf3a691
Fix capistrano puma port
stevenbarragan Sep 11, 2024
67e82e0
Fix session redis host environment variables
stevenbarragan Sep 11, 2024
79a628e
Make sure resque gets restart after deploy
stevenbarragan Sep 12, 2024
fa2afe3
Update buildspec_searchgov.yml (#1642)
sb-ebukaanene Sep 12, 2024
2845cbf
Update fetch_env_vars.sh
sb-ebukaanene Sep 13, 2024
9469232
Setup host and port for sidekiq
stevenbarragan Sep 13, 2024
76c7f2a
Log search impression data on its own key
stevenbarragan Sep 16, 2024
321df4d
Log clicks data on its own key, same as impressions
stevenbarragan Sep 16, 2024
5981d17
Log impression and clicks to its own file
stevenbarragan Sep 16, 2024
7ebc2b8
Fix search impression
stevenbarragan Sep 16, 2024
21b789f
Log click and search impressions the same way as before
stevenbarragan Sep 16, 2024
7b2dca4
Use REDIS_SYSTEM_URL instead of REDIS_HOST and REDIS_PORT
stevenbarragan Sep 17, 2024
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ yarn-debug.log*
/app/assets/builds/*
!/app/assets/builds/.keep

# Ignore OSX system files
.env
.DS_Store
26 changes: 26 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'capistrano/setup'

require 'capistrano/deploy'

require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

require 'capistrano/rbenv'

require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

require 'capistrano/puma'
require 'capistrano/puma/workers'

install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Systemd

require 'capistrano-resque'
require 'whenever/capistrano'

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
18 changes: 15 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rails', '~> 7.0.8'
gem 'dotenv', '~> 3.1', '>= 3.1.2'

gem 'base64', '~> 0.2.0'

Expand Down Expand Up @@ -153,7 +154,6 @@ gem 'react-rails', '~> 3.0.0'
# See https://github.com/shakacode/shakapacker#upgrading
gem 'shakapacker', '~> 6.5.4'
gem 'cssbundling-rails', '~> 1.2' # Management of css (Less) files conversion

# Temporarily locking the 'mail' version until the next version of Rails is released
# https://github.com/rails/rails/pull/46650
gem 'mail', '~> 2.7.1'
Expand All @@ -162,6 +162,12 @@ gem 'bootsnap', require: false

gem 'rails_semantic_logger', '~> 4.14'

gem 'dotenv', '~> 3.1'
gem 'whenever', '~> 1.0', require: false

# web server
gem 'puma', '~> 5.6'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
Expand All @@ -176,6 +182,13 @@ group :development do
# gem 'web-console'
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"

# Deployment
gem 'capistrano-resque', '~> 0.2.3', require: false
gem 'capistrano', '~> 3.19', require: false
gem 'capistrano-rails', '~> 1.6', require: false
gem 'capistrano-rbenv', '~> 2.2', require: false
gem 'capistrano3-puma', '~> 5.2', require: false
end

group :development, :test do
Expand All @@ -192,7 +205,6 @@ group :development, :test do
# For improved console readability:
# https://github.com/amazing-print/amazing_print
gem 'amazing_print', '~> 1.4'
gem 'puma', '~> 5.6'
gem 'debug'
end

Expand Down
54 changes: 48 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ GEM
after_commit_action (1.1.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
airbrussh (1.5.2)
sshkit (>= 1.6.1, != 1.7.0)
amazing_print (1.5.0)
american_date (1.1.1)
ast (2.4.2)
Expand All @@ -180,12 +182,12 @@ GEM
activerecord (>= 5.2, < 7.1)
activesupport (>= 5.2, < 7.1)
request_store (~> 1.0)
aws-eventstream (1.2.0)
aws-eventstream (1.3.0)
aws-partitions (1.810.0)
aws-sdk-core (3.181.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-sdk-core (3.201.1)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
aws-sigv4 (~> 1.8)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.71.0)
aws-sdk-core (~> 3, >= 3.177.0)
Expand All @@ -194,7 +196,7 @@ GEM
aws-sdk-core (~> 3, >= 3.120.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
aws-sigv4 (1.6.0)
aws-sigv4 (1.8.0)
aws-eventstream (~> 1, >= 1.0.2)
axe-core-api (4.7.0)
dumb_delegator
Expand All @@ -221,6 +223,27 @@ GEM
msgpack (~> 1.2)
builder (3.2.4)
byebug (11.1.3)
capistrano (3.19.1)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (>= 1.9.0)
capistrano-bundler (2.1.0)
capistrano (~> 3.1)
capistrano-rails (1.6.3)
capistrano (~> 3.1)
capistrano-bundler (>= 1.1, < 3)
capistrano-rbenv (2.2.0)
capistrano (~> 3.1)
sshkit (~> 1.3)
capistrano-resque (0.2.3)
capistrano
resque
resque-scheduler
capistrano3-puma (5.2.0)
capistrano (~> 3.7)
capistrano-bundler
puma (>= 4.0, < 6.0)
capybara (3.39.2)
addressable
matrix
Expand All @@ -233,6 +256,7 @@ GEM
capybara-screenshot (1.0.26)
capybara (>= 1.0, < 4)
launchy
chronic (0.10.2)
chunky_png (1.4.0)
cld3 (3.6.0)
climate_control (0.2.0)
Expand Down Expand Up @@ -505,8 +529,13 @@ GEM
net-protocol
net-protocol (0.2.2)
timeout
net-scp (4.0.0)
net-ssh (>= 2.6.5, < 8.0.0)
net-sftp (4.0.0)
net-ssh (>= 5.0.0, < 8.0.0)
net-smtp (0.4.0.1)
net-protocol
net-ssh (7.2.3)
newrelic_rpm (9.10.2)
nio4r (2.7.1)
nokogiri (1.16.6)
Expand Down Expand Up @@ -783,6 +812,11 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sshkit (1.23.0)
base64
net-scp (>= 1.1.2)
net-sftp (>= 2.1.2)
net-ssh (>= 2.8.0)
sys-uname (1.2.3)
ffi (~> 1.1)
temple (0.10.2)
Expand Down Expand Up @@ -837,6 +871,8 @@ GEM
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
whenever (1.0.0)
chronic (>= 0.6.3)
will_paginate (3.3.1)
will_paginate-bootstrap (1.0.2)
will_paginate (>= 3.0.3)
Expand Down Expand Up @@ -866,6 +902,11 @@ DEPENDENCIES
base64 (~> 0.2.0)
bigdecimal (~> 3.1, >= 3.1.8)
bootsnap
capistrano (~> 3.19)
capistrano-rails (~> 1.6)
capistrano-rbenv (~> 2.2)
capistrano-resque (~> 0.2.3)
capistrano3-puma (~> 5.2)
capybara (~> 3.26)
capybara-screenshot
cld3 (~> 3.6.0)
Expand All @@ -882,7 +923,7 @@ DEPENDENCIES
debug
dogapi (~> 1.45)
dogstatsd-ruby (~> 3.2.0)
dotenv (~> 3.1, >= 3.1.2)
dotenv (~> 3.1)
elasticsearch!
elasticsearch-xpack (~> 7.4.0)
email_spec (~> 2.2)
Expand Down Expand Up @@ -976,6 +1017,7 @@ DEPENDENCIES
virtus (~> 1.0.5)
webdrivers (~> 5.0)
webmock (~> 3.8)
whenever (~> 1.0)
will_paginate (~> 3.3.0)
will_paginate-bootstrap (~> 1.0.1)

Expand Down
7 changes: 6 additions & 1 deletion app/models/click.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ def initialize(params)
end

def log
Rails.logger.info("[Click] #{click_hash.to_json}")
clicks_logger.info("[Click] #{click_hash.to_json}")
Rails.logger.info('[Click]', search_data: click_hash)
end

private

def clicks_logger
@@logger ||= Logger.new('log/clicks.log')
end

# prevent validation from choking on "invalid byte sequence in UTF-8"
def validate_url_encoding
return unless url
Expand Down
2 changes: 1 addition & 1 deletion app/models/rtu_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def top_urls
end

def trending_urls
redis = Redis.new(:host => REDIS_HOST, :port => REDIS_PORT)
redis = Redis.new(url: ENV.fetch('REDIS_SYSTEM_URL'))
trending_urls_key = ['TrendingUrls', @site.name].join(':')
redis.smembers(trending_urls_key)
end
Expand Down
7 changes: 6 additions & 1 deletion app/models/search_impression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def self.log(search, vertical, params, request)
modules: search.modules.join('|'),
params: clean_params(params))

Rails.logger.info("[Search Impression] #{hash.to_json}")
impression_logger.info("[Search Impression] #{hash.to_json}")
Rails.logger.info('[Search Impression]', search_data: hash)
end

def self.clean_params(params)
Expand All @@ -37,4 +38,8 @@ def self.get_url_from_request(request)
def self.flatten_diagnostics_hash(diagnostics_hash)
diagnostics_hash.keys.sort.map { |k| diagnostics_hash[k].merge(module: k) }
end

def self.impression_logger
@@logger ||= Logger.new('log/impressions.log')
end
end
2 changes: 1 addition & 1 deletion app/models/trending_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TrendingUrl
attr_accessor :affiliate, :url

cattr_reader :redis
@@redis = Redis.new(:host => REDIS_HOST, :port => REDIS_PORT)
@@redis = Redis.new(url: ENV.fetch('REDIS_SYSTEM_URL'))

def self.all
sorted_trending_affiliate_keys = @@redis.keys("TrendingUrls:*").sort
Expand Down
15 changes: 15 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

version: 0.0
os: linux
# files:
# - source: /
# destination: /home/search/cicd_temp

hooks:

BeforeInstall:
- location: cicd-scripts/fetch_env_vars.sh
timeout: 300
runas: search


48 changes: 48 additions & 0 deletions buildspec_searchgov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

version: 0.2
env:
parameter-store:
# env_used_in_app: "env_in_param_store"
APP_SERVER_ADDRESSES: "DEPLOY_SEARCHGOV_SERVER_ADDRESS"
RESQUE_SERVER_ADDRESSES: "DEPLOY_RESQUE_SERVER_ADDRESSES"
DEPLOYMENT_PATH: "DEPLOY_SEARCHGOV_DEPLOYMENT_PATH"
SERVER_DEPLOYMENT_USER: "DEPLOY_SERVER_DEPLOYMENT_USER"
RESQUE_WORKERS_COUNT: "DEPLOY_RESQUE_WORKERS_COUNT"
# SSH_KEY_PATH: "DEPLOY_SSH_KEY_PATH" - defined below

# shared deployment variables with subsequent stages - might not to export as this is the final stage
exported-variables:
- APP_SERVER_ADDRESSES
- RESQUE_SERVER_ADDRESSES
- DEPLOYMENT_PATH
- SERVER_DEPLOYMENT_USER
- SSH_KEY_PATH

phases:
install:
runtime-versions:
python: 3.x
commands:
- export PATH="$HOME/.rbenv/bin:$PATH"
- eval "$(rbenv init -)"


pre_build:
commands:
- aws secretsmanager get-secret-value --secret-id $SEARCH_SECRETSMANAGER_KEY_SECRET_NAME --region $SEARCH_AWS_REGION --query 'SecretString' --output text > $SEARCH_ENV_EC2_KEY
build:
commands:
- CURRENT_LOCATION=$(pwd) # would look something like this - /codebuild/output/src559980389/src - a temp dir created by codebuild
- SSH_KEY_PATH="${CURRENT_LOCATION}/${SEARCH_ENV_EC2_KEY}"
- echo $SSH_KEY_PATH
- echo "deploying searchgov app with capistrano"
- bundle install
- cap $SEARCH_ENV puma:config puma:systemd:config puma:systemd:enable
- cap $SEARCH_ENV deploy
- cap $SEARCH_ENV --tasks
- cap $SEARCH_ENV resque:start
- cap $SEARCH_ENV puma:restart

artifacts:
files:
- '**/*'
Loading