Skip to content

Commit

Permalink
Fix asset paths (#5)
Browse files Browse the repository at this point in the history
* Fix paths in app_base.rb

* Remove debug echoes from demo.sh

* Use tmpfs volume-mounts with mode 01777 to satisfy stricter Ruby base image

* Add better error logging to demo.sh
  • Loading branch information
JonJagger authored Dec 1, 2023
1 parent 0a2a34b commit 397430e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 43 deletions.
6 changes: 3 additions & 3 deletions app/app_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(externals)

# - - - - - - - - - - - - - - - - - - - - - -

environment.append_path('code/assets/images')
environment.append_path('app/assets/images')

def self.jquery_dialog_image(name)
get "/assets/images/#{name}", provides:[:png] do
Expand All @@ -35,7 +35,7 @@ def self.jquery_dialog_image(name)

# - - - - - - - - - - - - - - - - - - - - - -

environment.append_path('code/assets/stylesheets')
environment.append_path('app/assets/stylesheets')
environment.css_compressor = :sassc

get '/assets/app.css', provides:[:css] do
Expand All @@ -49,7 +49,7 @@ def self.jquery_dialog_image(name)

# - - - - - - - - - - - - - - - - - - - - - -

environment.append_path('code/assets/javascripts')
environment.append_path('app/assets/javascripts')
environment.js_compressor = Uglifier.new(harmony: true)

get '/assets/app.js', provides:[:js] do
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/app.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
//= require_tree .
//= require_tree .
75 changes: 40 additions & 35 deletions demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,17 @@ curl_smoke_test()
echo curl log in $(log_filename)
rm -rf $(log_filename) || true

echo curling server/alive
curl_json_body_200 alive
echo

echo curling server/ready
curl_json_body_200 ready
echo

echo curling server/sha
curl_json_body_200 sha
echo

echo curling assets/app.css
curl_200 assets/app.css 'Content-Type: text/css'
#cat $(log_filename) | grep 'SassC::SyntaxError:' && exit 42
echo

echo curling assets/app.js
curl_200 assets/app.js 'Content-Type: application/javascript'
#cat $(log_filename) | grep 'Uglifier::Error' && exit 42
echo

echo curling show/FxWwrr
curl_200 show/FxWwrr dashboard-page
echo
curl_plain_200 assets/app.css 'Content-Type: text/css'
curl_plain_200 assets/app.js 'Content-Type: application/javascript'
curl_plain_200 show/FxWwrr dashboard-page
}

#- - - - - - - - - - - - - - - - - - - - - - - - - - -
curl_json_body_200()
curl_json()
{
local -r route="${1}" # eg ready
curl \
Expand All @@ -60,30 +42,53 @@ curl_json_body_200()
--silent \
--verbose \
"http://localhost:$(server_port)/${route}" \
>> "$(log_filename)" 2>&1
> "$(log_filename)" 2>&1
}

grep --quiet 200 "$(log_filename)" # eg HTTP/1.1 200 OK
local -r result=$(tail -n 1 "$(log_filename)")
echo "GET ${route} => 200 ...|${result}"
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
curl_json_body_200()
{
local -r route="${1}" # eg ready
echo -n "GET ${route} => 200 ...|"
if curl_json "${route}" && grep --quiet 200 "$(log_filename)"; then
local -r result=$(tail -n 1 "$(log_filename)")
echo "${result}"
else
echo FAILED
echo
cat "$(log_filename)"
exit 42
fi
}

#- - - - - - - - - - - - - - - - - - - - - - - - - - -
curl_200()
curl_plain()
{
local -r route="${1}" # eg dashboard/choose
local -r pattern="${2}" # eg Hello

curl \
--fail \
--request GET \
--silent \
--verbose \
"http://localhost:$(server_port)/${route}" \
>> "$(log_filename)" 2>&1
> "$(log_filename)" 2>&1
}

grep --quiet 200 "$(log_filename)" # eg HTTP/1.1 200 OK
local -r result=$(grep "${pattern}" "$(log_filename)" | head -n 1)
echo "GET ${route} => 200 ...|${result}"
#- - - - - - - - - - - - - - - - - - - - - - - - - - -
curl_plain_200()
{
local -r route="${1}" # eg dashboard/choose
local -r pattern="${2}" # eg Hello
echo -n "GET ${route} => 200 ...|${pattern} "

if curl_plain "${route}" && grep --quiet 200 "$(log_filename)" && grep --quiet "${pattern}" "$(log_filename)"; then
echo SUCCESS
else
echo FAILED
echo
cat "$(log_filename)"
exit 42
fi
}

#- - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -101,7 +106,7 @@ curl_smoke_test
if [ "${1:-}" == '--no-browser' ]; then
containers_down
else
#open "http://localhost/dashboard/show/REf1t8?auto_refresh=true&minute_columns=true"
#open "http://localhost/dashboard/show/FxWwrr?auto_refresh=true&minute_columns=true"
open "http://localhost/dashboard/show/REf1t8?auto_refresh=true&minute_columns=true"
open "http://localhost/dashboard/show/FxWwrr?auto_refresh=true&minute_columns=true"
open "http://localhost/dashboard/show/LyQpFr?auto_refresh=true&minute_columns=true"
fi
12 changes: 10 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ services:
ports: [ 9999:9999 ]
read_only: true
restart: "no"
tmpfs: /tmp
volumes:
- ./test/client:/dashboard:ro
- ./test:/test:ro
- type: tmpfs
target: /tmp
tmpfs:
mode: 01777
size: 10485760 # 10MB

server:
image: cyberdojo/dashboard:${COMMIT_TAG}
Expand All @@ -50,7 +54,11 @@ services:
ports: [ 4527:4527 ]
read_only: true
restart: "no"
tmpfs: /tmp
volumes:
- ./app:/app:ro
- ./test:/test:ro
- type: tmpfs
target: /tmp
tmpfs:
mode: 01777
size: 10485760 # 10MB
12 changes: 10 additions & 2 deletions sh/create_docker_compose_yml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ services:
ports: [ $(client_port):$(client_port) ]
read_only: true
restart: "no"
tmpfs: /tmp
volumes:
- ./test/$(client_name):/dashboard:ro
- ./$(tests_dir):/test:ro
- type: tmpfs
target: /tmp
tmpfs:
mode: 01777
size: 10485760 # 10MB
$(server_name):
image: $(server_image):\${COMMIT_TAG}
Expand All @@ -65,9 +69,13 @@ services:
ports: [ $(server_port):$(server_port) ]
read_only: true
restart: "no"
tmpfs: /tmp
volumes:
- ./app:/app:ro
- ./$(tests_dir):/test:ro
- type: tmpfs
target: /tmp
tmpfs:
mode: 01777
size: 10485760 # 10MB
EOF
}

0 comments on commit 397430e

Please sign in to comment.