From 9cb68397b9fd3b8cfe7b4eeee4b4327e1796a87d Mon Sep 17 00:00:00 2001 From: masnn Date: Tue, 14 Apr 2020 16:45:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=87=AA=E5=8A=A8=E6=9E=84?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 53 +++++++++++++++++++++++++++++++++++++ .gitignore | 3 ++- Dockerfile | 7 +++++ docker-compose.yml | 16 +++++++++++ hydro/install.js | 2 +- hydro/interface.js | 1 - hydro/options.js | 14 ++++++---- package.json | 28 ++++++++++++++++---- webpack.config.js | 16 +++++++++++ 9 files changed, 127 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 webpack.config.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..c30aefaa --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,53 @@ +name: DockerBuild +on: + push: + branches: + - master +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node_version: '13.x' + - run: | + yarn + yarn add webpack webpack-cli -D + yarn build + - uses: actions/upload-artifact@v1 + with: + name: hydro + path: dist + - run: | + cd ui + yarn + yarn add webpack webpack-cli -D + yarn build + cd .. + - uses: actions/upload-artifact@v1 + with: + name: .uibuild + path: .uibuild + - run: | + yarn add pkg -D + yarn run pack + - uses: actions/upload-artifact@v1 + with: + name: Hydro_linux_amd64 + path: hydro-linux + - uses: actions/upload-artifact@v1 + with: + name: Hydro_macos_amd64 + path: hydro-macos + - uses: actions/upload-artifact@v1 + with: + name: Hydro_win_amd64.exe + path: hydro-win.exe + - uses: elgohr/Publish-Docker-Github-Action@master + with: + name: hydrooj/hydro:alpine + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + dockerfile: Dockerfile diff --git a/.gitignore b/.gitignore index 6d701d2b..b6686232 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ __* ui/misc/.iconfont ui/static/locale .webpackStats.json -.cache \ No newline at end of file +.cache +dist/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..89d88097 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM mhart/alpine-node:slim-10 +WORKDIR /app +ADD .uibuild dist locales templates /app/ +RUN mkdir /config +VOLUME [ "/config" ] +EXPOSE 8888 +CMD ["node", "dist/development.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..4aed184f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3' +services: + hydro: + image: hydrooj/hydro:latest + restart: always + links: + - mongo + volumes: + - ./config.yaml:/config/config.yaml + ports: + - 8888:8888 + mongo: + image: mongo:latest + restart: always + volumes: + - ./db:/data/db diff --git a/hydro/install.js b/hydro/install.js index 8cb493b3..302360e0 100644 --- a/hydro/install.js +++ b/hydro/install.js @@ -5,7 +5,7 @@ const builtin = require('./model/builtin'), pwhash = require('./lib/pwhash'), options = require('./options'), - { udoc } = require('../interfaces'); + { udoc } = require('./interface'); async function run() { let mongourl = 'mongodb://'; diff --git a/hydro/interface.js b/hydro/interface.js index b804ebed..d023ec33 100644 --- a/hydro/interface.js +++ b/hydro/interface.js @@ -1,4 +1,3 @@ -const { ObjectID } = require('bson'); exports.udoc = { _id: 0, mail: '', diff --git a/hydro/options.js b/hydro/options.js index a02b45db..0c817dad 100644 --- a/hydro/options.js +++ b/hydro/options.js @@ -1,8 +1,9 @@ const - yaml = require('js-yaml'), - { defaultsDeep } = require('lodash'), fs = require('fs'), - path = require('path'); + os = require('os'), + path = require('path'), + yaml = require('js-yaml'), + { defaultsDeep } = require('lodash'); let options = { db: { @@ -46,9 +47,12 @@ let options = { }; try { - let t = yaml.safeLoad(fs.readFileSync(path.resolve(process.cwd(), 'config.yaml'))); + let f = path.resolve(process.cwd(), 'config.yaml'); + if (!fs.existsSync(f)) f = path.resolve(os.homedir(), '.config', 'hydro', 'config.yaml'); + if (!fs.existsSync(f)) f = path.resolve('/config/config.yaml'); + let t = yaml.safeLoad(fs.readFileSync(f)); options = defaultsDeep(t, options); } catch (e) { console.error('Cannot load config'); } -module.exports = options; \ No newline at end of file +module.exports = options; diff --git a/package.json b/package.json index dd9b9ee4..e001eaaf 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { - "name": "hydrofrontend", + "name": "hydro", "version": "0.0.0", - "main": "vj5/development.js", - "repository": "https://github.com/masnn/vj5.git", + "main": "hydro/development.js", + "repository": "https://github.com/hydro-dev/Hydro.git", "author": "masnn", - "license": "MIT", + "license": "GPL-3.0-only", "dependencies": { "axios": "^0.19.0", "bson": "^4.0.2", @@ -25,5 +25,23 @@ }, "devDependencies": { "eslint": "^6.6.0" + }, + "scripts": { + "build": "webpack --config webpack.config.js", + "pack": "pkg .", + "lint": "eslint judger --fix" + }, + "pkg": { + "scripts": [ + "hydro/**.js" + ], + "assets": [ + ".uibuild/*", + "locales/*", + "templates/*" + ] + }, + "bin": { + "judger": "hydro/development.js" } -} +} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 00000000..a678f883 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,16 @@ +const config = { + mode: 'production', + entry: { + development: './hydro/development.js', + install: './hydro/install.js', + uninstall: './hydro/uninstall.js' + }, + output: { + filename: '[name].js', + path: __dirname + '/dist' + }, + target: 'node', + module: {} +}; + +module.exports = config;