Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4: serverless build #7

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,22 @@ All kudos go to original
Branch | Description
------ | -----------
[setup-fork](https://github.com/maizy/sightreading.training/tree/setup-fork) | Fork setup, fix file names for macOS
[iss4-serverless-build](https://github.com/maizy/sightreading.training/tree/iss4-serverless-build) | Serverless version: build docker container

## Serverless version

Version without lua backend. Only nginx serving statics.

Build

```
docker build -t st-serverless:latest -f serverless.dockerfile .
```

Run

```
docker run -p 8080:80 st-serverless:latest
```

Server started at [http://127.0.0.1:8080/](http://127.0.0.1:8080/)
44 changes: 44 additions & 0 deletions serverless-nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
worker_processes 2;
error_log stderr notice;
daemon off;

events {
worker_connections 1024;
}

http {
include mime.types;

server {
listen 80;

access_log /dev/stdout combined;

types_hash_max_size 4096;

location / {
root /site/sightreading.training/serverless;
try_files /index.html =404;
}

location /static/ {
if ($request_filename ~* \.es6$|\.scss$) {
return 403;
}

# access_log off;
gzip on;
gzip_types application/x-javascript text/css image/svg+xml;

alias /site/sightreading.training/static/;
}

location /sw.js {
alias /site/sightreading.training/static/service_worker.js;
}

location /favicon.ico {
alias /site/sightreading.training/static/favicon.ico;
}
}
}
28 changes: 28 additions & 0 deletions serverless.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM archlinux/base:latest

RUN pacman -Sy base-devel lua51 luajit luarocks tup nginx git npm discount sassc --noconfirm && (yes | pacman -Scc || :)

# setup lua (TODO: remove, need only for static/guides compilation)
RUN luarocks --lua-version=5.1 install moonscript && \
luarocks --lua-version=5.1 install discount && \
luarocks --lua-version=5.1 install lua-cjson
RUN eval $(luarocks --lua-version=5.1 path)

WORKDIR /site/sightreading.training

# init npm as separate step, for better caching
ADD package.json package.json
ADD package-lock.json package-lock.json
RUN npm install

ADD . .

RUN sed -i.bak 's/^.*moon.*//' ./Tuprules.tup && \
tup init

RUN tup generate build.sh && \
sed -i.bak '2iset -o xtrace' build.sh

RUN ./build.sh

ENTRYPOINT nginx -c /site/sightreading.training/serverless-nginx.conf
33 changes: 33 additions & 0 deletions serverless/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE HTML>
<html lang="en">

<head>
<meta charset="UTF-8" />
<title>Sight Reading Trainer</title>
<link rel="stylesheet" href="/static/style.css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway" />
<link rel="icon" href="/static/img/icon-144.png" sizes="144x144" />
<link rel="manifest" href="/static/manifest.json" />
<meta content="width=device-width, initial-scale=1" name="viewport" />

<meta content="Practice sight reading right with your MIDI keyboard directly in your browser. Customizable note generation to always give you a challenge. Completely free." property="og:description" />
<meta content="Practice sight reading right with your MIDI keyboard directly in your browser. Customizable note generation to always give you a challenge. Completely free." name="description" />
<meta content="#727290" name="theme-color" />
</head>

<body>
<div id="page">
<div class="page_layout">
<div class="header_spacer">
<div class="header"><a href="/" class="logo_link"><img alt="" height="35" class="logo" src="/static/img/logo.svg" /><img alt="" height="35" class="logo_small" src="/static/img/logo-small.svg" /></a></div>
</div>
</div>
</div>
<script src="/static/lib.min.js" type="text/javascript"></script>
<script src="/static/main.min.js" type="text/javascript"></script>
<script type="text/javascript">
requirejs(['st/main'], function(m) { m.init({ "cacheBuster": 1572060007 }) });
</script>
</body>

</html>
2 changes: 1 addition & 1 deletion static/guides/convert_to_json.moon
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ f = assert io.open fname
contents = f\read "*a"

print json.encode {
contents: discount(contents)
contents: discount.compile(contents)
}