Browse Source

Amber framework updated to 1.4 (#8575)

* Amber framework update

* Amber pool size config

* Max pool size 28

* Amber fix

* Amber gitignore

* Amber process count

* Amber docker static compilation
Dragos Varovici 1 year ago
parent
commit
7bd8f6193b

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

@@ -0,0 +1 @@
+lib/*

+ 23 - 5
frameworks/Crystal/amber/amber.dockerfile

@@ -1,19 +1,37 @@
-FROM crystallang/crystal:0.26.1
+FROM crystallang/crystal:1.10.1-alpine as build
 
 
 WORKDIR /amber
 WORKDIR /amber
 COPY config config
 COPY config config
 COPY src src
 COPY src src
-COPY run.sh run.sh
+
 COPY shard.lock shard.lock
 COPY shard.lock shard.lock
 COPY shard.yml shard.yml
 COPY shard.yml shard.yml
 
 
-ENV GC_MARKERS 1
+RUN apk update
+RUN apk add yaml-dev sqlite-dev
+
+# RUN shards build amber --release
+RUN shards install
+RUN crystal build --release --no-debug --static src/amber.cr
+RUN cp amber bin/amber
+
+# Main Image
+FROM ubuntu:22.04
+
+WORKDIR /amber
+
 ENV AMBER_ENV production
 ENV AMBER_ENV production
-ENV DATABASE_URL postgres://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world?initial_pool_size=56&max_pool_size=56&max_idle_pool_size=56
+ENV DATABASE_URL postgres://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world?initial_pool_size=10&max_idle_pool_size=10&retry_attempts=3&retry_delay=1
 
 
+RUN apt-get update
 RUN apt-get install -yqq libyaml-dev
 RUN apt-get install -yqq libyaml-dev
-RUN shards build amber --release --no-debug
+
+COPY run.sh run.sh
+RUN mkdir bin
+COPY --from=build /amber/amber /amber/bin/amber
 
 
 EXPOSE 8080
 EXPOSE 8080
 
 
 CMD bash run.sh
 CMD bash run.sh
+
+

+ 4 - 6
frameworks/Crystal/amber/config/application.cr

@@ -27,14 +27,14 @@ Amber::Server.configure do |settings|
   #
   #
   # > Read more about Linux PORT REUSE https://lwn.net/Articles/542629/
   # > Read more about Linux PORT REUSE https://lwn.net/Articles/542629/
   #
   #
-  settings.port_reuse = false
+  settings.port_reuse = true
   #
   #
   #
   #
   # Process Count: This will enable Amber to be used in cluster mode,
   # Process Count: This will enable Amber to be used in cluster mode,
   # spinning an instance for each number of process specified here.
   # spinning an instance for each number of process specified here.
   # Rule of thumb, always leave at least 1 core available for system processes/resources.
   # Rule of thumb, always leave at least 1 core available for system processes/resources.
   #
   #
-  settings.process_count = 1
+  settings.process_count = (System.cpu_count).to_i32
   #
   #
   #
   #
   # PORT: This is the port that you're application will run on. Examples would be (80, 443, 3000, 8080)
   # PORT: This is the port that you're application will run on. Examples would be (80, 443, 3000, 8080)
@@ -45,7 +45,5 @@ Amber::Server.configure do |settings|
   # Log: Is the logger that will be used for Amber and it defaults to ::Logger.new(STDOUT).
   # Log: Is the logger that will be used for Amber and it defaults to ::Logger.new(STDOUT).
   # You can supply a custom logger.
   # You can supply a custom logger.
   #
   #
-  settings.logger = Amber::Environment::Logger.new(nil)
-  #
-  #
-end
+  settings.logging.severity = "info"
+end

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

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

+ 1 - 4
frameworks/Crystal/amber/run.sh

@@ -1,7 +1,4 @@
 #!/bin/bash
 #!/bin/bash
 
 
-for i in $(seq 1 $(nproc --all)); do
-  ./bin/amber &
-done
+./bin/amber
 
 
-wait

+ 85 - 45
frameworks/Crystal/amber/shard.lock

@@ -1,86 +1,126 @@
-version: 1.0
+version: 2.0
 shards:
 shards:
   amber:
   amber:
-    github: amberframework/amber
-    version: 0.9.0
+    git: https://github.com/amberframework/amber.git
+    version: 1.4.1
 
 
   amber_router:
   amber_router:
-    github: amberframework/amber-router
-    version: 0.2.0
+    git: https://github.com/amberframework/amber-router.git
+    version: 0.4.4
+
+  backtracer:
+    git: https://github.com/sija/backtracer.cr.git
+    version: 1.2.2
 
 
   callback:
   callback:
-    github: mosop/callback
-    version: 0.6.3
+    git: https://github.com/amberframework/callback.git
+    version: 0.9.2
 
 
   cli:
   cli:
-    github: mosop/cli
-    version: 0.7.0
+    git: https://github.com/amberframework/cli.git
+    version: 0.11.4
 
 
   compiled_license:
   compiled_license:
-    github: elorest/compiled_license
-    version: 0.1.3
+    git: https://github.com/elorest/compiled_license.git
+    version: 1.2.2
 
 
   db:
   db:
-    github: crystal-lang/crystal-db
-    version: 0.5.0
+    git: https://github.com/crystal-lang/crystal-db.git
+    version: 0.11.0
+
+  dotenv:
+    git: https://github.com/gdotdesign/cr-dotenv.git
+    version: 1.0.0
+
+  exception_page:
+    git: https://github.com/crystal-loot/exception_page.git
+    version: 0.3.1
+
+  future:
+    git: https://github.com/crystal-community/future.cr.git
+    version: 1.0.0
 
 
   granite:
   granite:
-    github: amberframework/granite
-    version: 0.13.1
+    git: https://github.com/amberframework/granite.git
+    version: 0.23.3
+
+  i18n:
+    git: https://github.com/crimson-knight/i18n.cr.git
+    version: 0.4.1
+
+  ifrit:
+    git: https://github.com/imdrasil/ifrit.git
+    version: 0.1.3
 
 
   inflector:
   inflector:
-    github: phoffer/inflector.cr
-    version: 0.1.8
+    git: https://github.com/phoffer/inflector.cr.git
+    version: 1.0.0
+
+  jennifer:
+    git: https://github.com/imdrasil/jennifer.cr.git
+    version: 0.13.0
+
+  json_mapping:
+    git: https://github.com/crystal-lang/json_mapping.cr.git
+    version: 0.1.1
 
 
   kilt:
   kilt:
-    github: jeromegn/kilt
-    version: 0.4.0
+    git: https://github.com/jeromegn/kilt.git
+    version: 0.6.1
 
 
   liquid:
   liquid:
-    github: TechMagister/liquid.cr
-    version: 0.3.0
+    git: https://github.com/dare892/liquid.cr.git
+    version: 0.4.1+git.commit.e4ef5ca06bf5bafe74e0b270c7aae2941a91ddd3
 
 
   micrate:
   micrate:
-    github: amberframework/micrate
-    version: 0.3.3
+    git: https://github.com/amberframework/micrate.git
+    version: 0.15.0
 
 
   mysql:
   mysql:
-    github: crystal-lang/crystal-mysql
-    version: 0.5.0
+    git: https://github.com/crystal-lang/crystal-mysql.git
+    version: 0.14.0
 
 
   optarg:
   optarg:
-    github: mosop/optarg
-    version: 0.5.8
+    git: https://github.com/amberframework/optarg.git
+    version: 0.9.3
 
 
   pg:
   pg:
-    github: will/crystal-pg
-    version: 0.15.0
+    git: https://github.com/will/crystal-pg.git
+    version: 0.26.0
 
 
   pool:
   pool:
-    github: ysbaddaden/pool
-    version: 0.2.3
+    git: https://github.com/ysbaddaden/pool.git
+    version: 0.3.0
 
 
   redis:
   redis:
-    github: stefanwille/crystal-redis
-    version: 2.0.0
+    git: https://github.com/stefanwille/crystal-redis.git
+    version: 2.8.3
+
+  sam:
+    git: https://github.com/imdrasil/sam.cr.git
+    version: 0.5.0
 
 
   shell-table:
   shell-table:
-    github: luckyframework/shell-table.cr
-    commit: 078a04ea58ead5203bb435a3b5fff448ddabaeea
+    git: https://github.com/luckyframework/shell-table.cr.git
+    version: 0.9.3
 
 
   slang:
   slang:
-    github: jeromegn/slang
-    version: 1.7.1
+    git: https://github.com/jeromegn/slang.git
+    version: 1.7.3
 
 
   sqlite3:
   sqlite3:
-    github: crystal-lang/crystal-sqlite3
-    version: 0.10.0
-
-  string_inflection:
-    github: mosop/string_inflection
-    version: 0.2.1
+    git: https://github.com/crystal-lang/crystal-sqlite3.git
+    version: 0.19.0
 
 
   teeplate:
   teeplate:
-    github: mosop/teeplate
-    version: 0.6.1
+    git: https://github.com/amberframework/teeplate.git
+    version: 0.11.2
+
+  wordsmith:
+    git: https://github.com/luckyframework/wordsmith.git
+    version: 0.4.0
+
+  yaml_mapping:
+    git: https://github.com/crystal-lang/yaml_mapping.cr.git
+    version: 0.1.1
 
 

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

@@ -1,5 +1,5 @@
 name: amber
 name: amber
-version: 0.1.0
+version: 0.2.0
 
 
 authors:
 authors:
   - Amber Team and Contributors <amberframework.org>
   - Amber Team and Contributors <amberframework.org>
@@ -13,8 +13,28 @@ targets:
 dependencies:
 dependencies:
   amber:
   amber:
     github: amberframework/amber
     github: amberframework/amber
-    version: 0.9.0
+    version: 1.4.1
+
+  jennifer:
+    github: imdrasil/jennifer.cr
+    version: "~> 0.13.0"
+
+  sam:
+    github: imdrasil/sam.cr
+    version: 0.5.0
+
+  pg:
+    github: will/crystal-pg
+    version: "= 0.26.0"
+
+  mysql:
+    github: crystal-lang/crystal-mysql
+    version: 0.14.0
+
+  dotenv:
+    github: gdotdesign/cr-dotenv
+    version: 1.0.0
 
 
   granite:
   granite:
     github: amberframework/granite
     github: amberframework/granite
-    version: 0.13.1
+    version: 0.23.3

+ 1 - 1
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"] = HTTP.format_time(Time.now)
+      response.headers["Date"] = HTTP.format_time(Time.local)
     end
     end
   end
   end
 
 

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

@@ -1,9 +1,9 @@
 require "granite/adapter/pg"
 require "granite/adapter/pg"
 
 
 class Fortune < Granite::Base
 class Fortune < Granite::Base
-  adapter pg
-
-  table_name fortune
-  primary id : Int32
-  field message : String
+  connection pg
+  table fortune
+  
+  column id : Int32, primary: true
+  column message : String
 end
 end

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

@@ -1,9 +1,9 @@
 require "granite/adapter/pg"
 require "granite/adapter/pg"
 
 
 class World < Granite::Base
 class World < Granite::Base
-  adapter pg
+  connection pg
+  table world
 
 
-  table_name world
-  primary id : Int32
-  field randomnumber : Int32
+  column id : Int32, primary: true
+  column randomnumber : Int32
 end
 end