Compare commits
2 Commits
develop
...
df61e45aff
Author | SHA1 | Date | |
---|---|---|---|
df61e45aff
|
|||
044f807182
|
@ -26,7 +26,7 @@ jobs:
|
|||||||
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
needs: lint
|
needs: link
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@ -38,7 +38,7 @@ jobs:
|
|||||||
ruby-version: '3.3'
|
ruby-version: '3.3'
|
||||||
bundler-cache: true
|
bundler-cache: true
|
||||||
|
|
||||||
- run: bundle exec rspec
|
- run: ruby app_test.rb
|
||||||
|
|
||||||
|
|
||||||
release-image:
|
release-image:
|
4
Gemfile
4
Gemfile
@ -9,7 +9,7 @@ gem "anyflake"
|
|||||||
gem "ksuid"
|
gem "ksuid"
|
||||||
gem "nanoid"
|
gem "nanoid"
|
||||||
gem "ulid"
|
gem "ulid"
|
||||||
gem "uuid7"
|
gem 'uuid7'
|
||||||
|
|
||||||
gem "jwt"
|
gem "jwt"
|
||||||
|
|
||||||
@ -18,6 +18,6 @@ group :development do
|
|||||||
gem "rubocop"
|
gem "rubocop"
|
||||||
gem "rbs"
|
gem "rbs"
|
||||||
gem "rack-test"
|
gem "rack-test"
|
||||||
gem "rspec"
|
gem "test-unit"
|
||||||
gem "standard"
|
gem "standard"
|
||||||
end
|
end
|
||||||
|
19
Gemfile.lock
19
Gemfile.lock
@ -4,7 +4,6 @@ GEM
|
|||||||
anyflake (0.0.1)
|
anyflake (0.0.1)
|
||||||
ast (2.4.2)
|
ast (2.4.2)
|
||||||
base64 (0.2.0)
|
base64 (0.2.0)
|
||||||
diff-lcs (1.5.1)
|
|
||||||
json (2.7.2)
|
json (2.7.2)
|
||||||
jwt (2.8.2)
|
jwt (2.8.2)
|
||||||
base64
|
base64
|
||||||
@ -21,6 +20,7 @@ GEM
|
|||||||
parser (3.3.3.0)
|
parser (3.3.3.0)
|
||||||
ast (~> 2.4.1)
|
ast (~> 2.4.1)
|
||||||
racc
|
racc
|
||||||
|
power_assert (2.0.3)
|
||||||
prism (0.30.0)
|
prism (0.30.0)
|
||||||
puma (6.4.2)
|
puma (6.4.2)
|
||||||
nio4r (~> 2.0)
|
nio4r (~> 2.0)
|
||||||
@ -42,19 +42,6 @@ GEM
|
|||||||
regexp_parser (2.9.2)
|
regexp_parser (2.9.2)
|
||||||
rexml (3.3.0)
|
rexml (3.3.0)
|
||||||
strscan
|
strscan
|
||||||
rspec (3.13.0)
|
|
||||||
rspec-core (~> 3.13.0)
|
|
||||||
rspec-expectations (~> 3.13.0)
|
|
||||||
rspec-mocks (~> 3.13.0)
|
|
||||||
rspec-core (3.13.0)
|
|
||||||
rspec-support (~> 3.13.0)
|
|
||||||
rspec-expectations (3.13.1)
|
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
|
||||||
rspec-support (~> 3.13.0)
|
|
||||||
rspec-mocks (3.13.1)
|
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
|
||||||
rspec-support (~> 3.13.0)
|
|
||||||
rspec-support (3.13.1)
|
|
||||||
rubocop (1.64.1)
|
rubocop (1.64.1)
|
||||||
json (~> 2.3)
|
json (~> 2.3)
|
||||||
language_server-protocol (>= 3.17.0)
|
language_server-protocol (>= 3.17.0)
|
||||||
@ -104,6 +91,8 @@ GEM
|
|||||||
lint_roller (~> 1.1)
|
lint_roller (~> 1.1)
|
||||||
rubocop-performance (~> 1.21.0)
|
rubocop-performance (~> 1.21.0)
|
||||||
strscan (3.1.0)
|
strscan (3.1.0)
|
||||||
|
test-unit (3.6.2)
|
||||||
|
power_assert
|
||||||
tilt (2.3.0)
|
tilt (2.3.0)
|
||||||
ulid (1.4.0)
|
ulid (1.4.0)
|
||||||
unicode-display_width (2.5.0)
|
unicode-display_width (2.5.0)
|
||||||
@ -125,12 +114,12 @@ DEPENDENCIES
|
|||||||
rack-test
|
rack-test
|
||||||
rackup
|
rackup
|
||||||
rbs
|
rbs
|
||||||
rspec
|
|
||||||
rubocop
|
rubocop
|
||||||
ruby-lsp
|
ruby-lsp
|
||||||
sinatra
|
sinatra
|
||||||
sinatra-contrib
|
sinatra-contrib
|
||||||
standard
|
standard
|
||||||
|
test-unit
|
||||||
ulid
|
ulid
|
||||||
uuid7
|
uuid7
|
||||||
|
|
||||||
|
68
app.rb
68
app.rb
@ -2,7 +2,6 @@ require "bundler/setup"
|
|||||||
require "sinatra"
|
require "sinatra"
|
||||||
require "sinatra/json"
|
require "sinatra/json"
|
||||||
require "sinatra/cookies"
|
require "sinatra/cookies"
|
||||||
require "sinatra/multi_route"
|
|
||||||
require "time"
|
require "time"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
require "json"
|
require "json"
|
||||||
@ -205,8 +204,6 @@ end
|
|||||||
before do
|
before do
|
||||||
# content_type 'text/plain'
|
# content_type 'text/plain'
|
||||||
sleep(1) while Sleep.instance.asleep? && request.path_info != "/livez/sleep"
|
sleep(1) while Sleep.instance.asleep? && request.path_info != "/livez/sleep"
|
||||||
content_type :text if request.path_info.start_with? "/_cat"
|
|
||||||
request.session_options[:skip] = !request.path_info.start_with?("/session")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/" do
|
get "/" do
|
||||||
@ -214,13 +211,19 @@ get "/" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
get "/env", provides: "json" do
|
get "/env", provides: "json" do
|
||||||
content_type :json
|
|
||||||
|
|
||||||
return JSON.pretty_generate ENV.sort.to_h if params.key? "pretty"
|
return JSON.pretty_generate ENV.sort.to_h if params.key? "pretty"
|
||||||
|
|
||||||
JSON.generate ENV.sort.to_h
|
JSON.generate ENV.sort.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "/env" do
|
||||||
|
stream do |out|
|
||||||
|
ENV.sort.each do |k, v|
|
||||||
|
out << "#{k}=#{v}\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
get "/headers", provides: "json" do
|
get "/headers", provides: "json" do
|
||||||
h = req_headers
|
h = req_headers
|
||||||
return JSON.pretty_generate h if params.key? "pretty"
|
return JSON.pretty_generate h if params.key? "pretty"
|
||||||
@ -228,6 +231,14 @@ get "/headers", provides: "json" do
|
|||||||
JSON.generate h
|
JSON.generate h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "/headers" do
|
||||||
|
stream do |out|
|
||||||
|
req_headers.each do |k, v|
|
||||||
|
out << "#{k}: #{v.inspect}\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
get "/livez" do
|
get "/livez" do
|
||||||
error 503 unless Health.instance.healthy?
|
error 503 unless Health.instance.healthy?
|
||||||
|
|
||||||
@ -252,14 +263,6 @@ post "/livez/sleep" do
|
|||||||
"ok\n"
|
"ok\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/readyz" do
|
|
||||||
error 503 unless Ready.instance.ready?
|
|
||||||
|
|
||||||
return Ready.instance.to_json if request.env["HTTP_ACCEPT"] == "application/json"
|
|
||||||
|
|
||||||
Ready.instance.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
get "/uuid" do
|
get "/uuid" do
|
||||||
n = params.fetch(:n, 1).to_i
|
n = params.fetch(:n, 1).to_i
|
||||||
stream do |out|
|
stream do |out|
|
||||||
@ -333,42 +336,3 @@ end
|
|||||||
get "/cookies" do
|
get "/cookies" do
|
||||||
json response.headers
|
json response.headers
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/_cat/headers" do
|
|
||||||
stream do |out|
|
|
||||||
req_headers.each do |k, v|
|
|
||||||
out << "#{k}: #{v.inspect}\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
get "/_cat/env" do
|
|
||||||
stream do |out|
|
|
||||||
ENV.sort.each do |k, v|
|
|
||||||
out << "#{k}=#{v}\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
get "/_cat/cookies" do
|
|
||||||
stream do |out|
|
|
||||||
cookies.each do |k, v|
|
|
||||||
out << "#{k}=#{v}\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
route :delete, :get, :patch, :post, :put, "/status/:code" do
|
|
||||||
# hello
|
|
||||||
code = Integer(params[:code])
|
|
||||||
status code if code.between? 100, 599
|
|
||||||
end
|
|
||||||
|
|
||||||
get "/chunked/:delay" do
|
|
||||||
delay = Float(params[:delay])
|
|
||||||
stream do |out|
|
|
||||||
out << "Hello, world!\n"
|
|
||||||
sleep delay
|
|
||||||
out << "Hello, world!\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
19
app_test.rb
Normal file
19
app_test.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
ENV["APP_ENV"] = "test"
|
||||||
|
|
||||||
|
require "./app"
|
||||||
|
require "test/unit"
|
||||||
|
require "rack/test"
|
||||||
|
|
||||||
|
class ToyTest < Test::Unit::TestCase
|
||||||
|
include Rack::Test::Methods
|
||||||
|
|
||||||
|
def app
|
||||||
|
Sinatra::Application
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_root
|
||||||
|
get "/"
|
||||||
|
assert last_response.ok?
|
||||||
|
assert_equal "hello there!\n", last_response.body
|
||||||
|
end
|
||||||
|
end
|
@ -1,11 +0,0 @@
|
|||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: ConfigMap
|
|
||||||
metadata:
|
|
||||||
name: toy-configmap
|
|
||||||
namespace: toy
|
|
||||||
annotations:
|
|
||||||
reloader.stakater.com/match: "true"
|
|
||||||
data:
|
|
||||||
CAT: luna
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
|||||||
---
|
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
|
||||||
kind: Kustomization
|
|
||||||
namespace: toy
|
|
||||||
resources:
|
|
||||||
- secret.yaml
|
|
||||||
- configmap.yaml
|
|
||||||
- rollout.yaml
|
|
||||||
- services.yaml
|
|
||||||
- ingress.yaml
|
|
@ -1,58 +0,0 @@
|
|||||||
---
|
|
||||||
apiVersion: argoproj.io/v1alpha1
|
|
||||||
kind: Rollout
|
|
||||||
metadata:
|
|
||||||
name: toy
|
|
||||||
annotations:
|
|
||||||
reloader.stakater.com/auto: "true"
|
|
||||||
spec:
|
|
||||||
replicas: 5
|
|
||||||
strategy:
|
|
||||||
canary:
|
|
||||||
steps:
|
|
||||||
- setWeight: 20
|
|
||||||
- pause: {}
|
|
||||||
- setWeight: 40
|
|
||||||
- pause: {duration: 10}
|
|
||||||
- setWeight: 60
|
|
||||||
- pause: {duration: 10}
|
|
||||||
- setWeight: 80
|
|
||||||
- pause: {duration: 10}
|
|
||||||
revisionHistoryLimit: 2
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: toy
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: toy
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: toy
|
|
||||||
image: git.kill0.net/ryanc/toy:latest
|
|
||||||
imagePullPolicy: Always
|
|
||||||
ports:
|
|
||||||
- name: web
|
|
||||||
containerPort: 4567
|
|
||||||
env:
|
|
||||||
- name: SESSION_SECRET
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: toy-session-secret
|
|
||||||
key: session_secret
|
|
||||||
optional: true
|
|
||||||
envFrom:
|
|
||||||
- configMapRef:
|
|
||||||
name: toy-configmap
|
|
||||||
livenessProbe:
|
|
||||||
httpGet:
|
|
||||||
path: /livez
|
|
||||||
port: 4567
|
|
||||||
initialDelaySeconds: 3
|
|
||||||
periodSeconds: 3
|
|
||||||
readinessProbe:
|
|
||||||
httpGet:
|
|
||||||
path: /readyz
|
|
||||||
port: 4567
|
|
||||||
initialDelaySeconds: 5
|
|
||||||
periodSeconds: 5
|
|
@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
apiVersion: bitnami.com/v1alpha1
|
|
||||||
kind: SealedSecret
|
|
||||||
metadata:
|
|
||||||
creationTimestamp: null
|
|
||||||
name: toy-session-secret
|
|
||||||
namespace: toy
|
|
||||||
annotations:
|
|
||||||
reloader.stakater.com/match: "true"
|
|
||||||
spec:
|
|
||||||
encryptedData:
|
|
||||||
session_secret: AgBTxKU1zmMUNAUi9zR8bBby/u7voCe9axQgtNP9naE4Jhb8cGORCOuhT7EwUNZUc0gYf8XE56EeZQx9fl/m7IPr34dkC7IK22ZAG391PUBsj7gKYdBRL+s7hqH2s02eY3EIw45lWWjjdEmEizenFmqKpD0zD/UZFps1oRUnJ8Fry/wmfpNsapyb3J5fMC1p/SlJAFAEbGe+BKhjyIxAgHbizL510X1fGvS7LGgUQR4ePnX8Xmi1ubM8PeQOX0tRZwdw+AT8hm1eUd9KSw1PwlcF/xzrGHb7Pw5zTwoa9p1H9+nv80SyNdKxgWvwFj0+GThbOc3wiF1ENVyZmxZo/Y5SyHs7QpATvy23f253aC67nmTz5FU2KkmfqO8hGhdsrxIdQo/iMZq/SVABX4FgbrbKi70dRMe4SWRD1albqp4h/e2asBMPyzS+L27m6zD8BMZ+J9sQGyjAzzkADS5xG9UAF78fXZXJmPbNxCq92FFINHK98np3ucP+VdDBMyfOeKH8ieBR/qfakWRHnVQVsR+hnwdRS0CMixw7wB6RQw/JCAXKiwKVvvmVVXZzpNucuTesFClYNTxRKhPBHtiyXEPDaHpi7PghQB81wDcY0T9u6HYjGl4udA0friiN1CmUGO8e5FtkQ4eiMe+SIB3oCXNGWErMpMkHIRdt4rdP08rZ2m4GG3MKtQlBKM4MHfcKvke4tkLmeAItMTl2qNd283xaeabO0lG9yh0fuYuaNbqvYNt8TCprLWVb+ynrqbHn4E0SeoRT+vjGSR9K9N+iLkv6GCjDhiw+TrQ4QArYHI3CS2SeY4oIOe2HUP3jyjSh4r6jH1+n3elJG/eb+GQ9nlC4xKqXE+wwx+7s850nMifcDuk=
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
creationTimestamp: null
|
|
||||||
name: toy-session-secret
|
|
||||||
namespace: toy
|
|
31
kustomize/deployment.yaml
Normal file
31
kustomize/deployment.yaml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
kind: Deployment
|
||||||
|
apiVersion: apps/v1
|
||||||
|
metadata:
|
||||||
|
name: toy
|
||||||
|
labels:
|
||||||
|
app: toy
|
||||||
|
|
||||||
|
spec:
|
||||||
|
replicas: 3
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: toy
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: toy
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: toy
|
||||||
|
image: git.kill0.net/ryanc/toy:latest
|
||||||
|
ports:
|
||||||
|
- name: web
|
||||||
|
containerPort: 4567
|
||||||
|
env:
|
||||||
|
- name: SESSION_SECRET
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: toy-session-secret
|
||||||
|
key: toy-session-secret
|
||||||
|
optional: true
|
@ -3,6 +3,6 @@ apiVersion: kustomize.config.k8s.io/v1beta1
|
|||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
namespace: toy
|
namespace: toy
|
||||||
resources:
|
resources:
|
||||||
- namespace.yaml
|
- deployment.yaml
|
||||||
- ./app
|
- services.yaml
|
||||||
- ./memcached
|
- ingress.yaml
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
---
|
|
||||||
kind: Deployment
|
|
||||||
apiVersion: apps/v1
|
|
||||||
metadata:
|
|
||||||
name: toy-memcached
|
|
||||||
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: toy-memcached
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: toy-memcached
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: toy-memcached
|
|
||||||
image: memcached:latest
|
|
||||||
ports:
|
|
||||||
- name: memcached
|
|
||||||
containerPort: 11211
|
|
@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
|
||||||
kind: Kustomization
|
|
||||||
namespace: toy
|
|
||||||
resources:
|
|
||||||
- deployment.yaml
|
|
||||||
- services.yaml
|
|
@ -1,13 +0,0 @@
|
|||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: toy-memcached
|
|
||||||
|
|
||||||
spec:
|
|
||||||
ports:
|
|
||||||
- name: memcached
|
|
||||||
port: 11211
|
|
||||||
targetPort: memcached
|
|
||||||
selector:
|
|
||||||
app: toy-memcached
|
|
@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Namespace
|
|
||||||
metadata:
|
|
||||||
name: toy
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
|||||||
ENV["APP_ENV"] = "test"
|
|
||||||
|
|
||||||
require "./app"
|
|
||||||
require "rspec"
|
|
||||||
require "rack/test"
|
|
||||||
|
|
||||||
describe "Toy App" do
|
|
||||||
include Rack::Test::Methods
|
|
||||||
|
|
||||||
def app
|
|
||||||
Sinatra::Application
|
|
||||||
end
|
|
||||||
|
|
||||||
context "test /" do
|
|
||||||
it "test root route" do
|
|
||||||
get "/"
|
|
||||||
expect(last_response).to be_ok
|
|
||||||
expect(last_response.body).to eq("hello there!\n")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Reference in New Issue
Block a user