diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..46facb1 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,13 @@ +#FROM library/rust +FROM ubuntu + +WORKDIR /home/forustm + +RUN apt-get update && apt-get install -y libpq-dev libssl1.0.0 + +#COPY .. . +#RUN cargo install + +ADD .env . + +CMD ["sh"] diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..9fc4382 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,63 @@ +version: '3.1' + +services: + + db: + image: postgres + restart: always + container_name: db + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: 123 + ports: + - 5432:5432 + volumes: + - db-data:/var/lib/postgresql/data + + cache: + image: redis + container_name: cache + restart: always + + web: + build: . + container_name: web + restart: always + links: + - db:postgres + - cache:redis + entrypoint: /home/forustm/forustm_web + env_file: + - .env + volumes: + - ../target/debug:/home/forustm + - ../static:/home/forustm/static + - ../views:/home/forustm/views + api: + build: . + container_name: api + restart: always + links: + - db:postgres + - cache:redis + entrypoint: /home/forustm/forustm_api + env_file: + - .env + volumes: + - ../target/debug:/home/forustm + nginx: + image: nginx + container_name: nginx + restart: always + links: + - api + - web + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + ports: + - 80:80 + - 443:443 + +volumes: + db-data: + diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..a36c5d9 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,37 @@ +user www-data; +worker_processes 4; +pid /run/nginx.pid; +events { + worker_connections 65535; + # multi_accept on; +} + +http{ + include mime.types; + upstream forustm_web { + server web:8081; + } + upstream forustm_api { + server api:8888; + } + server { + listen 80; + server_name 0.0.0.0; + + location / { + proxy_pass http://forustm_web; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /api/v1/ { + proxy_pass http://forustm_api/; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + } +} diff --git a/docs/getting_start.md b/docs/getting_start.md index e222f4e..053ce4d 100644 --- a/docs/getting_start.md +++ b/docs/getting_start.md @@ -29,3 +29,32 @@ forustm $ cargo run --bin forustm_api - 执行命令 : `docker pull postgres`,默认安装latest版本,[Docker Hub地址](https://hub.docker.com/_/postgres/) - 执行命令 : `docker run --name your_postgres_name -e POSTGRES_PASSWORD=system -d -p 5432:5432 postgres`,启动postresql实例 - 登录到Postgresql: `docker run -it --rm --link your_postgres_name:postgres postgres psql -h postgres -U postgres `,使用`\q`命令退出 + +### Get started with Docker Compose + +Prepare the dependents + +``` +$ cargo install diesel_cli +``` + +Setup the DB + +``` +$ cd docker && docker-compose up -d +$ diesel setup +``` + +Compile here + +``` +$ cargo build +``` + +Restart + +``` +$ cd docker && docker-compose restart +``` + +Now, [Click Here](http://localhost) diff --git a/migrations/2018-01-06-074038_users_custom_css/down.sql b/migrations/2018-01-06-074038_users_custom_css/down.sql new file mode 100644 index 0000000..165c468 --- /dev/null +++ b/migrations/2018-01-06-074038_users_custom_css/down.sql @@ -0,0 +1,5 @@ +-- Remove custom css column` + +ALTER TABLE ruser +DROP COLUMN custom_css + diff --git a/migrations/2018-01-06-074038_users_custom_css/up.sql b/migrations/2018-01-06-074038_users_custom_css/up.sql new file mode 100644 index 0000000..292cd6c --- /dev/null +++ b/migrations/2018-01-06-074038_users_custom_css/up.sql @@ -0,0 +1,4 @@ +-- Create column for custom css + +ALTER TABLE ruser +ADD custom_css VARCHAR diff --git a/src/models/rusers.rs b/src/models/rusers.rs index e5fa9ff..3e3bad4 100644 --- a/src/models/rusers.rs +++ b/src/models/rusers.rs @@ -28,6 +28,7 @@ struct RawUser { pub role: i16, // member => 2, manager => 1, admin => 0 pub status: i16, // 0 normal, 1 frozen, 2 deleted pub github: Option, + pub custom_css: Option, } impl RawUser { @@ -42,6 +43,7 @@ impl RawUser { signup_time: self.signup_time, role: self.role, github: self.github, + custom_css: self.custom_css, } } } @@ -57,6 +59,7 @@ pub struct RUser { pub signup_time: NaiveDateTime, pub role: i16, pub github: Option, + pub custom_css: Option, } impl RUser { @@ -241,6 +244,7 @@ pub struct EditUser { pub say: Option, pub avatar: Option, pub wx_openid: Option, + pub custom_css: Option, } impl EditUser { @@ -252,6 +256,7 @@ impl EditUser { ruser::say.eq(self.say), ruser::avatar.eq(self.avatar), ruser::wx_openid.eq(self.wx_openid), + ruser::custom_css.eq(self.custom_css), )) .get_result::(conn); match res { diff --git a/static/js/home.js b/static/js/home.js index c7006ba..5a14911 100644 --- a/static/js/home.js +++ b/static/js/home.js @@ -62,6 +62,7 @@ $(".modify :button").click(function (event) { event.preventDefault(); var nickname = $("#nickname").val().replace(/(^\s*)|(\s*$)/g, ""); var say = $("#say").val(); + var custom_css = $("#custom_css").val(); var avatar = $("#avatar").val().replace(/(^\s*)|(\s*$)/g, ""); var wx_openid = $("#wx_openid").val(); $(".text-danger").remove(); @@ -70,7 +71,7 @@ $(".modify :button").click(function (event) { url: "/api/v1/user/edit", type: "post", dataType: "json", - data: JSON.stringify({ "nickname": nickname, "say": say, "avatar": avatar, "wx_openid": wx_openid }), + data: JSON.stringify({ "nickname": nickname, "say": say, "custom_css": custom_css, "avatar": avatar, "wx_openid": wx_openid }), headers: { "Content-Type": "application/json" }, success: function (res) { if (res.status) { @@ -86,6 +87,7 @@ $(".modify :button").click(function (event) { function getInfo() { $("#nickname").val($(".nickname").text()); $("#say").val($(".say").text()); + $("#custom_css").val($(".custom_css").text()); $("#wx_openid").val($(".wx_openid").text()); $("#avatar").val($("#path")[0].src) } diff --git a/views/base.html b/views/base.html index f54e914..43376cc 100644 --- a/views/base.html +++ b/views/base.html @@ -64,6 +64,9 @@ font-family: -apple-system, "Helvetica Neue", Helvetica, "Nimbus Sans L", Arial, "Liberation Sans", "PingFang SC", "Hiragino Sans GB", "Source Han Sans CN", "Source Han Sans SC", "Microsoft YaHei", "Wenquanyi Micro Hei", "WenQuanYi Zen Hei", "ST Heiti", SimHei, "WenQuanYi Zen Hei Sharp", sans-serif;; } */ + {% if user %} + {{ user.custom_css }} + {% endif %} diff --git a/views/home.html b/views/home.html index 6c71e7f..a557527 100644 --- a/views/home.html +++ b/views/home.html @@ -36,6 +36,9 @@

用户信息

{{ user.say }}

+
+

{{ user.custom_css }}

+

@@ -49,6 +52,9 @@

修改信息

+
+ +
diff --git a/views/index.html b/views/index.html index 9d9abd1..c3fec15 100644 --- a/views/index.html +++ b/views/index.html @@ -1,186 +1,189 @@ -{% extends "base.html" %} - -{% block title %} -Rust语言中文社区-首页 -{% endblock title %} - -{% block content %} - - - - -
- -
- {% if title and desc %} -

{{ title }}

-

{{ desc }}

- {% endif %} -
- -
- -
- {% if blogs | length == 0 %} -

这里还没有内容哦……

- {% else %} - - {% endif %} -
-
- -
- {% if cate_sections_len == 0 %} -

这里还没有内容哦……

- {% else %} - {% for key, section in sections_hash %} -
- -
-
    - {% for s in section.2 %} -
  • - {{ s.title }} -
  • - {% endfor %} -
-
-
- {% endfor %} - {% endif %} -
-
- -
-
-

Rust 项目专题

-
- {% if proj_sections_len == 0 %} -

这里还没有内容哦……

- {% else %} -
- {% for key, section in projects_hash %} -
- -
-
    - {% for s in section.2 %} -
  • - {{ s.title }} -
  • - {% endfor %} -
-
-
- {% endfor %} - {% endif %} -
-
-
-
-{% endblock content %} +{% extends "base.html" %} + +{% block title %} +Rust语言中文社区-首页 +{% endblock title %} + +{% block content %} + + + + +
+ +
+ {% if title and desc %} +

{{ title }}

+

{{ desc }}

+ {% endif %} +
+ +
+ +
+ {% if blogs | length == 0 %} +

这里还没有内容哦……

+ {% else %} + + {% endif %} +
+
+ +
+ {% if cate_sections_len == 0 %} +

这里还没有内容哦……

+ {% else %} + {% for key, section in sections_hash %} +
+ +
+
    + {% for s in section.2 %} +
  • + {{ s.title }} +
  • + {% endfor %} +
+
+
+ {% endfor %} + {% endif %} +
+
+ +
+
+

Rust 项目专题

+
+ {% if proj_sections_len == 0 %} +

这里还没有内容哦……

+ {% else %} +
+ {% for key, section in projects_hash %} +
+ +
+
    + {% for s in section.2 %} +
  • + {{ s.title }} +
  • + {% endfor %} +
+
+
+ {% endfor %} + {% endif %} +
+
+
+
+{% endblock content %}