Преглед на файлове

Update Crystal and frameworks (#4020)

* Update Crystal and frameworks

* Generate Date header using HTTP.format_time

Not only it is more idiomatic, but faster as well:

Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT") 689.84k (  1.45µs) (± 1.35%)  242 B/op   1.37× slower
                    HTTP.format_time(Time.now) 941.75k (  1.06µs) (± 1.83%)  242 B/op        fastest

* Remove unnecessary X-Powered-By: Kemal
Vladislav Zarakovsky преди 7 години
родител
ревизия
b20ac7b1ba

+ 1 - 1
frameworks/Crystal/amber/amber.dockerfile

@@ -1,4 +1,4 @@
-FROM crystallang/crystal:0.24.1
+FROM crystallang/crystal:0.26.1
 
 
 WORKDIR /amber
 WORKDIR /amber
 COPY config config
 COPY config config

+ 3 - 2
frameworks/Crystal/amber/config/initializers/database.cr

@@ -1,3 +1,4 @@
-require "granite_orm/adapter/pg"
+require "granite/adapter/pg"
 
 
-Granite::ORM.settings.logger = Logger.new(nil)
+Granite.settings.logger = Logger.new(nil)
+Granite::Adapters << Granite::Adapter::Pg.new({name: "pg", url: ENV["DATABASE_URL"]})

+ 34 - 22
frameworks/Crystal/amber/shard.lock

@@ -2,35 +2,51 @@ version: 1.0
 shards:
 shards:
   amber:
   amber:
     github: amberframework/amber
     github: amberframework/amber
-    version: 0.6.7
+    version: 0.9.0
+
+  amber_router:
+    github: amberframework/amber-router
+    version: 0.2.0
 
 
   callback:
   callback:
     github: mosop/callback
     github: mosop/callback
     version: 0.6.3
     version: 0.6.3
 
 
   cli:
   cli:
-    github: amberframework/cli
+    github: mosop/cli
     version: 0.7.0
     version: 0.7.0
 
 
+  compiled_license:
+    github: elorest/compiled_license
+    version: 0.1.3
+
   db:
   db:
     github: crystal-lang/crystal-db
     github: crystal-lang/crystal-db
     version: 0.5.0
     version: 0.5.0
 
 
-  granite_orm:
-    github: amberframework/granite-orm
-    version: 0.8.4
+  granite:
+    github: amberframework/granite
+    version: 0.13.1
+
+  inflector:
+    github: phoffer/inflector.cr
+    version: 0.1.8
 
 
   kilt:
   kilt:
     github: jeromegn/kilt
     github: jeromegn/kilt
     version: 0.4.0
     version: 0.4.0
 
 
-  micrate:
-    github: juanedi/micrate
+  liquid:
+    github: TechMagister/liquid.cr
     version: 0.3.0
     version: 0.3.0
 
 
+  micrate:
+    github: amberframework/micrate
+    version: 0.3.3
+
   mysql:
   mysql:
     github: crystal-lang/crystal-mysql
     github: crystal-lang/crystal-mysql
-    version: 0.4.0
+    version: 0.5.0
 
 
   optarg:
   optarg:
     github: mosop/optarg
     github: mosop/optarg
@@ -38,37 +54,33 @@ shards:
 
 
   pg:
   pg:
     github: will/crystal-pg
     github: will/crystal-pg
-    version: 0.14.1
+    version: 0.15.0
 
 
-  radix:
-    github: luislavena/radix
-    version: 0.3.8
+  pool:
+    github: ysbaddaden/pool
+    version: 0.2.3
 
 
   redis:
   redis:
     github: stefanwille/crystal-redis
     github: stefanwille/crystal-redis
-    version: 1.9.0
+    version: 2.0.0
 
 
   shell-table:
   shell-table:
-    github: jwaldrip/shell-table.cr
-    version: 0.9.2
+    github: luckyframework/shell-table.cr
+    commit: 078a04ea58ead5203bb435a3b5fff448ddabaeea
 
 
   slang:
   slang:
     github: jeromegn/slang
     github: jeromegn/slang
     version: 1.7.1
     version: 1.7.1
 
 
-  spinner:
-    github: askn/spinner
-    version: 0.1.1
-
   sqlite3:
   sqlite3:
     github: crystal-lang/crystal-sqlite3
     github: crystal-lang/crystal-sqlite3
-    version: 0.9.0
+    version: 0.10.0
 
 
   string_inflection:
   string_inflection:
     github: mosop/string_inflection
     github: mosop/string_inflection
     version: 0.2.1
     version: 0.2.1
 
 
   teeplate:
   teeplate:
-    github: amberframework/teeplate
-    version: 0.5.0
+    github: mosop/teeplate
+    version: 0.6.1
 
 

+ 4 - 4
frameworks/Crystal/amber/shard.yml

@@ -13,8 +13,8 @@ targets:
 dependencies:
 dependencies:
   amber:
   amber:
     github: amberframework/amber
     github: amberframework/amber
-    version: 0.6.7
+    version: 0.9.0
 
 
-  granite_orm:
-    github: amberframework/granite-orm
-    version: 0.8.4
+  granite:
+    github: amberframework/granite
+    version: 0.13.1

+ 5 - 5
frameworks/Crystal/amber/src/controllers/benchmark_controller.cr

@@ -8,7 +8,7 @@ class BenchmarkController < Amber::Controller::Base
   before_action do
   before_action do
     all do
     all do
       response.headers["Server"] = "Amber"
       response.headers["Server"] = "Amber"
-      response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
+      response.headers["Date"] = HTTP.format_time(Time.now)
     end
     end
   end
   end
 
 
@@ -26,7 +26,7 @@ class BenchmarkController < Amber::Controller::Base
     response.content_type = JSON
     response.content_type = JSON
     results = {} of Symbol => Int32
     results = {} of Symbol => Int32
     if world = World.find rand(1..ID_MAXIMUM)
     if world = World.find rand(1..ID_MAXIMUM)
-      results = {id: world.id, randomNumber: world.randomNumber}
+      results = {id: world.id, randomNumber: world.randomnumber}
     end
     end
     results.to_json
     results.to_json
   end
   end
@@ -39,7 +39,7 @@ class BenchmarkController < Amber::Controller::Base
 
 
     results = (1..queries).map do
     results = (1..queries).map do
       if world = World.find rand(1..ID_MAXIMUM)
       if world = World.find rand(1..ID_MAXIMUM)
-        {id: world.id, randomNumber: world.randomNumber}
+        {id: world.id, randomNumber: world.randomnumber}
       end
       end
     end
     end
 
 
@@ -54,9 +54,9 @@ class BenchmarkController < Amber::Controller::Base
 
 
     results = (1..queries).map do
     results = (1..queries).map do
       if world = World.find rand(1..ID_MAXIMUM)
       if world = World.find rand(1..ID_MAXIMUM)
-        world.randomNumber = rand(1..ID_MAXIMUM)
+        world.randomnumber = rand(1..ID_MAXIMUM)
         world.save
         world.save
-        {id: world.id, randomNumber: world.randomNumber}
+        {id: world.id, randomNumber: world.randomnumber}
       end
       end
     end
     end
 
 

+ 2 - 2
frameworks/Crystal/amber/src/models/fortune.cr

@@ -1,6 +1,6 @@
-require "granite_orm/adapter/pg"
+require "granite/adapter/pg"
 
 
-class Fortune < Granite::ORM::Base
+class Fortune < Granite::Base
   adapter pg
   adapter pg
 
 
   table_name fortune
   table_name fortune

+ 3 - 3
frameworks/Crystal/amber/src/models/world.cr

@@ -1,9 +1,9 @@
-require "granite_orm/adapter/pg"
+require "granite/adapter/pg"
 
 
-class World < Granite::ORM::Base
+class World < Granite::Base
   adapter pg
   adapter pg
 
 
   table_name world
   table_name world
   primary id : Int32
   primary id : Int32
-  field randomNumber : Int32
+  field randomnumber : Int32
 end
 end

+ 1 - 1
frameworks/Crystal/crystal/crystal-radix.dockerfile

@@ -1,4 +1,4 @@
-FROM crystallang/crystal:0.24.1
+FROM crystallang/crystal:0.26.1
 
 
 WORKDIR /crystal
 WORKDIR /crystal
 COPY views views
 COPY views views

+ 1 - 1
frameworks/Crystal/crystal/crystal.dockerfile

@@ -1,4 +1,4 @@
-FROM crystallang/crystal:0.24.1
+FROM crystallang/crystal:0.26.1
 
 
 WORKDIR /crystal
 WORKDIR /crystal
 COPY views views
 COPY views views

+ 3 - 3
frameworks/Crystal/crystal/server.cr

@@ -6,12 +6,12 @@ require "ecr"
 APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world?initial_pool_size=256&max_pool_size=256&max_idle_pool_size=256")
 APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world?initial_pool_size=256&max_pool_size=256&max_idle_pool_size=256")
 ID_MAXIMUM = 10_000
 ID_MAXIMUM = 10_000
 
 
-server = HTTP::Server.new("0.0.0.0", 8080) do |context|
+server = HTTP::Server.new do |context|
   response = context.response
   response = context.response
   request = context.request
   request = context.request
 
 
   response.headers["Server"] = "Crystal"
   response.headers["Server"] = "Crystal"
-  response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
+  response.headers["Date"] = HTTP.format_time(Time.now)
   
   
   case request.path
   case request.path
   when "/json"
   when "/json"
@@ -95,4 +95,4 @@ private def sanitized_query_count(request)
   queries.clamp(1..500)
   queries.clamp(1..500)
 end
 end
 
 
-server.listen(reuse_port: true)
+server.listen("0.0.0.0", 8080, reuse_port: true)

+ 3 - 3
frameworks/Crystal/crystal/server_radix.cr

@@ -92,11 +92,11 @@ tree.add "/updates", updates_handler
 APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world")
 APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world")
 ID_MAXIMUM = 10_000
 ID_MAXIMUM = 10_000
 
 
-server = HTTP::Server.new("0.0.0.0", 8080) do |context|
+server = HTTP::Server.new do |context|
   request = context.request
   request = context.request
   response = context.response
   response = context.response
   response.headers["Server"] = "Crystal"
   response.headers["Server"] = "Crystal"
-  response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
+  response.headers["Date"] = HTTP.format_time(Time.now)
 
 
   result = tree.find(request.path)
   result = tree.find(request.path)
 
 
@@ -134,4 +134,4 @@ private def sanitized_query_count(request)
   queries.clamp(1..500)
   queries.clamp(1..500)
 end
 end
 
 
-server.listen(reuse_port: true)
+server.listen("0.0.0.0", 8080, reuse_port: true)

+ 1 - 1
frameworks/Crystal/crystal/shard.lock

@@ -6,7 +6,7 @@ shards:
 
 
   pg:
   pg:
     github: will/crystal-pg
     github: will/crystal-pg
-    version: 0.14.1
+    version: 0.15.0
 
 
   radix:
   radix:
     github: luislavena/radix
     github: luislavena/radix

+ 1 - 1
frameworks/Crystal/crystal/shard.yml

@@ -6,7 +6,7 @@ license: MIT
 dependencies:
 dependencies:
   pg:
   pg:
     github: will/crystal-pg
     github: will/crystal-pg
-    version: 0.14.1
+    version: 0.15.0
 
 
   radix:
   radix:
     github: luislavena/radix
     github: luislavena/radix

+ 2 - 2
frameworks/Crystal/h2o.cr/h2o.cr.dockerfile

@@ -4,8 +4,8 @@ RUN apt update \
   && apt install -yqq libh2o-evloop-dev libwslay-dev libyaml-0-2 libevent-dev libpcre3-dev \
   && apt install -yqq libh2o-evloop-dev libwslay-dev libyaml-0-2 libevent-dev libpcre3-dev \
     gcc wget git libssl-dev libuv1-dev ca-certificates --no-install-recommends
     gcc wget git libssl-dev libuv1-dev ca-certificates --no-install-recommends
 
 
-RUN wget -q https://github.com/crystal-lang/crystal/releases/download/0.24.2/crystal-0.24.2-1-linux-x86_64.tar.gz \
-  && tar --strip-components=1 -xzf crystal-0.24.2-1-linux-x86_64.tar.gz -C /usr/ \
+RUN wget -q https://github.com/crystal-lang/crystal/releases/download/0.26.1/crystal-0.26.1-1-linux-x86_64.tar.gz \
+  && tar --strip-components=1 -xzf crystal-0.26.1-1-linux-x86_64.tar.gz -C /usr/ \
   && rm -f *.tar.gz
   && rm -f *.tar.gz
 
 
 WORKDIR /crystal
 WORKDIR /crystal

+ 1 - 1
frameworks/Crystal/h2o.cr/shard.yml

@@ -3,7 +3,7 @@ version: 0.0.1
 
 
 license: MIT
 license: MIT
 
 
-crystal: 0.24.2
+crystal: 0.26.1
 
 
 dependencies:
 dependencies:
   h2o:
   h2o:

+ 1 - 1
frameworks/Crystal/kemal/kemal.dockerfile

@@ -1,4 +1,4 @@
-FROM crystallang/crystal:0.24.1
+FROM crystallang/crystal:0.26.1
 
 
 WORKDIR /kemal
 WORKDIR /kemal
 COPY views views
 COPY views views

+ 3 - 2
frameworks/Crystal/kemal/server-postgres.cr

@@ -44,7 +44,7 @@ end
 
 
 before_all do |env|
 before_all do |env|
   env.response.headers["Server"] = "Kemal"
   env.response.headers["Server"] = "Kemal"
-  env.response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
+  env.response.headers["Date"] = HTTP.format_time(Time.now)
 end
 end
 
 
 #
 #
@@ -111,6 +111,7 @@ end
 Kemal.config do |cfg|
 Kemal.config do |cfg|
   cfg.serve_static = false
   cfg.serve_static = false
   cfg.logging = false
   cfg.logging = false
+  cfg.powered_by_header = false
 end
 end
 
 
-Kemal.run { |cfg| cfg.server.not_nil!.bind(reuse_port: true) }
+Kemal.run { |cfg| cfg.server.not_nil!.bind_tcp(cfg.host_binding, cfg.port, reuse_port: true) }

+ 11 - 3
frameworks/Crystal/kemal/shard.lock

@@ -4,9 +4,13 @@ shards:
     github: crystal-lang/crystal-db
     github: crystal-lang/crystal-db
     version: 0.5.0
     version: 0.5.0
 
 
+  exception_page:
+    github: crystal-loot/exception_page
+    version: 0.1.1
+
   kemal:
   kemal:
     github: kemalcr/kemal
     github: kemalcr/kemal
-    version: 0.22.0
+    version: 0.24.0
 
 
   kilt:
   kilt:
     github: jeromegn/kilt
     github: jeromegn/kilt
@@ -14,7 +18,11 @@ shards:
 
 
   pg:
   pg:
     github: will/crystal-pg
     github: will/crystal-pg
-    version: 0.14.1
+    version: 0.15.0
+
+  pool:
+    github: ysbaddaden/pool
+    version: 0.2.3
 
 
   radix:
   radix:
     github: luislavena/radix
     github: luislavena/radix
@@ -22,5 +30,5 @@ shards:
 
 
   redis:
   redis:
     github: stefanwille/crystal-redis
     github: stefanwille/crystal-redis
-    version: 1.9.0
+    version: 2.0.0
 
 

+ 3 - 3
frameworks/Crystal/kemal/shard.yml

@@ -6,10 +6,10 @@ license: MIT
 dependencies:
 dependencies:
   pg:
   pg:
     github: will/crystal-pg
     github: will/crystal-pg
-    version: 0.14.1
+    version: 0.15.0
   kemal:
   kemal:
     github: kemalcr/kemal
     github: kemalcr/kemal
-    version: 0.22.0
+    version: 0.24.0
   redis:
   redis:
     github: stefanwille/crystal-redis
     github: stefanwille/crystal-redis
-    version: 1.9.0
+    version: 2.0.0

+ 6 - 6
frameworks/Crystal/raze/raze.cr

@@ -40,7 +40,7 @@ end
 # Test 1: JSON Serialization
 # Test 1: JSON Serialization
 get "/json" do |ctx|
 get "/json" do |ctx|
   ctx.response.headers["Server"] = "Raze"
   ctx.response.headers["Server"] = "Raze"
-  ctx.response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
+  ctx.response.headers["Date"] = HTTP.format_time(Time.now)
   ctx.response.content_type = CONTENT::JSON
   ctx.response.content_type = CONTENT::JSON
   { message: "Hello, World!" }.to_json
   { message: "Hello, World!" }.to_json
 end
 end
@@ -48,7 +48,7 @@ end
 # Postgres Test 2: Single database query
 # Postgres Test 2: Single database query
 get "/db" do |ctx|
 get "/db" do |ctx|
   ctx.response.headers["Server"] = "Raze"
   ctx.response.headers["Server"] = "Raze"
-  ctx.response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
+  ctx.response.headers["Date"] = HTTP.format_time(Time.now)
   ctx.response.content_type = CONTENT::JSON
   ctx.response.content_type = CONTENT::JSON
   get_world.to_json
   get_world.to_json
 end
 end
@@ -59,7 +59,7 @@ get "/queries" do |ctx|
     get_world
     get_world
   end
   end
   ctx.response.headers["Server"] = "Raze"
   ctx.response.headers["Server"] = "Raze"
-  ctx.response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
+  ctx.response.headers["Date"] = HTTP.format_time(Time.now)
   ctx.response.content_type = CONTENT::JSON
   ctx.response.content_type = CONTENT::JSON
   results.to_json
   results.to_json
 end
 end
@@ -67,7 +67,7 @@ end
 # Postgres Test 4: Fortunes
 # Postgres Test 4: Fortunes
 get "/fortunes" do |ctx|
 get "/fortunes" do |ctx|
   ctx.response.headers["Server"] = "Raze"
   ctx.response.headers["Server"] = "Raze"
-  ctx.response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
+  ctx.response.headers["Date"] = HTTP.format_time(Time.now)
   ctx.response.content_type = CONTENT::HTML
   ctx.response.content_type = CONTENT::HTML
   data = fortunes
   data = fortunes
   additional_fortune = {
   additional_fortune = {
@@ -87,7 +87,7 @@ get "/updates" do |ctx|
     set_world({id: get_world[:id], randomNumber: Random.rand(CONTENT::ID_MAX).succ})
     set_world({id: get_world[:id], randomNumber: Random.rand(CONTENT::ID_MAX).succ})
   end
   end
   ctx.response.headers["Server"] = "Raze"
   ctx.response.headers["Server"] = "Raze"
-  ctx.response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
+  ctx.response.headers["Date"] = HTTP.format_time(Time.now)
   ctx.response.content_type = CONTENT::JSON
   ctx.response.content_type = CONTENT::JSON
   updated.to_json
   updated.to_json
 end
 end
@@ -95,7 +95,7 @@ end
 # Test 6: Plaintext
 # Test 6: Plaintext
 get "/plaintext" do |ctx|
 get "/plaintext" do |ctx|
   ctx.response.headers["Server"] = "Raze"
   ctx.response.headers["Server"] = "Raze"
-  ctx.response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
+  ctx.response.headers["Date"] = HTTP.format_time(Time.now)
   ctx.response.content_type = CONTENT::PLAIN
   ctx.response.content_type = CONTENT::PLAIN
   "Hello, World!"
   "Hello, World!"
 end
 end

+ 1 - 1
frameworks/Crystal/raze/raze.dockerfile

@@ -1,4 +1,4 @@
-FROM crystallang/crystal:0.24.1
+FROM crystallang/crystal:0.26.1
 
 
 WORKDIR /raze
 WORKDIR /raze
 COPY views views
 COPY views views

+ 2 - 2
frameworks/Crystal/raze/shard.lock

@@ -10,7 +10,7 @@ shards:
 
 
   pg:
   pg:
     github: will/crystal-pg
     github: will/crystal-pg
-    version: 0.14.1
+    version: 0.15.0
 
 
   radix:
   radix:
     github: luislavena/radix
     github: luislavena/radix
@@ -18,5 +18,5 @@ shards:
 
 
   raze:
   raze:
     github: samueleaton/raze
     github: samueleaton/raze
-    version: 0.2.1
+    version: 0.3.0
 
 

+ 3 - 2
frameworks/Crystal/raze/shard.yml

@@ -5,13 +5,14 @@ targets:
   raze:
   raze:
     main: src/raze.cr
     main: src/raze.cr
 
 
-crystal: 0.24.1
+crystal: 0.26.1
 
 
 license: MIT
 license: MIT
 
 
 dependencies:
 dependencies:
   raze:
   raze:
     github: samueleaton/raze
     github: samueleaton/raze
+    version: 0.3.0
   pg:
   pg:
     github: will/crystal-pg
     github: will/crystal-pg
-    version: 0.14.1
+    version: 0.15.0