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

Add support for google cloud #3821

Merged
merged 19 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from 16 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ certbot.log
rerun.txt

# Ignore VCR
features/support/fixtures/cassettes/**
features/support/fixtures/cassettes/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to put this re-enabling of vcr in this pr?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually looks like I just accidentally removed the last blank line, which doesn't seem to hurt anything

/config/master.key
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ AllCops:
- 'node_modules/**/*'
- 'server/**/*'
- 'vendor/**/*'
TargetRubyVersion: 3.0.4
TargetRubyVersion: 3.0.5
NewCops: enable

Gemspec/DateAssignment: # (new in 1.10)
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-3.0.4
ruby-3.0.5
7 changes: 4 additions & 3 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: WebsiteOne - CI
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
os_image: ubuntu2004
blocks:
- name: Test
task:
Expand All @@ -26,11 +26,12 @@ blocks:
commands:
- checkout
- sem-service start postgres 13
- sem-version ruby 3.0.4
- sem-version ruby 3.0.5
- sudo -u postgres createuser -s semaphore
- createdb -U postgres -h 0.0.0.0 websiteone_test
- cache restore
- bundle install --path vendor/bundle
- bundle config set --local path 'vendor/bundle'
- bundle install
- mkdir -p tmp/pids
- npm install bower
- npm install yarn
Expand Down
67 changes: 46 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,66 @@
FROM ruby:3.0.4 as base
# Use the official Ruby image from Docker Hub
# https://hub.docker.com/_/ruby

RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get update -qq && apt-get install -y build-essential \
libpq-dev nodejs \
libqt5webkit5-dev dos2unix \
gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x
# [START cloudrun_rails_base_image]
# Pinning the OS to buster because the nodejs install script is buster-specific.
# Be sure to update the nodejs install command if the base image OS is updated.
FROM ruby:3.0-buster as base
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we running 3.0.5 here with this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I think they keep 'buster' up with the 'stable' version of ruby 3.0.x

# [END cloudrun_rails_base_image]

RUN (curl -sS https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | apt-key add -) && \
echo "deb https://deb.nodesource.com/node_14.x buster main" > /etc/apt/sources.list.d/nodesource.list && \
apt-get update && apt-get install -y nodejs lsb-release

RUN (curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -) && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn

RUN apt-get update -qq && apt-get install -y dos2unix postgresql-client

RUN mkdir /WebsiteOne
WORKDIR /WebsiteOne

COPY Gemfile /WebsiteOne/Gemfile
COPY Gemfile.lock /WebsiteOne/Gemfile.lock

COPY ./docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]

#OPENSSL_CONF is set to /dev/null since not able to determine how to
#set it "correctly" for now. perhaps replace phantomjs with something else?
ENV BUNDLE_PATH=/bundle \
BUNDLE_BIN=/bundle/bin \
GEM_HOME=/bundle
# OPENSSL_CONF=/dev/null
ENV PATH="${BUNDLE_BIN}:${PATH}"

RUN bundle install
#Production or staging, use middle 2 config lines below when bundling
RUN gem install bundler && \
# bundle config set --local deployment 'true' && \
# bundle config set --local without 'development test' && \
bundle install

COPY package.json /WebsiteOne/package.json
COPY scripts /WebsiteOne/scripts
COPY vendor/assets/javascripts /WebsiteOne/assets/javascripts

FROM base

RUN dos2unix scripts/copy_javascript_dependencies.js
RUN npm install -g yarn
# To execute tests, install chrome below
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
RUN apt-get update && apt-get -y install google-chrome-stable

RUN dos2unix scripts/copy_javascript_dependencies.js
RUN yarn install
COPY . /WebsiteOne
RUN bundle exec rake assets:precompile

#Production or staging, take out 'bundle' line above and use the following
# ENV RAILS_ENV=production
# ENV RAILS_SERVE_STATIC_FILES=true
# # Redirect Rails log to STDOUT for Cloud Run to capture
# ENV RAILS_LOG_TO_STDOUT=true
# # [START cloudrun_rails_dockerfile_key]
# ARG MASTER_KEY
# ENV RAILS_MASTER_KEY=${MASTER_KEY}
# # [END cloudrun_rails_dockerfile_key]

# # pre-compile Rails assets with master key
# RUN bundle exec rake assets:precompile
# EXPOSE 8080
# CMD ["bin/rails", "server", "-b", "0.0.0.0", "-p", "8080"]

# Also add lines below to database.yml under 'production:'
# username: av
# password: <%= Rails.application.credentials.gcp[:db_password] %>
# host: /cloudsql/av-wso:us-central1:postgres
7 changes: 6 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source 'https://rubygems.org'

ruby '3.0.4'
ruby '3.0.5'

# Rather than loading the entire Rails framework, we charry pick the parts we use
gem 'actionmailer', '~> 6.1.7'
Expand Down Expand Up @@ -36,6 +36,7 @@ gem 'faker'
gem 'font-awesome-rails'
gem 'friendly_id'
gem 'geocoder'
gem 'google-cloud-storage'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this in this pr?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try taking all of the cloud storage stuff out. There's a chance that it's necessary for asset pipeline, but hopefully not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took it out.

# gem 'ice_cube', '0.16.3'
gem 'jquery-rails'
gem 'jquery-turbolinks', '2.1.0'
Expand Down Expand Up @@ -86,6 +87,10 @@ gem 'will_paginate-bootstrap'
gem 'youtube_rails'
gem 'rack-timeout'

group :production do
gem 'mini_racer' # for environment without pre-existing js runtimes
end

group :test do
gem 'capybara'
gem 'capybara-screenshot'
Expand Down
60 changes: 59 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ GEM
date (3.3.1)
dead_end (1.1.7)
debug_inspector (1.1.0)
declarative (0.0.20)
deep_merge (1.2.1)
delorean (2.1.0)
chronic
Expand All @@ -259,6 +260,8 @@ GEM
responders
warden (~> 1.2.3)
diff-lcs (1.4.4)
digest-crc (0.6.4)
rake (>= 12.0.0, < 14.0.0)
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
Expand Down Expand Up @@ -359,6 +362,40 @@ GEM
gli (2.20.0)
globalid (1.0.0)
activesupport (>= 5.0)
google-apis-core (0.9.2)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
httpclient (>= 2.8.1, < 3.a)
mini_mime (~> 1.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.a)
rexml
webrick
google-apis-iamcredentials_v1 (0.16.0)
google-apis-core (>= 0.9.1, < 2.a)
google-apis-storage_v1 (0.19.0)
google-apis-core (>= 0.9.0, < 2.a)
google-cloud-core (1.6.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
google-cloud-env (1.6.0)
faraday (>= 0.17.3, < 3.0)
google-cloud-errors (1.3.0)
google-cloud-storage (1.44.0)
addressable (~> 2.8)
digest-crc (~> 0.4)
google-apis-iamcredentials_v1 (~> 0.1)
google-apis-storage_v1 (~> 0.19.0)
google-cloud-core (~> 1.6)
googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0)
googleauth (1.3.0)
faraday (>= 0.17.3, < 3.a)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
guard (2.18.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
Expand Down Expand Up @@ -393,6 +430,7 @@ GEM
httparty (0.18.1)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
httpclient (2.8.3)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
icalendar (2.7.1)
Expand Down Expand Up @@ -428,6 +466,8 @@ GEM
addressable (~> 2.7)
letter_opener (1.7.0)
launchy (~> 2.2)
libv8-node (16.10.0.0-x86_64-darwin)
libv8-node (16.10.0.0-x86_64-linux)
listen (3.6.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand All @@ -442,6 +482,7 @@ GEM
net-pop
net-smtp
marcel (1.0.2)
memoist (0.16.2)
memory_profiler (1.0.0)
method_source (1.0.0)
middleware (0.1.0)
Expand All @@ -450,6 +491,8 @@ GEM
mime-types-data (3.2021.0704)
mini_histogram (0.3.1)
mini_mime (1.1.2)
mini_racer (0.6.3)
libv8-node (~> 16.10.0.0)
minitest (5.16.3)
msgpack (1.6.0)
multi_json (1.15.0)
Expand Down Expand Up @@ -503,6 +546,7 @@ GEM
actionpack (>= 4.2)
omniauth (~> 2.0)
orm_adapter (0.5.0)
os (1.1.4)
paper_trail (12.0.0)
activerecord (>= 5.2)
request_store (~> 1.1)
Expand Down Expand Up @@ -603,6 +647,10 @@ GEM
json
redcarpet (3.5.1)
regexp_parser (2.1.1)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
request_store (1.5.0)
rack (>= 1.4)
responders (3.0.1)
Expand All @@ -613,6 +661,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
retriable (3.1.2)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
Expand Down Expand Up @@ -695,6 +744,11 @@ GEM
shellany (0.0.1)
shoulda-matchers (4.5.1)
activesupport (>= 4.2.0)
signet (0.17.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simple_form (5.1.0)
actionpack (>= 5.2)
activemodel (>= 5.2)
Expand Down Expand Up @@ -739,11 +793,13 @@ GEM
timeout (0.3.1)
tins (1.29.1)
sync
trailblazer-option (0.1.2)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
uber (0.1.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
Expand Down Expand Up @@ -834,6 +890,7 @@ DEPENDENCIES
font-awesome-rails
friendly_id
geocoder
google-cloud-storage
guard
guard-cucumber
guard-livereload
Expand All @@ -853,6 +910,7 @@ DEPENDENCIES
local_time (~> 2.1)
mercury-rails!
mime-types (~> 3.3, >= 3.3.1)
mini_racer
nokogiri (= 1.11.5)
octokit
omniauth
Expand Down Expand Up @@ -912,7 +970,7 @@ DEPENDENCIES
youtube_rails

RUBY VERSION
ruby 3.0.4p208
ruby 3.0.5p211

BUNDLED WITH
2.2.33
51 changes: 51 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

# [START cloudrun_rails_cloudbuild]
steps:
- id: "build image"
name: "gcr.io/cloud-builders/docker"
entrypoint: 'bash'
args: ["-c", "docker build --build-arg MASTER_KEY=${_RAILS_KEY} -t gcr.io/${PROJECT_ID}/${_SERVICE_NAME} . "]
# secretEnv: ["_RAILS_KEY"]

- id: "push image"
name: "gcr.io/cloud-builders/docker"
args: ["push", "gcr.io/${PROJECT_ID}/${_SERVICE_NAME}"]

- id: "apply migrations"
name: "gcr.io/google-appengine/exec-wrapper"
entrypoint: "bash"
args:
[
"-c",
"/buildstep/execute.sh -i gcr.io/${PROJECT_ID}/${_SERVICE_NAME} -s ${PROJECT_ID}:${_REGION}:${_INSTANCE_NAME} -e RAILS_MASTER_KEY=${_RAILS_KEY} -- bundle exec rails db:migrate"
]

# Use seed step below only on first deploy if you want sample data
# - id: "seed some display data"
# name: "gcr.io/google-appengine/exec-wrapper"
# entrypoint: "bash"
# args:
# [
# "-c",
# "/buildstep/execute.sh -i gcr.io/${PROJECT_ID}/${_SERVICE_NAME} -s ${PROJECT_ID}:${_REGION}:${_INSTANCE_NAME} -e RAILS_MASTER_KEY=${_RAILS_KEY} -- bundle exec rake db:seed"
# ]
# secretEnv: ["_RAILS_KEY"]

substitutions:
_REGION: us-central1
_SERVICE_NAME: av-wso
_INSTANCE_NAME: postgres
# _SECRET_NAME: rails-master-key
# Do not put the key here for any official site as it will expose secrets and passwords.
# Instead, use the availableSecrets section below and put the key in google cloud secrets.
_RAILS_KEY: 79c9bca5ff743a515be994095fd41a3a


# availableSecrets:
# secretManager:
# - versionName: projects/${PROJECT_ID}/secrets/${_SECRET_NAME}/versions/latest
# env: RAILS_KEY

images:
- "gcr.io/${PROJECT_ID}/${_SERVICE_NAME}"
# [END cloudrun_rails_cloudbuild]
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative 'boot'
require 'rails'
require "active_storage/engine"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we end up needing this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took it out.


%w(
active_record/railtie
Expand Down
1 change: 1 addition & 0 deletions config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xxXTi2v2HMRD6dcSX6qpaUByfveL15gulGj/KfDKWfsNwHQXPSObiQqjWgtkWw9gjUhDSK1dJbBR8FA2MtbJJPNSMiSOP7csIFAIvMw/T7dNSQas+ilhGCjYVrnW6sZl4vc+GKKea569HaAuWTuC518pzD8eQI97w9+C0o5P9IpxPXGrLTB3Hm43uEzTxQD35e9mRW0VzSjvDjJCruKx+vbPF2O81Ap3XeWF4oOd2rw9xyPzbbTDVKB8dxApGLvkGtD5jKavS8Ne/+Iny5Miwg81H6wWqAdKrWg9rnZ8k4dkbGg0/7ZU0fFSyM6/UVwr6BbU/TV7U2mTFkLgsB05S4KJgx90pIiAZbTavME9rlPFPI1B5gI2G5JHNWINcuwY7D3WqNNA7Yg2NZMIDeB3qE0w+eSdditHkIfJZI3sPDJz63NVH0EQK135V3iYEaM/sQkz--IwmpHfU6ig9OgiMI--AvQyzBX9AUqeqe6stOPuXA==
Loading