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 CLOUD_BUILD_GCS_LOG_DIR option to read cloud build logs #35

Merged
merged 1 commit into from
Nov 28, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions lib/appengine/exec.rb
Expand Up @@ -175,6 +175,11 @@ module AppEngine
# accessed only over a private IP, you should use the `deployment` strategy
# instead.
#
# The Cloud Build log is output to the directory specified by
# "CLOUD_BUILD_GCS_LOG_DIR". (ex. "gs://BUCKET-NAME/FOLDER-NAME")
# By default, log directory name is
# "gs://[PROJECT_NUMBER].cloudbuild-logs.googleusercontent.com/".
#
# ### Specifying the host application
#
# The `cloud_build` strategy needs to know exactly which app, service, and
Expand Down Expand Up @@ -365,11 +370,13 @@ class << self
# standard). Allowed values are `nil`, `"deployment"` (which is the
# default for Standard), and `"cloud_build"` (which is the default
# for Flexible).
# @param gcs_log_dir [String,nil] GCS bucket name of the cloud build log
# when strategy is "cloud_build". (ex. "gs://BUCKET-NAME/FOLDER-NAME")
#
def new_rake_task name, args: [], env_args: [],
service: nil, config_path: nil, version: nil,
timeout: nil, project: nil, wrapper_image: nil,
strategy: nil
strategy: nil, gcs_log_dir: nil
escaped_args = args.map do |arg|
arg.gsub(/[,\[\]]/) { |m| "\\#{m}" }
end
Expand All @@ -382,7 +389,7 @@ def new_rake_task name, args: [], env_args: [],
new ["bundle", "exec", "rake", name_with_args] + env_args,
service: service, config_path: config_path, version: version,
timeout: timeout, project: project, wrapper_image: wrapper_image,
strategy: strategy
strategy: strategy, gcs_log_dir: gcs_log_dir
end
end

Expand Down Expand Up @@ -410,10 +417,12 @@ def new_rake_task name, args: [], env_args: [],
# standard). Allowed values are `nil`, `"deployment"` (which is the
# default for Standard), and `"cloud_build"` (which is the default for
# Flexible).
# @param gcs_log_dir [String,nil] GCS bucket name of the cloud build log
# when strategy is "cloud_build". (ex. "gs://BUCKET-NAME/FOLDER-NAME")
#
def initialize command,
project: nil, service: nil, config_path: nil, version: nil,
timeout: nil, wrapper_image: nil, strategy: nil
timeout: nil, wrapper_image: nil, strategy: nil, gcs_log_dir: nil
@command = command
@service = service
@config_path = config_path
Expand All @@ -422,6 +431,7 @@ def initialize command,
@project = project
@wrapper_image = wrapper_image
@strategy = strategy
@gcs_log_dir = gcs_log_dir

yield self if block_given?
end
Expand Down Expand Up @@ -760,13 +770,17 @@ def start_build_strategy app_info
begin
::JSON.dump config, file
file.flush
Util::Gcloud.execute [
execute_command = [
"builds", "submit",
"--project", @project,
"--no-source",
"--config", file.path,
"--timeout", @timeout
"--timeout", @timeout,
]
execute_command.concat([
"--gcs-log-dir", @gcs_log_dir
]) unless @gcs_log_dir.nil?
Util::Gcloud.execute execute_command
ensure
file.close!
end
Expand Down
14 changes: 13 additions & 1 deletion lib/appengine/tasks.rb
Expand Up @@ -113,6 +113,10 @@ module AppEngine
# the "cloud_build" strategy, and applies only to that strategy.) Normally,
# you should not override this unless you are testing a new wrapper.
#
# #### CLOUD_BUILD_GCS_LOG_DIR
#
# GCS bucket name of the cloud build log when GAE_STRATEGY is "cloud_build".
# (ex. "gs://BUCKET-NAME/FOLDER-NAME")
module Tasks
## @private
PROJECT_ENV = "GAE_PROJECT"
Expand All @@ -128,6 +132,8 @@ module Tasks
TIMEOUT_ENV = "GAE_TIMEOUT"
## @private
WRAPPER_IMAGE_ENV = "GAE_EXEC_WRAPPER_IMAGE"
## @private
GCS_LOG_DIR = "CLOUD_BUILD_GCS_LOG_DIR"

@defined = false

Expand Down Expand Up @@ -161,7 +167,8 @@ def setup_exec_task
version: ::ENV[VERSION_ENV],
timeout: ::ENV[TIMEOUT_ENV],
wrapper_image: ::ENV[WRAPPER_IMAGE_ENV],
strategy: ::ENV[STRATEGY_ENV]
strategy: ::ENV[STRATEGY_ENV],
gcs_log_dir: ::ENV[GCS_LOG_DIR]
start_and_report_errors app_exec
exit
end
Expand Down Expand Up @@ -274,6 +281,11 @@ def show_usage
the "cloud_build" strategy, and applies only to that strategy.) Normally,
you should not override this unless you are testing a new wrapper.

CLOUD_BUILD_GCS_LOG_DIR

GCS bucket name of the cloud build log when GAE_STRATEGY is "cloud_build".
(ex. "gs://BUCKET-NAME/FOLDER-NAME")

This rake task is provided by the "appengine" gem. To make these tasks
available, add the following line to your Rakefile:

Expand Down