Add deploy files; Add about view.

This commit is contained in:
zema1 2017-10-24 21:16:00 +08:00
parent 610ead513a
commit 06e007801a
19 changed files with 275 additions and 8786 deletions

View File

@ -7,7 +7,7 @@ module.exports = {
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
assetsPublicPath: '/admin',
productionSourceMap: true,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.

8
deploy/Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM node:6.11-alpine
RUN apk add --no-cache nginx git python build-base
VOLUME [ "/OJ_FE", "/var/log/nginx/", "/data/avatar"]
EXPOSE 80
CMD ["/bin/sh", "/OJ_FE/deploy/run.sh"]

116
deploy/nginx.conf Normal file
View File

@ -0,0 +1,116 @@
user nginx;
# Set number of worker processes automatically based on number of CPU cores.
worker_processes auto;
# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;
# Configures default error logger.
error_log /var/log/nginx/nginx_error.log warn;
daemon off;
# set pid path
pid /tmp/nginx.pid;
# Includes files with directives to load dynamic modules.
include /etc/nginx/modules/*.conf;
events {
# The maximum number of simultaneous connections that can be opened by
# a worker process.
worker_connections 1024;
}
http {
# Includes mapping of file name extensions to MIME types of responses
# and defines the default type.
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Name servers used to resolve names of upstream servers into addresses.
# It's also needed when using tcpsocket and udpsocket in Lua modules.
#resolver 208.67.222.222 208.67.220.220;
# Don't tell nginx version to clients.
server_tokens off;
# Specifies the maximum accepted body size of a client request, as
# indicated by the request header Content-Length. If the stated content
# length is greater than this size, then the client receives the HTTP
# error code 413. Set to 0 to disable.
client_max_body_size 100m;
# Timeout for keep-alive connections. Server will close connections after
# this time.
keepalive_timeout 10;
# Sendfile copies data between one FD and other from within the kernel,
# which is more efficient than read() + write().
sendfile on;
# Don't buffer data-sends (disable Nagle algorithm).
# Good for sending frequent small bursts of data in real time.
tcp_nodelay on;
# Causes nginx to attempt to send its HTTP response head in one packet,
# instead of using partial frames.
#tcp_nopush on;
# Path of the file with Diffie-Hellman parameters for EDH ciphers.
#ssl_dhparam /etc/ssl/nginx/dh2048.pem;
# Specifies that our cipher suits should be preferred over client ciphers.
ssl_prefer_server_ciphers on;
# Enables a shared SSL cache with size that can hold around 8000 sessions.
ssl_session_cache shared:SSL:2m;
# Enable gzipping of responses.
gzip on;
gzip_types application/javascript text/css;
# Set the Vary HTTP header as defined in the RFC 2616.
gzip_vary on;
# Enable checking the existence of precompressed files.
#gzip_static on;
# Specifies the main log format.
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# Sets the path, format, and configuration for a buffered log write.
# access_log /var/log/nginx/access.log main;
access_log off;
server {
listen 80 default_server;
server_name _;
location /static/avatar {
expires max;
alias /data/avatar;
}
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_pass http://oj_backend:8080;
}
location /admin {
alias /OJ_FE/admin/dist;
try_files $uri $uri/ /admin/index.html;
}
location / {
root /OJ_FE/oj/dist;
try_files $uri $uri/ /index.html;
}
}
}

21
deploy/run.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/sh
run_build() {
cd $1
npm install --registry=https://registry.npm.taobao.org && \
npm run build
if [ $? -ne 0 ]; then
echo "Build error, please check node version and package.json"
exit 1
fi
echo "Build success, dist files in $1/dist\n"
}
sleep 3
run_build /OJ_FE/oj
run_build /OJ_FE/admin
exec nginx -c /OJ_FE/deploy/nginx.conf

View File

@ -47,7 +47,7 @@ module.exports = {
},
{
test: /\.js$/,
loader: 'babel-loader?cacheDirectory',
loader: 'babel-loader?cacheDirectory=true',
exclude: /node_modules/,
include: [resolve('src'), resolve('test')]
},

View File

@ -1,6 +1,12 @@
var merge = require('webpack-merge')
var prodEnv = require('./prod.env')
const merge = require('webpack-merge')
module.exports = merge(prodEnv, {
NODE_ENV: '"development"'
})
let date = require('moment')().format('YYYYMMDD')
let commit = require('child_process').execSync('git rev-parse HEAD').toString().slice(0, 5)
let version = `"${date}-${commit}"`
console.log(`current version is ${version}`)
module.exports = {
NODE_ENV: '"development"',
VERSION: version
}

View File

@ -1,10 +1,3 @@
let date = require('moment')().format('YYYYMMDD')
let commit = require('child_process').execSync('git rev-parse HEAD').toString().slice(0, 5)
let version = `"${date}-${commit}"`
console.log(`current version is ${version}`)
module.exports = {
NODE_ENV: '"production"',
VERSION: version
}

View File

@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>OnlineJudge</title>
</head>
<body>
<body style="background: #eee">
<div id="app"></div>
<!-- built files will be auto injected -->
</body>

8753
oj/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -55,7 +55,7 @@
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"http-proxy-middleware": "^0.17.3",
"less": "^3.0.0-alpha.3",
"less": "^2.7.3",
"less-loader": "^4.0.5",
"opn": "^5.1.0",
"optimize-css-assets-webpack-plugin": "^3.2.0",

View File

@ -26,6 +26,7 @@
</template>
<script>
import { codemirror } from 'vue-codemirror-lite'
import api from '@/api'
// theme
import 'codemirror/theme/monokai.css'
@ -64,11 +65,11 @@
},
data () {
return {
lang: 'C++',
lang: 'C',
options: {
// codemirror options
tabSize: 4,
mode: 'text/x-c++src',
mode: 'text/x-csrc',
theme: 'solarized',
lineNumbers: true,
line: true,
@ -81,10 +82,7 @@
highlightSelectionMatches: {showToken: /\w/, annotateScrollbar: true}
},
mode: {
'C': 'text/x-csrc',
'C++': 'text/x-c++src',
'Java': 'text/x-java',
'Python2': 'text/x-python'
'C': 'text/x-csrc'
},
themes: [
{label: 'Monokai', value: 'monokai'},
@ -94,9 +92,19 @@
}
},
mounted () {
this.getLanguages()
this.editor.focus()
},
methods: {
getLanguages () {
api.getLanguages().then(res => {
let mode = {}
res.data.data.languages.forEach(language => {
mode[language.name] = language.content_type
})
this.mode = mode
})
},
onEditorCodeChange (newCode) {
this.$emit('update:value', newCode)
},

View File

@ -30,7 +30,7 @@
OI Rank
</Menu-item>
</Submenu>
<Menu-item name="/4">
<Menu-item name="/about">
<Icon type="information-circled"></Icon>
About
</Menu-item>
@ -115,7 +115,7 @@
left: 0;
height: 60px;
width: 100%;
z-index: 10;
z-index: 1000;
background-color: #fff;
box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.1);
.oj-menu {

View File

@ -90,8 +90,8 @@ Vue.component(Panel.name, Panel)
Vue.prototype.$Message.config({
duration: 2
})
Vue.prototype.$error = Vue.prototype.$Message.error
Vue.prototype.$info = Vue.prototype.$Message.info
Vue.prototype.$success = Vue.prototype.$Message.success
Vue.prototype.$error = (s) => Vue.prototype.$Message.error(s)
Vue.prototype.$info = (s) => Vue.prototype.$Message.info(s)
Vue.prototype.$success = (s) => Vue.prototype.$Message.success(s)
new Vue(Vue.util.extend({router, store}, App)).$mount('#app')

View File

@ -1,6 +1,6 @@
// all routes here.
import {
Home, Logout,
Home, Logout, About,
ProblemList, Problem,
SubmissionList, SubmissionDetails,
ACMRank, OIRank,
@ -125,6 +125,11 @@ export default [
component: Setting.SecuritySetting
}
]
},
{
path: '/about',
name: 'about',
component: About
}
// {
// path: '*', redirect: '/problems'

View File

@ -93,6 +93,7 @@ const mutations = {
},
[types.CLEAR_CONTEST] (state) {
state.contest = {created_by: {}}
state.contestProblems = []
},
[types.NOW] (state, payload) {
state.now = payload.now

View File

@ -0,0 +1,75 @@
<template>
<div>
<panel :padding="15" class="container">
<div slot="title">Compiler & Judger</div>
<div class="content">
<ul>
<li>C (GCC 4.8)
<pre>gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c99 {src_path} -lm -o {exe_path}</pre>
</li>
<li>C++ (G++ 4.8)
<pre>g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++11 {src_path} -lm -o {exe_path}</pre>
</li>
<li>JAVA (OpenJDK 1.7)
<pre>
javac {src_path} -d {exe_dir} -encoding UTF8
java -cp {exe_dir} -Xss1M -Xms16M -Xmx{max_memory}k -Djava.security.manager -Djava.security.policy=={policy} -Djava.awt.headless=true Main</pre>
</li>
<li>Python (Python2.7)
<pre>python -m py_compile {src_path}</pre>
</li>
</ul>
</div>
</panel>
<panel :padding="15" class="container">
<div slot="title">Result Explanation</div>
<div class="content">
<ul>
<li><b>Pending & Juding</b> : You solution will be judged soon, please wait for result</li>
<li><b>Compile Error</b> : Failed to compile your source code. Click on the link to see compiler's output.
</li>
<li><b>Accepted</b> : Congratulations. Your solution is correct.</li>
<li><b>Wrong Answer</b> : Your program's output doesn't match judger's answer.</li>
<li>
<b>Runtime Error</b>
: Your program terminated abnormally. Possible reasons are: segment fault, divided by zero or exited with code other than 0.
</li>
<li><b>Time Limit Exceeded</b>
: The CPU time your program used has exceeded limit. Java has a triple time limit.
</li>
<li><b>Memory Limit Exceeded</b> : The memory your program actually used has exceeded limit.</li>
<li><b>System Error</b> : Oops, something has gone wrong with the judger. Please report this to administrator.
</li>
</ul>
</div>
</panel>
</div>
</template>
<script>
</script>
<style scoped lang="less">
.container {
margin-bottom: 20px;
.content {
margin: 0 50px 20px 50px;
> ul {
list-style: disc;
li {
line-height: 1.8;
.title {
font-weight: 500;
}
}
}
}
}
</style>

View File

@ -1,6 +1,7 @@
import ProblemList from './problem/ProblemList.vue'
import Logout from './user/Logout.vue'
import Home from './user/Home.vue'
import About from './about/About.vue'
// Grouping Components in the Same Chunk
const SubmissionList = () => import(/* webpackChunkName: "submission" */ '@/views/submission/SubmissionList.vue')
@ -15,7 +16,7 @@ const ResetPassword = () => import(/* webpackChunkName: "password" */ '@/views/u
const Problem = () => import(/* webpackChunkName: "Problem" */ '@/views/problem/Problem.vue')
export {
Logout, Home,
Logout, Home, About,
ProblemList, Problem,
ACMRank, OIRank,
SubmissionList, SubmissionDetails,

View File

@ -40,7 +40,7 @@
</Panel>
<!--problem main end-->
<Card :padding="20" id="submit-code" dis-hover>
<CodeMirror :value.sync="code" @changeLang="onChangeLang"></CodeMirror>
<CodeMirror :value.sync="code" @changeLang="onChangeLang" :languages="problem.languages"></CodeMirror>
<Row type="flex" justify="space-between">
<Col :span="10">
<div class="status" v-if="statusVisible && contestRuleType !== 'OI'">
@ -53,7 +53,7 @@
<Alert type="success" show-icon>You have solved the problem</Alert>
</div>
<div class="status" v-if="problemSubmitDisabled">
<div class="status" v-if="contestEnded">
<Alert type="warning" show-icon>Contest have ended</Alert>
</div>
</Col>
@ -151,7 +151,7 @@
import { types } from '@/store'
import CodeMirror from '@/components/CodeMirror'
import api from '@/api'
import { JUDGE_STATUS } from '@/utils/consts'
import { JUDGE_STATUS, CONTEST_STATUS_REVERSE } from '@/utils/consts'
import { pie, largePie } from './chartData'
@ -178,6 +178,7 @@
description: '',
hint: '',
my_status: '',
languages: [],
created_by: {
username: ''
}
@ -291,10 +292,13 @@
}
},
computed: {
...mapGetters(['problemSubmitDisabled', 'contestRuleType', 'OIContestRealTimePermission']),
...mapGetters(['problemSubmitDisabled', 'contestRuleType', 'OIContestRealTimePermission', 'contestStatus']),
contest () {
return this.$store.state.contest.contest
},
contestEnded () {
return this.contestStatus === CONTEST_STATUS_REVERSE.ENDED
},
submissionStatus () {
return {
text: JUDGE_STATUS[this.result.result]['name'],

View File

@ -150,4 +150,8 @@
margin-top: 5px;
margin-right: 10px;
}
pre {
border: none;
background: none;
}
</style>