Browse Source

Update crystal kemal amber (#3229)

* Update crystal

* Update kemal

* Update amber

* Remove quotes

* Remove unused enviroments

* Add amber encrypt section

* Move amber settings to config/application.cr

* Remove amber encrypt section

* Fix crystal install script

* Fix amber database

* Add database port

* Add database port

* Remove granite logs

* Fix granite database

* Remove amber/granite logs

* Use shards build on amber
Faustino Aguilar 7 years ago
parent
commit
e66a8460d9

+ 1 - 1
frameworks/Crystal/amber/LICENSE

@@ -1,6 +1,6 @@
 The MIT License (MIT)
 
-Copyright (c) 2017
+Copyright (c) 2018 Amber Team
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal

+ 9 - 6
frameworks/Crystal/amber/README.md

@@ -12,12 +12,15 @@ Amber Crystal borrows concepts that already have been battle tested, successful,
 
 ## Contributors
 
-- [eliasjpr](https://github.com/eliasjpr) Elias Perez - Maintainer
-- [fridgerator](https://github.com/fridgerator) Nick Franken - Maintainer
-- [elorest](https://github.com/elorest) Isaac Sloan - Maintainer
-- [drujensen](https://github.com/drujensen) Dru Jensen - Maintainer
-- [bew](https://github.com/bew) Benoit de Chezelles - Member
-- [faustinoaq](https://github.com/faustinoaq) Faustino Aguilar - Contributor
+- Dru Jensen [drujensen](https://github.com/drujensen) 
+- Elias Perez [eliasjpr](https://github.com/eliasjpr) 
+- Isaac Sloan [elorest](https://github.com/elorest) 
+- Faustino Aguilar [faustinoaq](https://github.com/faustinoaq) 
+- Nick Franken [fridgerator](https://github.com/fridgerator)
+- Mark Siemers [marksiemers](https://github.com/marksiemers)
+- Robert Carpenter [robacarp](https://github.com/robacarp) 
+
+See more [Amber contributors](https://github.com/amberframework/amber/graphs/contributors)
 
 ## License
 

+ 45 - 5
frameworks/Crystal/amber/config/application.cr

@@ -1,11 +1,51 @@
 require "amber"
 
+require "./initializers/*"
 require "../src/models/*"
 require "../src/controllers/*"
 
-Amber::Server.configure do |app|
-  app.name = "TFB test app"
-  app.color = false
-  app.port = 8080
-  app.host = "0.0.0.0"
+Amber::Server.configure do |settings|
+  # Use your environment variables settings here.
+  #
+  # Name: A name that identifies this application. This is not internally
+  # used by the framework.
+  #
+  settings.name = "amber"
+  #
+  #
+  # Host: is the application server host address or ip address. Useful for when
+  # deploying Amber to a PAAS and likely the assigned server IP is either
+  # known or unknown. Defaults to an environment variable HOST
+  #
+  settings.host = "0.0.0.0"
+  #
+  #
+  # Port Reuse: Amber supports clustering mode which allows to spin
+  # multiple app instances per core. This setting allows to bind the different
+  # instances to the same port. Default this setting to true if the number or process
+  # is grater than 1.
+  #
+  # > Read more about Linux PORT REUSE https://lwn.net/Articles/542629/
+  #
+  settings.port_reuse = true
+  #
+  #
+  # Process Count: This will enable Amber to be used in cluster mode,
+  # spinning an instance for each number of process specified here.
+  # Rule of thumb, always leave at least 1 core available for system processes/resources.
+  #
+  settings.process_count = 1
+  #
+  #
+  # PORT: This is the port that you're application will run on. Examples would be (80, 443, 3000, 8080)
+  #
+  settings.port = 8080
+  #
+  #
+  # Log: Is the logger that will be used for Amber and it defaults to ::Logger.new(STDOUT).
+  # You can supply a custom logger.
+  #
+  settings.logger = Amber::Environment::Logger.new(nil)
+  #
+  #
 end

+ 0 - 2
frameworks/Crystal/amber/config/database.yml

@@ -1,2 +0,0 @@
-pg:
-  database: postgres://benchmarkdbuser:benchmarkdbpass@TFB-database/hello_world

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

@@ -0,0 +1,3 @@
+require "granite_orm/adapter/pg"
+
+Granite::ORM.settings.logger = Logger.new(nil)

+ 5 - 5
frameworks/Crystal/amber/setup.sh

@@ -2,16 +2,16 @@
 
 fw_depends postgresql crystal
 
-shards install
-
-crystal build --release --no-debug src/amber.cr
-
 export GC_MARKERS=1
 
 export AMBER_ENV=production
 
+export DATABASE_URL=postgres://benchmarkdbuser:benchmarkdbpass@TFB-database:5432/hello_world
+
+shards build amber --release --no-debug
+
 for i in $(seq 1 $(nproc --all)); do
-  ./amber &
+  ./bin/amber &
 done
 
 wait

+ 11 - 15
frameworks/Crystal/amber/shard.lock

@@ -2,23 +2,23 @@ version: 1.0
 shards:
   amber:
     github: amberframework/amber
-    version: 0.3.6
+    version: 0.6.4
 
   callback:
     github: mosop/callback
     version: 0.6.3
 
   cli:
-    github: mosop/cli
-    version: 0.6.10
+    github: amberframework/cli
+    version: 0.7.0
 
   db:
     github: crystal-lang/crystal-db
-    version: 0.4.3
+    version: 0.5.0
 
   granite_orm:
     github: amberframework/granite-orm
-    version: 0.7.8
+    version: 0.8.2
 
   kilt:
     github: jeromegn/kilt
@@ -30,7 +30,7 @@ shards:
 
   mysql:
     github: crystal-lang/crystal-mysql
-    version: 0.3.3
+    version: 0.4.0
 
   optarg:
     github: mosop/optarg
@@ -38,7 +38,7 @@ shards:
 
   pg:
     github: will/crystal-pg
-    version: 0.13.4
+    version: 0.14.1
 
   radix:
     github: luislavena/radix
@@ -48,17 +48,13 @@ shards:
     github: stefanwille/crystal-redis
     version: 1.9.0
 
-  sentry:
-    github: samueleaton/sentry
-    version: 0.1.1
-
   shell-table:
     github: jwaldrip/shell-table.cr
     version: 0.9.2
 
   slang:
     github: jeromegn/slang
-    version: 1.7.0
+    commit: 777e2fc3e63daf5cfe9bd4475257905903b78542
 
   spinner:
     github: askn/spinner
@@ -66,13 +62,13 @@ shards:
 
   sqlite3:
     github: crystal-lang/crystal-sqlite3
-    version: 0.8.3
+    version: 0.9.0
 
   string_inflection:
     github: mosop/string_inflection
     version: 0.2.1
 
   teeplate:
-    github: mosop/teeplate
-    version: 0.4.5
+    github: amberframework/teeplate
+    version: 0.5.0
 

+ 7 - 3
frameworks/Crystal/amber/shard.yml

@@ -2,15 +2,19 @@ name: amber
 version: 0.1.0
 
 authors:
-  - Amber <amberframework.org>
+  - Amber Team and Contributors <amberframework.org>
 
 license: MIT
 
+targets:
+  amber:
+    main: src/amber.cr
+
 dependencies:
   amber:
     github: amberframework/amber
-    version: "0.3.6" 
+    version: 0.6.4 
 
   granite_orm:
     github: amberframework/granite-orm
-    version: "0.7.8"
+    version: 0.8.2

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

@@ -5,10 +5,11 @@ class BenchmarkController < Amber::Controller::Base
   TEXT_PLAIN = "text/plain"
   ID_MAXIMUM = 10_000
 
-  def initialize(@context)
-    super(@context)
-    response.headers["Server"] = "Amber"
-    response.headers["Date"] = Time.now.to_s
+  before_action do
+    all do
+      response.headers["Server"] = "Amber"
+      response.headers["Date"] = "#{Time.now}"
+    end
   end
 
   def plaintext
@@ -70,7 +71,7 @@ class BenchmarkController < Amber::Controller::Base
 
     fortunes = Fortune.all
     fortunes << fortune
-    fortunes.sort_by! { |fortune| fortune.message.to_s }
+    fortunes.sort_by! { |fortune| fortune.message || "" }
 
     render("fortune/index.ecr")
   end

+ 1 - 1
frameworks/Crystal/amber/src/views/fortune/index.ecr

@@ -6,7 +6,7 @@
   <% fortunes.each do |fortune| %>
     <tr>
     <td><%= fortune.id %></td>
-    <td><%= HTML.escape(fortune.message.to_s) %></td>
+    <td><%= HTML.escape(fortune.message || "") %></td>
     </tr>
   <% end %>
 </table>

+ 1 - 1
frameworks/Crystal/crystal/benchmark_config.json

@@ -45,7 +45,7 @@
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "Crystal-radix",
+      "display_name": "Crystal (Radix)",
       "notes": "",
       "versus": "crystal"
     }

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

@@ -3,7 +3,7 @@ require "json"
 require "pg"
 require "ecr"
 
-APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@#{ENV["DBHOST"]? || "127.0.0.1"}/hello_world?initial_pool_size=256&max_pool_size=256&max_idle_pool_size=256")
+APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@#{ENV["DBHOST"]? || "127.0.0.1"}:5432/hello_world?initial_pool_size=256&max_pool_size=256&max_idle_pool_size=256")
 ID_MAXIMUM = 10_000
 
 server = HTTP::Server.new("0.0.0.0", 8080) do |context|

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

@@ -89,7 +89,7 @@ tree.add "/queries", queries_handler
 tree.add "/fortunes", fortunes_handler
 tree.add "/updates", updates_handler
 
-APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@#{ENV["DBHOST"]? || "127.0.0.1"}/hello_world")
+APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@#{ENV["DBHOST"]? || "127.0.0.1"}:5432/hello_world")
 ID_MAXIMUM = 10_000
 
 server = HTTP::Server.new("0.0.0.0", 8080) do |context|

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

@@ -2,11 +2,11 @@ version: 1.0
 shards:
   db:
     github: crystal-lang/crystal-db
-    version: 0.4.3
+    version: 0.5.0
 
   pg:
     github: will/crystal-pg
-    version: 0.13.3
+    version: 0.14.1
 
   radix:
     github: luislavena/radix

+ 6 - 7
frameworks/Crystal/crystal/shard.yml

@@ -1,14 +1,13 @@
-name: "crystal"
-version: "0.0.1"
+name: crystal
+version: 0.0.1
+
+license: MIT
 
 dependencies:
   pg:
-    github: "will/crystal-pg"
-    version: "0.13.3"
+    github: will/crystal-pg
+    version: 0.14.1
 
   radix:
     github: luislavena/radix
     version: 0.3.8
-
-
-license: "MIT"

+ 0 - 1
frameworks/Crystal/kemal/.gitignore

@@ -1,4 +1,3 @@
-libs/
 lib/
 .crystal
 .shards

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

@@ -4,7 +4,7 @@ require "pg"
 # Compose Objects (like Hash) to have a to_json method
 require "json/to_json"
 
-APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@#{ENV["DBHOST"]? || "127.0.0.1"}/hello_world")
+APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@#{ENV["DBHOST"]? || "127.0.0.1"}:5432/hello_world")
 
 class CONTENT
   UTF8  = "; charset=UTF-8"
@@ -113,4 +113,4 @@ Kemal.config do |cfg|
   cfg.logging = false
 end
 
-Kemal.run { |cfg| cfg.server.bind(reuse_port: true) }
+Kemal.run { |cfg| cfg.server.not_nil!.bind(reuse_port: true) }

+ 1 - 1
frameworks/Crystal/kemal/server-redis.cr

@@ -113,4 +113,4 @@ Kemal.config do |cfg|
   cfg.logging = false
 end
 
-Kemal.run { |cfg| cfg.server.bind(reuse_port: true) }
+Kemal.run { |cfg| cfg.server.not_nil!.bind(reuse_port: true) }

+ 5 - 5
frameworks/Crystal/kemal/shard.lock

@@ -2,11 +2,11 @@ version: 1.0
 shards:
   db:
     github: crystal-lang/crystal-db
-    version: 0.4.2
+    version: 0.5.0
 
   kemal:
-    github: sdogruyol/kemal
-    version: 0.21.0
+    github: kemalcr/kemal
+    version: 0.22.0
 
   kilt:
     github: jeromegn/kilt
@@ -14,7 +14,7 @@ shards:
 
   pg:
     github: will/crystal-pg
-    version: 0.13.3
+    version: 0.14.1
 
   radix:
     github: luislavena/radix
@@ -22,5 +22,5 @@ shards:
 
   redis:
     github: stefanwille/crystal-redis
-    version: 1.8.0
+    version: 1.9.0
 

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

@@ -1,15 +1,15 @@
-name: "kemal"
-version: "0.0.1"
+name: kemal
+version: 0.0.1
+
+license: MIT
 
 dependencies:
   pg:
-    github: "will/crystal-pg"
-    version: "0.13.3"
+    github: will/crystal-pg
+    version: 0.14.1
   kemal:
-    github: "sdogruyol/kemal"
-    version: "0.21.0"
+    github: kemalcr/kemal
+    version: 0.22.0
   redis:
-    github: "stefanwille/crystal-redis"
-    version: "1.8.0"
-
-license: "MIT"
+    github: stefanwille/crystal-redis
+    version: 1.9.0

+ 5 - 18
toolset/setup/linux/languages/crystal.sh

@@ -2,30 +2,17 @@
 
 fw_installed crystal && return 0
 
-# install crystal
+# install crystal and shards (shards is embedded in crystal release)
 
-VERSION="0.23.1"
+VERSION="0.24.1"
 
-SAVE_AS=crystal-$VERSION-3-linux-x86_64.tar.gz
-URL=https://github.com/crystal-lang/crystal/releases/download/$VERSION/crystal-$VERSION-3-linux-x86_64.tar.gz
+SAVE_AS=crystal-$VERSION-2-linux-x86_64.tar.gz
+URL=https://github.com/crystal-lang/crystal/releases/download/v$VERSION/crystal-$VERSION-2-linux-x86_64.tar.gz
 
 fw_get -o $SAVE_AS $URL
 
 fw_untar ${SAVE_AS}
 
-# install shards
-
-SVERSION="0.7.1"
-SAVE_AS=shards-${SVERSION}_linux_x86_64
-URL=https://github.com/crystal-lang/shards/releases/download/v${SVERSION}/shards-${SVERSION}_linux_x86_64.gz
-
-fw_get -o ${SAVE_AS}.gz $URL
-
-gunzip ${SAVE_AS}.gz
-chmod 755 ${SAVE_AS}
-
-mv ${SAVE_AS} crystal-${VERSION}-3/bin/shards
-
-echo -e "export PATH=${IROOT}/crystal-${VERSION}-3/bin/:\$PATH" > $IROOT/crystal.installed
+echo -e "export PATH=${IROOT}/crystal-${VERSION}/bin/:\$PATH" > $IROOT/crystal.installed
 
 source $IROOT/crystal.installed