Skip to content

Commit

Permalink
Fix os identify (itsumura-h#201)
Browse files Browse the repository at this point in the history
* add Debian

* add scss style in example

* add centos

* change check libsass exists process

* rm prefix for session id

* add key generate command

* update session

* remove utils
  • Loading branch information
itsumura-h authored Feb 27, 2022
1 parent cb65d61 commit f156066
Show file tree
Hide file tree
Showing 43 changed files with 427 additions and 225 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Test
run: docker-compose run app sh /root/project/runTest.sh
run: docker-compose run app-alpine sh /root/project/runTest.sh
- name: Test multi-thread
run: |
echo '' >> tests/config.nims
echo 'switch("threads", "on")' >> tests/config.nims
echo 'switch("threadAnalysis", "off")' >> tests/config.nims
docker-compose run app sh /root/project/runTest.sh
docker-compose run app-alpine sh /root/project/runTest.sh
create-tag-draft:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ karax
*.log.*
*.db
*.db.*
*.exe
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ An asynchronous full-stack web framework for Nim, based on [asynchttpserver](htt

:warning: This project is under heavy development. It's not yet production-ready. :warning:

The only supported OS are Alpine, Debian, and Ubuntu.
It is recommended to use Docker regular flavor for development.
`nimlang/nim:1.6.2-alpine-regular` or `nimlang/nim:1.6.2-ubuntu-regular`
https://hub.docker.com/r/nimlang/nim

## Table of Contents

<!--ts-->
Expand Down
34 changes: 28 additions & 6 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,40 @@ services:
redis:
image: redis:alpine
tty: true
depends_on:
- app

app:
build:
context: .
dockerfile: ./docker/nim/Dockerfile
app-alpine:
build: ./docker/nim/alpine
tty: true
ports:
- 9000:5000
volumes:
- .:/root/project

app-ubuntu:
build: ./docker/nim/ubuntu
tty: true
ports:
- 9001:5000
volumes:
- .:/root/project

app-debian:
build: ./docker/nim/debian
tty: true
ports:
- 9002:5000
volumes:
- .:/root/project

app-centos:
build: ./docker/nim/centos
tty: true
privileged: true
ports:
- 9003:5000
volumes:
- .:/root/project

frontend:
build:
context: .
Expand All @@ -37,6 +58,7 @@ services:
MYSQL_PASSWORD: benchmarkdbpass
TZ: Asia/Tokyo
default_authentication_plugin: mysql_native_password

tfb-database-pg:
image: postgres:alpine
tty: true
Expand Down
10 changes: 6 additions & 4 deletions docker/nim/Dockerfile → docker/nim/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nimlang/nim:1.4.4-alpine
FROM nimlang/nim:1.6.2-alpine-regular

RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
RUN apk update && \
Expand All @@ -9,8 +9,10 @@ RUN apk update && \
pcre \
bsd-compat-headers \
lcov \
sqlite mariadb-dev libpq && \
sqlite \
mariadb-dev \
libpq \
libsass-dev && \
rm /usr/lib/mysqld* -fr && rm /usr/bin/mysql* -fr
WORKDIR /root/project/
ADD ./basolato.nimble /root/project/
ENV PATH $PATH:/root/.nimble/bin
WORKDIR /root/project/
21 changes: 21 additions & 0 deletions docker/nim/centos/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM centos:centos8.4.2105

RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*;
RUN dnf update -y && \
dnf makecache
RUN dnf install -y --enablerepo=powertools \
gcc \
vim \
wget \
git \
libsass-devel

WORKDIR /root
RUN wget https://nim-lang.org/download/nim-1.6.2-linux_x64.tar.xz && \
tar -Jxf nim-1.6.2-linux_x64.tar.xz && \
rm -f nim-1.6.2-linux_x64.tar.xz && \
mkdir /root/.nimble && \
mv nim-1.6.2/* .nimble/

ENV PATH $PATH:/root/.nimble/bin
WORKDIR /root/project
25 changes: 25 additions & 0 deletions docker/nim/debian/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM debian:11.2-slim

RUN apt update && \
apt upgrade -y
RUN apt install -y --no-install-recommends \
gcc \
xz-utils \
ca-certificates \
vim \
wget \
git \
sqlite3 \
libpq-dev \
libmariadb-dev \
libsass-dev

WORKDIR /root
RUN wget https://nim-lang.org/download/nim-1.6.2-linux_x64.tar.xz && \
tar -Jxf nim-1.6.2-linux_x64.tar.xz && \
rm -f nim-1.6.2-linux_x64.tar.xz && \
mkdir /root/.nimble && \
mv nim-1.6.2/* .nimble/

ENV PATH $PATH:/root/.nimble/bin
WORKDIR /root/project
15 changes: 15 additions & 0 deletions docker/nim/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM nimlang/nim:1.6.2-ubuntu-regular

RUN apt update; apt install -y libgnutls30 && \
apt update && \
apt upgrade -y && \
apt install -y --no-install-recommends \
vim \
curl \
sqlite \
libpq-dev \
libmysqlclient-dev \
libsass-dev
ENV PATH $PATH:/root/.nimble/bin
WORKDIR /root/project

8 changes: 7 additions & 1 deletion documents/en/ducere.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,16 @@ Create new file

#### config
Create `config.nims` for database connection, logging, session-timeout configuation.
```
```sh
ducere make config
```

#### key
Generate new `SECRET_KEY` in `.env`
```sh
ducere make key
```

#### controller
Create new controller
```sh
Expand Down
8 changes: 7 additions & 1 deletion documents/ja/ducere.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,16 @@ ducere migrate --reset --seed
#### config

DBコネクション、ログ、セッションタイムなどを定義するための`config.nims``.env`のファイルを作ります。
```
```sh
ducere make config
```

#### key
新しい`SECRET_KEY``.env`の中に作ります
```sh
ducere make key
```

#### controller

コントローラーを作ります。
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark/asynchttpserver/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SECRET_KEY="<bA^V0&&4-%F=YN|AZXCZZ}0" # 24 length
SECRET_KEY="hYio&ScMswgA(zz9$z5jpHfl3>!Gz+4RHO;ZJoZ!V0$VKQ;8|-2J{{H<EBvP0lXHQgU5$}y~vM*d%D1SrF)WDYma0mgPj<;RIxVm"
# DB Connection
DB_CONNECTION="tfb-database-pg:5432"
DB_USER=benchmarkdbuser
Expand Down
5 changes: 5 additions & 0 deletions examples/example/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Secret
SECRET_KEY="$VgK7N2|m2~@t&#!!Xr]A{D2M0,]p#MmiU?F)0.OH,EB.3BD(8$T5aL1{;#VC{%.(^CTg9[ehIanww{c=(*uBb(gDXEe3?At~zP+"

# DB Connection
DB_DATABASE="/root/project/examples/example/db.sqlite3" # sqlite file path or database name
DB_USER=""
Expand All @@ -16,9 +19,11 @@ LOG_DIR="/root/project/examples/example/logs"
# Session db
# Session type, file or redis, is defined in config.nims
SESSION_DB_PATH="/root/project/examples/example/session.db" # Session file path or redis host:port. ex:"127.0.0.1:6379"
# SESSION_DB_PATH="redis:6379" # Session file path or redis host:port. ex:"127.0.0.1:6379"
SESSION_TIME=20160 # minutes of 2 weeks
ENABLE_ANONYMOUS_COOKIE=true # true or false
COOKIE_DOMAINS="" # to specify multiple domains, "sample.com, sample.org"

HOST="0.0.0.0"
PORT=5000
LOCALE=en
3 changes: 3 additions & 0 deletions examples/example/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Secret
SECRET_KEY=""

# DB Connection
DB_DATABASE="/root/project/examples/example/db.sqlite3" # sqlite file path or database name
DB_USER=""
Expand Down
1 change: 0 additions & 1 deletion examples/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ lcov.info
# IDE
.vscode/*

config.nims
.env
*.out
*.log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ proc presentDd*(context:Context, params:Params):Future[Response] {.async.} =
dd(
a,
"abc",
request.repr,
context.request.repr,
)
return render("dd")

Expand Down
21 changes: 21 additions & 0 deletions examples/example/app/http/views/pages/sample/with_style_view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,30 @@ proc component2():string =
<div class="$(style2.element("className"))"></div>
"""

proc component3():string =
style "scss", style3:"""
<style>
.className{
height: 200px;
width: 200px;
background-color: yellow;
&:hover{
background-color: red;
}
}
</style>
"""

tmpli html"""
$(style3)
<div class="$(style3.element("className"))"></div>
"""

proc impl():string = tmpli html"""
$(component1())
$(component2())
$(component3())
"""

proc withStyleView*():string =
Expand Down
6 changes: 5 additions & 1 deletion examples/example/config.nims
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import os
putEnv("SECRET_KEY", "~>$)PCdkm7eFp(O57ULFY)21") # 24 chars
putEnv("DB_SQLITE", $true) # "true" or "false"
# putEnv("DB_POSTGRES", $true) # "true" or "false"
# putEnv("DB_MYSQL", $true) # "true" or "false"
# putEnv("DB_MARIADB", $true) # "true" or "false"
putEnv("SESSION_TYPE", "file") # "file" or "redis"
putEnv("LIBSASS", $true) # "true" or "false"
40 changes: 24 additions & 16 deletions examples/todo_app/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ import app/http/controllers/todo_controller
import app/http/middlewares/auth_middleware
import app/http/middlewares/cors_middleware

var routes = Routes.new()
routes.middleware(re".*", auth_middleware.checkCsrfTokenMiddleware)
routes.middleware(re"/api/.*", cors_middleware.setCorsHeadersMiddleware)
let ROUTES = @[
Route.group("", @[
Route.get("/", todo_controller.toppage),

routes.middleware(re"/(signin|signup)", auth_middleware.loginSkip)
routes.get("/signin", signin_controller.index)
routes.post("/signin", signin_controller.store)
routes.get("/signout", signin_controller.delete)
routes.get("/signup", signup_controller.index)
routes.post("/signup", signup_controller.store)
Route.group("", @[
Route.get("/signin", signin_controller.index),
Route.post("/signin", signin_controller.store),
Route.get("/signout", signin_controller.delete),
Route.get("/signup", signup_controller.index),
Route.post("/signup", signup_controller.store),
])
.middleware(auth_middleware.loginSkip),

routes.get("/", todo_controller.toppage)
Route.group("/todo", @[
Route.get("", todo_controller.index),
Route.get("/create", todo_controller.create),
Route.post("/create", todo_controller.store),
Route.post("/change-sort", todo_controller.changeSort),
])
.middleware(auth_middleware.mustBeLoggedIn),

routes.middleware(re"/todo", auth_middleware.mustBeLoggedIn)
routes.get("/todo", todo_controller.index)
routes.get("/todo/create", todo_controller.create)
routes.post("/todo/create", todo_controller.store)
routes.post("/todo/change-sort", todo_controller.changeSort)
Route.group("/api", @[])
.middleware(cors_middleware.setCorsHeadersMiddleware),
])
.middleware(auth_middleware.checkCsrfTokenMiddleware),
]

serve(routes)
serve(ROUTES)
32 changes: 0 additions & 32 deletions oop.nim

This file was deleted.

Loading

0 comments on commit f156066

Please sign in to comment.