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

iss #4: python guides converter #9

Merged
merged 2 commits into from
Jan 14, 2020
Merged
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
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.git
.idea
.tup
static/guides/*.json
static/js/song_parser_peg.es6
node_modules
**/*.css
**/*.js
!static/define_libs.js
!static/soundfonts/*
!static/pre_libs.js
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Branch | Description
[iss4-serverless-build](https://github.com/maizy/sightreading.training/pull/7/files) | Serverless version: build docker container
[iss5-macos-dev-support](https://github.com/maizy/sightreading.training/pull/6/files) | Dev automation for serverless version, especially for macOS
[iss5-ios-support](https://github.com/maizy/sightreading.training/pull/8/files) | iOS + Web MIDI Browser support (authored by [@MaienM](https://github.com/MaienM/sightreading.training))
[iss4-python-guides-converter](https://github.com/maizy/sightreading.training/pull/9/files) | Remove lua requirements for building statics, use python instead. Lightweight final docker image.

## Serverless version

Expand All @@ -25,7 +26,7 @@ docker build -t st-serverless:latest -f serverless.dockerfile .
Run

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

Server started at [http://127.0.0.1:8080/](http://127.0.0.1:8080/)
Expand All @@ -35,26 +36,14 @@ Server started at [http://127.0.0.1:8080/](http://127.0.0.1:8080/)
#### 1\.

```
brew cask install osxfuse
brew install sassc npm tup
brew cask install osxfuse # restart may required
brew install sassc npm tup python
python -m pip install -r requirements.txt
```

#### 2\. comment line with moon

in `Tuprules.tup`

```diff
--- a/Tuprules.tup
+++ b/Tuprules.tup
@@ -15,4 +15,4 @@ TOP = $(TUP_CWD)
!pegjs = |> cat %f | $(TOP)/node_modules/.bin/pegjs --format amd | sed -e 's/^define(/define("st\/%O", /' > %o |>

: foreach *.scss |> !scss |> %B.css
-: foreach *.moon |> moonc %f |> %B.lua
+# : foreach *.moon |> moonc %f |> %B.lua
```

and in `static/guides/Tupfile`
in `static/guides/Tupfile`

```diff
--- a/static/guides/Tupfile
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
markdown2==2.3.8
30 changes: 15 additions & 15 deletions serverless.dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
FROM archlinux/base:latest
FROM archlinux/base:latest AS build_image

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)
RUN pacman -Sy tup nginx git npm sassc python3 python-pip --noconfirm && (yes | pacman -Scc || :)

WORKDIR /site/sightreading.training

Expand All @@ -18,11 +12,17 @@ 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
python3 -m pip install -r requirements.txt && \
tup init && \
tup generate build.sh && \
sed -i.bak '2iset -o xtrace' build.sh && \
./build.sh && \
rm -r node_modules .tup

FROM nginx:1.16.1-alpine as final_image
WORKDIR /site/sightreading.training
COPY --from=build_image /site/sightreading.training/static /site/sightreading.training/static
COPY --from=build_image /site/sightreading.training/serverless /site/sightreading.training/serverless
COPY --from=build_image /site/sightreading.training/mime.types /site/sightreading.training/mime.types

ENTRYPOINT nginx -c /site/sightreading.training/serverless-nginx.conf
ENTRYPOINT nginx -c /site/sightreading.training/serverless/nginx.conf
2 changes: 1 addition & 1 deletion serverless-nginx.conf → serverless/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ events {
}

http {
include mime.types;
include /site/sightreading.training/mime.types;

server {
listen 80;
Expand Down
49 changes: 49 additions & 0 deletions static/Tupfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
include_rules

.gitignore

: scss/*.css |> !join |> style.css
: js/service_worker/*.js |> !join |> service_worker.js
: js/*.js js/components/*.js js/components/pages/*.js |> !join |> main.js

: pre_libs.js \
../node_modules/classnames/index.js \
../node_modules/nosleep.js/dist/NoSleep.js \
../node_modules/mersennetwister/src/MersenneTwister.js \
../node_modules/react/umd/react.development.js \
../node_modules/react-dom/umd/react-dom.development.js \
../node_modules/prop-types/prop-types.js \
../node_modules/react-transition-group/dist/react-transition-group.js \
../node_modules/react-router-dom/umd/react-router-dom.js \
../node_modules/chart.js/dist/Chart.js \
../node_modules/react-chartjs-2/dist/react-chartjs-2.js \
../node_modules/moment/moment.js \
../node_modules/soundfont-player/dist/soundfont-player.js \
../node_modules/requirejs/require.js \
define_libs.js |> !join |> lib-dev.js

: pre_libs.js \
../node_modules/classnames/index.js \
../node_modules/nosleep.js/dist/NoSleep.js \
../node_modules/mersennetwister/src/MersenneTwister.js \
../node_modules/react/umd/react.production.min.js \
../node_modules/react-dom/umd/react-dom.production.min.js \
../node_modules/prop-types/prop-types.js \
../node_modules/react-transition-group/dist/react-transition-group.js \
../node_modules/react-router/umd/react-router.min.js \
../node_modules/react-router-dom/umd/react-router-dom.min.js \
../node_modules/chart.js/dist/Chart.js \
../node_modules/react-chartjs-2/dist/react-chartjs-2.js \
../node_modules/moment/min/moment.min.js \
../node_modules/soundfont-player/dist/soundfont-player.min.js \
../node_modules/requirejs/require.js \
define_libs.js |> !join |> lib.js

: ../node_modules/jasmine-core/lib/jasmine-core/boot.js |> ../node_modules/.bin/babel --plugins @babel/plugin-transform-modules-amd --module-id 'jasmine_boot' %f > %o |> jasmine_boot.js

: ../node_modules/jasmine-core/lib/jasmine-core/jasmine.js \
../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js |> !join |> spec.js

: ../node_modules/jasmine-core/lib/jasmine-core/jasmine.css |> !join |> spec.css

: foreach lib.js main.js service_worker.js |> ../node_modules/.bin/uglifyjs %f > %o |> %B.min.js
70 changes: 0 additions & 70 deletions static/Tupfile.lua

This file was deleted.

4 changes: 0 additions & 4 deletions static/Tuprules.lua

This file was deleted.

1 change: 1 addition & 0 deletions static/Tuprules.tup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!join = |> ^ join %o^ cat %f > %o |>
2 changes: 1 addition & 1 deletion static/guides/Tupfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.gitignore

: foreach *.md |> moon convert_to_json.moon %f > %o |> %B.json
: foreach *.md |> python3 convert_to_json.py %f > %o |> %B.json
20 changes: 20 additions & 0 deletions static/guides/convert_to_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
# encoding: utf-8

import json
import sys

import markdown2

if __name__ == '__main__':
if len(sys.argv) != 2:
sys.stderr.write('Wrong arguments')
sys.exit(1)

fname = sys.argv[1]
with open(fname) as fp:
result = {
'contents': markdown2.markdown(fp.read())
}
json.dump(result, sys.stdout)