Skip to content
Open
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
13 changes: 13 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
63 changes: 63 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:

37 changes: 37 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
29 changes: 29 additions & 0 deletions docs/getting_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions migrations/2018-01-06-074038_users_custom_css/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Remove custom css column`

ALTER TABLE ruser
DROP COLUMN custom_css

4 changes: 4 additions & 0 deletions migrations/2018-01-06-074038_users_custom_css/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Create column for custom css

ALTER TABLE ruser
ADD custom_css VARCHAR
5 changes: 5 additions & 0 deletions src/models/rusers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub custom_css: Option<String>,
}

impl RawUser {
Expand All @@ -42,6 +43,7 @@ impl RawUser {
signup_time: self.signup_time,
role: self.role,
github: self.github,
custom_css: self.custom_css,
}
}
}
Expand All @@ -57,6 +59,7 @@ pub struct RUser {
pub signup_time: NaiveDateTime,
pub role: i16,
pub github: Option<String>,
pub custom_css: Option<String>,
}

impl RUser {
Expand Down Expand Up @@ -241,6 +244,7 @@ pub struct EditUser {
pub say: Option<String>,
pub avatar: Option<String>,
pub wx_openid: Option<String>,
pub custom_css: Option<String>,
}

impl EditUser {
Expand All @@ -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::<RawUser>(conn);
match res {
Expand Down
4 changes: 3 additions & 1 deletion static/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions views/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
</style>
</head>
<body>
Expand Down
6 changes: 6 additions & 0 deletions views/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ <h3>用户信息</h3>
<div><label>签名:</label>
<p style="display:inline;" class="say">{{ user.say }}</p>
</div>
<div><label>自定义CSS:</label>
<p style="display:inline;" class="custom_css">{{ user.custom_css }}</p>
</div>
<div><label>创建时间:</label><p style="display:inline;" class="signup_time">{{ user.signup_time }}</p></div>
<br />
</div>
Expand All @@ -49,6 +52,9 @@ <h3>修改信息</h3>
<div class="form-group">
<label>签名:</label><textarea id="say" rows="5"></textarea>
</div>
<div class="form-group">
<label>自定义CSS:</label><textarea id="custom_css" rows="10"></textarea>
</div>
<div class="form-group">
<label>头像地址:</label><input id="avatar" type="text">
</div>
Expand Down
Loading