From c425fa48c323633863baf0b8c09e092e2eeb5d5a Mon Sep 17 00:00:00 2001 From: shmokmt <32533860+shmokmt@users.noreply.github.com> Date: Thu, 21 Dec 2023 18:58:39 +0900 Subject: [PATCH] Add Ruby example --- .github/dependabot.yml | 5 +++ .github/workflows/main.yml | 3 ++ ci/run-ruby-example.sh | 9 +++++ examples/ruby/Gemfile | 5 +++ examples/ruby/Gemfile.lock | 79 ++++++++++++++++++++++++++++++++++++++ examples/ruby/main.rb | 16 ++++++++ 6 files changed, 117 insertions(+) create mode 100644 ci/run-ruby-example.sh create mode 100644 examples/ruby/Gemfile create mode 100644 examples/ruby/Gemfile.lock create mode 100644 examples/ruby/main.rb diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 966d3dccc9..5e70f0eb95 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -31,6 +31,11 @@ updates: schedule: interval: daily open-pull-requests-limit: 99 + - package-ecosystem: bundler + directory: "/examples/ruby" + schedule: + interval: daily + open-pull-requests-limit: 99 - package-ecosystem: docker directory: "/" schedule: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dad217f965..55a9c871e2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -134,6 +134,9 @@ jobs: - lang: dotnet docker-image: mcr.microsoft.com/dotnet/sdk:5.0-alpine entrypoint: /bin/sh + - lang: ruby + docker-image: ruby:3.2-alpine + entrypoint: /bin/sh - lang: scala docker-image: mozilla/sbt:8u292_1.5.7 entrypoint: /bin/sh diff --git a/ci/run-ruby-example.sh b/ci/run-ruby-example.sh new file mode 100644 index 0000000000..7c69eb7208 --- /dev/null +++ b/ci/run-ruby-example.sh @@ -0,0 +1,9 @@ +set -e + +./fake-gcs-server -backend memory -scheme http -port 8080 -external-url "http://localhost:8080" & + +( + cd examples/ruby + bundle + bundle exec ruby main.rb +) diff --git a/examples/ruby/Gemfile b/examples/ruby/Gemfile new file mode 100644 index 0000000000..018e8cf139 --- /dev/null +++ b/examples/ruby/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +gem 'google-cloud-storage' diff --git a/examples/ruby/Gemfile.lock b/examples/ruby/Gemfile.lock new file mode 100644 index 0000000000..e6ce1640f1 --- /dev/null +++ b/examples/ruby/Gemfile.lock @@ -0,0 +1,79 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) + base64 (0.2.0) + declarative (0.0.20) + digest-crc (0.6.5) + rake (>= 12.0.0, < 14.0.0) + faraday (2.8.1) + base64 + faraday-net_http (>= 2.0, < 3.1) + ruby2_keywords (>= 0.0.4) + faraday-net_http (3.0.2) + google-apis-core (0.11.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.17.0) + google-apis-core (>= 0.11.0, < 2.a) + google-apis-storage_v1 (0.29.0) + google-apis-core (>= 0.11.0, < 2.a) + google-cloud-core (1.6.1) + google-cloud-env (>= 1.0, < 3.a) + google-cloud-errors (~> 1.0) + google-cloud-env (2.1.0) + faraday (>= 1.0, < 3.a) + google-cloud-errors (1.3.1) + google-cloud-storage (1.45.0) + addressable (~> 2.8) + digest-crc (~> 0.4) + google-apis-iamcredentials_v1 (~> 0.1) + google-apis-storage_v1 (~> 0.29.0) + google-cloud-core (~> 1.6) + googleauth (>= 0.16.2, < 2.a) + mini_mime (~> 1.0) + googleauth (1.9.1) + faraday (>= 1.0, < 3.a) + google-cloud-env (~> 2.1) + jwt (>= 1.4, < 3.0) + multi_json (~> 1.11) + os (>= 0.9, < 2.0) + signet (>= 0.16, < 2.a) + httpclient (2.8.3) + jwt (2.7.1) + mini_mime (1.1.5) + multi_json (1.15.0) + os (1.1.4) + public_suffix (5.0.4) + rake (13.1.0) + representable (3.2.0) + declarative (< 0.1.0) + trailblazer-option (>= 0.1.1, < 0.2.0) + uber (< 0.2.0) + retriable (3.1.2) + rexml (3.2.6) + ruby2_keywords (0.0.5) + signet (0.18.0) + addressable (~> 2.8) + faraday (>= 0.17.5, < 3.a) + jwt (>= 1.5, < 3.0) + multi_json (~> 1.10) + trailblazer-option (0.1.2) + uber (0.1.0) + webrick (1.8.1) + +PLATFORMS + arm64-darwin-22 + +DEPENDENCIES + google-cloud-storage + +BUNDLED WITH + 2.4.1 diff --git a/examples/ruby/main.rb b/examples/ruby/main.rb new file mode 100644 index 0000000000..9bd52ac88e --- /dev/null +++ b/examples/ruby/main.rb @@ -0,0 +1,16 @@ +# How to run this example +# 1 - Build the docker image by running the command "docker build -t fsouza/fake-gcs-server ." +# 2 - Start the docker container: "docker run -d --name fake-gcs-server -p 8080:4443 -v ${PWD}/examples/data:/data fsouza/fake-gcs-server -scheme http" +# 3 - Check if it's working by running: "curl http://0.0.0.0:8080/storage/v1/b" +# 4 - Install requirements: "bundle install" +# 5 - Run this script: "bundle exec ruby main.rb" + +require 'google/cloud/storage' + +client = Google::Cloud::Storage.anonymous(endpoint: 'http://localhost:8080/') +client.buckets.each do |bucket| + puts "Bucket: #{bucket.name}" + bucket.files.each do |file| + puts "File: #{file.name}" + end +end