Commit d0fad442 authored by Tiffany Rea's avatar Tiffany Rea

Merge branch 'use-fog-google' into 'master'

Use Fog Google

See merge request gitlab-org/gitlab!82740
parents 7687cf1b c4a39f9c
......@@ -29,7 +29,6 @@ gem 'influxdb-client', '~> 1.17'
gem 'terminal-table', '~> 3.0.0', require: false
gem 'slack-notifier', '~> 2.4', require: false
gem 'fog-google', '~> 1.17', require: false
gem 'google-cloud-storage', '~> 1.36', require: false
gem 'confiner', '~> 0.2'
......
......@@ -65,8 +65,6 @@ GEM
deprecation_toolkit (1.5.1)
activesupport (>= 4.2)
diff-lcs (1.3)
digest-crc (0.6.4)
rake (>= 12.0.0, < 14.0.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
equalizer (0.0.11)
......@@ -152,20 +150,8 @@ GEM
google-apis-core (>= 0.4, < 2.a)
google-apis-storage_v1 (0.9.0)
google-apis-core (>= 0.4, < 2.a)
google-cloud-core (1.6.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
google-cloud-env (1.5.0)
faraday (>= 0.17.3, < 2.0)
google-cloud-errors (1.2.0)
google-cloud-storage (1.36.1)
addressable (~> 2.8)
digest-crc (~> 0.4)
google-apis-iamcredentials_v1 (~> 0.1)
google-apis-storage_v1 (~> 0.1)
google-cloud-core (~> 1.6)
googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0)
googleauth (1.1.0)
faraday (>= 0.17.3, < 2.0)
jwt (>= 1.4, < 3.0)
......@@ -382,7 +368,6 @@ DEPENDENCIES
faker (~> 2.19, >= 2.19.0)
fog-google (~> 1.17)
gitlab-qa
google-cloud-storage (~> 1.36)
influxdb-client (~> 1.17)
knapsack (~> 4.0)
octokit (~> 4.21)
......
# frozen_string_literal: true
require "google/cloud/storage"
require "fog/google"
# This script handles resources created during E2E test runs
#
......@@ -67,7 +67,7 @@ module QA
files.each do |file|
file_name = "#{environment_name}/#{file.split('/').last}"
Runtime::Logger.info("Uploading #{file_name}...")
gcs_bucket.create_file(file, file_name)
gcs_storage.put_object(BUCKET, file_name, File.read(file))
end
puts "\nDone"
......@@ -76,17 +76,20 @@ module QA
# Download files from GCS bucket by environment name
# Delete the files afterward
def download(environment_name)
files_list = gcs_bucket.files(prefix: "#{environment_name}")
files_list = gcs_storage.list_objects(BUCKET, prefix: environment_name).items.each_with_object([]) do |obj, arr|
arr << obj.name
end
return puts "\nNothing to download!" if files_list.empty?
files_list.each do |file|
local_path = "tmp/#{file.name.split('/').last}"
Runtime::Logger.info("Downloading #{file.name} to #{local_path}")
file.download(local_path)
files_list.each do |file_name|
local_path = "tmp/#{file_name.split('/').last}"
Runtime::Logger.info("Downloading #{file_name} to #{local_path}")
file = gcs_storage.get_object(BUCKET, file_name)
File.write(local_path, file[:body])
Runtime::Logger.info("Deleting #{file.name} from bucket")
file.delete
Runtime::Logger.info("Deleting #{file_name} from bucket")
gcs_storage.delete_object(BUCKET, file_name)
end
puts "\nDone"
......@@ -158,18 +161,14 @@ module QA
end
def gcs_storage
@gcs_storage ||= Google::Cloud::Storage.new(
project_id: PROJECT,
credentials: json_key
@gcs_storage ||= Fog::Storage::Google.new(
google_project: PROJECT,
**(File.exist?(json_key) ? { google_json_key_location: json_key } : { google_json_key_string: json_key })
)
rescue StandardError => e
abort("\nThere might be something wrong with the JSON key file - [ERROR] #{e}")
end
def gcs_bucket
@gcs_bucket ||= gcs_storage.bucket(BUCKET, skip_lookup: true)
end
# Path to GCS service account json key file
# Or the content of the key file as a hash
def json_key
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment