phaedra 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1bdff92530752ce6f23f3b1e5e5763ac60ea46f0ff941147949790133a8d54e
4
- data.tar.gz: 940607642ec362c3eeb5a88629cfd5f42125990f0d0437fd160e7e27ce0f66e2
3
+ metadata.gz: 00d5ba6f3bc10860baef3bf63867665db4ef610b7cf14a8281495cf929339bc3
4
+ data.tar.gz: 5d1c500a8cbe79a89182497e7881fdeba3d129e5e2f2ddcce19012f9ae713171
5
5
  SHA512:
6
- metadata.gz: e151d4bf1a2471acf06e5331dde65dc97988403a873916062f08f46b37c6bfbc54a780e448bda0bada253cefe74747abd3811e3071ec7a8474e1346aa53cb863
7
- data.tar.gz: 16343524b69c5d67c228f4b69154faf816a996e9b6a15b66b01d10dbaf7510a3c1e747296e1c5d8b42100e7ca01c3e7e8492f4e2b5844946967a28bc1dd20799
6
+ metadata.gz: 3f3a8145df4a02f5362dfffb66f1de44ccd650425504007f2f49fa666c68bd9d228d0e8ade98daa2d318c57b220013009bd2c9b37d10d375a7cecca2cee0c4ac
7
+ data.tar.gz: f0effbf926248e56c67da411bd688cc3f6783d7710bdedf141029d523b4e55667df18b1e509cb68aa55795a01b74369ac8e007a91754ac9b3c6046741d166258
data/README.md CHANGED
@@ -118,7 +118,13 @@ All you have to do is create a static site repo ([Bridgetown](https://www.bridge
118
118
 
119
119
  We recommend using OpenFaaS' dockerfile template so you can define your own `Dockerfile` to book Rack + Phaedra using the Puma web server. This also allows you to customize the Docker image configuration to install and configure other tools as necessary.
120
120
 
121
- First, make sure you've pulled down the template:
121
+ First make sure you've added Puma to your Gemfile:
122
+
123
+ ```
124
+ gem "puma"
125
+ ```
126
+
127
+ Then make sure you've pulled down the OpenFaaS template:
122
128
 
123
129
  ```sh
124
130
  faas-cli template store pull dockerfile
@@ -174,7 +180,7 @@ Next add the `config.ru` file to boot Rack:
174
180
  ```ruby
175
181
  # testphaedra/config.ru
176
182
 
177
- require "phaedra"
183
+ require "phaedra/rack_app"
178
184
 
179
185
  run Phaedra::RackApp.new
180
186
  ```
@@ -210,7 +216,7 @@ In case you're wondering: yes, with Phaedra you can write multiple Ruby function
210
216
  Booting Phaedra up as Rack app is very simple. All you need to do is add a `config.ru` file alongside your `api` folder:
211
217
 
212
218
  ```ruby
213
- require "phaedra"
219
+ require "phaedra/rack_app"
214
220
 
215
221
  run Phaedra::RackApp.new
216
222
  ```
@@ -0,0 +1,46 @@
1
+ FROM ruby:2.6-alpine3.11 as builder
2
+
3
+ RUN apk add --no-cache --virtual \\
4
+ #
5
+ # required
6
+ bash tzdata build-base libffi-dev \\
7
+ #
8
+ # nice to haves
9
+ curl git
10
+
11
+ FROM builder as phaedra-app
12
+
13
+ # This is to fix an issue on Linux with permissions issues
14
+ ARG USER_ID=${USER_ID:-1000}
15
+ ARG GROUP_ID=${GROUP_ID:-1000}
16
+ ARG DOCKER_USER=${DOCKER_USER:-user}
17
+ ARG APP_DIR=${APP_DIR:-/home/user/phaedra-app}
18
+
19
+ # Change with --build-arg PHAEDRA_ENV=production
20
+ ARG PHAEDRA_ENV=staging
21
+ ENV PHAEDRA_ENV=$PHAEDRA_ENV
22
+
23
+ # Create a non-root user
24
+ RUN addgroup -g $GROUP_ID -S $GROUP_ID
25
+ RUN adduser --disabled-password -G $GROUP_ID --uid $USER_ID -S $DOCKER_USER
26
+
27
+ # Create and then own the directory to fix permissions issues
28
+ RUN mkdir -p $APP_DIR
29
+ RUN chown -R $USER_ID:$GROUP_ID $APP_DIR
30
+
31
+ # Define the user running the container
32
+ USER $USER_ID:$GROUP_ID
33
+
34
+ # . now == $APP_DIR
35
+ WORKDIR $APP_DIR
36
+
37
+ # COPY is run as a root user, not as the USER defined above, so we must chown it
38
+ COPY --chown=$USER_ID:$GROUP_ID Gemfile* ./
39
+ RUN gem install bundler
40
+ RUN bundle install
41
+
42
+ COPY --chown=$USER_ID:$GROUP_ID . .
43
+
44
+ EXPOSE 8080
45
+
46
+ CMD ["bundle", "exec", "rackup", "-p", "8080", "-o", "0.0.0.0"]
@@ -3,7 +3,7 @@ require_relative "../phaedra/initializers"
3
3
  class PhaedraFunction < Phaedra::Base
4
4
  def get(params)
5
5
  response["Content-Type"] = "text/html; charset=utf-8"
6
- "<p>This is Interesting. 😁 #{Phaedra.the_time}</p>"
6
+ "<p>😁 #{Phaedra.the_time} - #{ENV["PHAEDRA_ENV"]} - #{Time.new}</p>"
7
7
  end
8
8
  end
9
9
 
@@ -1,10 +1,10 @@
1
- require "phaedra"
1
+ require_relative "../phaedra/initializers"
2
2
 
3
3
  class PhaedraFunction < Phaedra::Base
4
4
  before_action :earlier_stuff
5
5
 
6
6
  def get(params)
7
- "The Current Time is: #{Time.new} and Search Param is #{params[:search]}."
7
+ "The ?search param is #{params[:search]}"
8
8
  end
9
9
 
10
10
  def post(params)
@@ -0,0 +1,8 @@
1
+ version: '3'
2
+ services:
3
+ web:
4
+ build: .
5
+ ports:
6
+ - "8080:8080"
7
+ environment:
8
+ - PHAEDRA_ENV
@@ -1,4 +1,5 @@
1
1
  require "phaedra/version"
2
2
  require "webrick"
3
3
  require "phaedra/initializers_module"
4
+ require "phaedra/startup_initializers"
4
5
  require "phaedra/base"
@@ -0,0 +1,9 @@
1
+ module Phaedra
2
+ Initializers.register self, priority: :high do
3
+ environment
4
+ end
5
+
6
+ def self.environment
7
+ @environment ||= ENV.fetch("PHAEDRA_ENV", :development).to_sym
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Phaedra
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phaedra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-23 00:00:00.000000000 Z
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,10 +80,12 @@ files:
80
80
  - LICENSE.txt
81
81
  - README.md
82
82
  - Rakefile
83
+ - example/Dockerfile
83
84
  - example/Gemfile
84
85
  - example/api/simple.rb
85
86
  - example/api/the-time.rb
86
87
  - example/config.ru
88
+ - example/docker-compose.yml
87
89
  - example/phaedra/initializers.rb
88
90
  - lib/phaedra.rb
89
91
  - lib/phaedra/base.rb
@@ -93,6 +95,7 @@ files:
93
95
  - lib/phaedra/rack_middleware.rb
94
96
  - lib/phaedra/rack_middleware/not_found.rb
95
97
  - lib/phaedra/rack_middleware/static.rb
98
+ - lib/phaedra/startup_initializers.rb
96
99
  - lib/phaedra/version.rb
97
100
  - phaedra.gemspec
98
101
  homepage: https://github.com/whitefusionhq/phaedra
@@ -114,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
117
  - !ruby/object:Gem::Version
115
118
  version: '0'
116
119
  requirements: []
117
- rubygems_version: 3.0.6
120
+ rubygems_version: 3.0.8
118
121
  signing_key:
119
122
  specification_version: 4
120
123
  summary: Write serverless Ruby functions via a REST-like microframework compatible