From 2ac6cdf69d9a32ff5084b49936e9dd6bdcd0cc80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Fri, 2 Sep 2022 11:15:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E7=BD=B2=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - Dockerfile | 33 +++++++++++++++++ Gemfile | 4 +-- Gemfile.lock | 24 +++++++++++-- README.md | 88 +++++++++++++++++++++++++++++++--------------- docker-compose.yml | 13 ++++--- 6 files changed, 125 insertions(+), 38 deletions(-) create mode 100644 Dockerfile diff --git a/.gitignore b/.gitignore index 2eac1d277..4a01bd5ec 100644 --- a/.gitignore +++ b/.gitignore @@ -81,7 +81,6 @@ db/bak/ docker/ educoder.sql redis_data/ -Dockerfile dump.rdb .tags* ceshi_user.xlsx diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..236e36935 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM ubuntu:18.04 + +RUN apt update + +RUN apt install -y openssl libssl-dev imagemagick git ruby-dev nodejs libmariadb-dev libmysqlclient-dev shared-mime-info libpq-dev libxml2-dev libxslt-dev +RUN DEBIAN_FRONTEND="noninteractive" apt -y install tzdata +RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime + +WORKDIR /home/app/gitlink + +ADD ./ /home/app/gitlink + +RUN gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ + +RUN gem update --system + +RUN gem install bundler +RUN gem install rake + +RUN rm -rf Gemfile.lock + +#RUN cp config/configuration.yml.example config/configuration.yml +#RUN cp config/database.yml.example config/database.yml +#RUN touch config/redis.yml +#RUN touch config/elasticsearch.yml + +RUN bundle install + +EXPOSE 4000 +RUN rails s -p 4000 -b '0.0.0.0' + + + diff --git a/Gemfile b/Gemfile index 3da6f273d..9ae0f0505 100644 --- a/Gemfile +++ b/Gemfile @@ -98,9 +98,9 @@ gem 'font-awesome-sass', '4.7.0' gem 'rails-i18n', '~> 5.1' # job -gem 'sidekiq' +gem 'sidekiq',"5.2.8" gem 'sinatra' -gem "sidekiq-cron", "~> 1.1" +gem "sidekiq-cron", "1.2.0" # batch insert gem 'bulk_insert' diff --git a/Gemfile.lock b/Gemfile.lock index e27c504aa..ee0c909a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,6 +106,8 @@ GEM activerecord (>= 3.1.0, < 7) diff-lcs (1.3) diffy (3.3.0) + domain_name (0.5.20190701) + unf (>= 0.0.5, < 1.0.0) doorkeeper (5.5.1) railties (>= 5) doorkeeper-jwt (0.4.1) @@ -133,6 +135,8 @@ GEM fugit (1.4.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) + gitea-client (0.10.5) + rest-client (~> 2.1.0) globalid (0.4.2) activesupport (>= 4.2.0) grape-entity (0.7.1) @@ -143,6 +147,9 @@ GEM harmonious_dictionary (0.0.1) hashie (3.6.0) htmlentities (4.3.4) + http-accept (1.7.0) + http-cookie (1.0.5) + domain_name (~> 0.5) i18n (1.8.2) concurrent-ruby (~> 1.0) io-like (0.3.1) @@ -180,6 +187,9 @@ GEM mimemagic (~> 0.3.2) maruku (0.7.3) method_source (0.9.2) + mime-types (3.4.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2022.0105) mimemagic (0.3.10) nokogiri (~> 1) rake @@ -193,6 +203,7 @@ GEM mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) + netrc (0.11.0) nio4r (2.5.2) nokogiri (1.10.8) mini_portile2 (~> 2.4.0) @@ -292,6 +303,11 @@ GEM regexp_parser (1.7.0) request_store (1.5.0) rack (>= 1.4) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) reverse_markdown (1.4.0) nokogiri roo (2.8.3) @@ -418,6 +434,9 @@ GEM thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.8.2) unicode-display_width (1.6.1) web-console (3.7.0) actionview (>= 5.0) @@ -459,6 +478,7 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) + gitea-client (~> 0.10.2) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) @@ -496,8 +516,8 @@ DEPENDENCIES sass-rails (~> 5.0) searchkick selenium-webdriver - sidekiq - sidekiq-cron (~> 1.1) + sidekiq (= 5.2.8) + sidekiq-cron (= 1.2.0) simple_form simple_xlsx_reader sinatra diff --git a/README.md b/README.md index 26761e767..ef86a4c35 100644 --- a/README.md +++ b/README.md @@ -34,18 +34,52 @@ GitLink(确实开源)是中国计算机学会(CCF)官方指定的开源 * imagemagick ### 步骤 - -(1)克隆稳定版本 +(1)安装 Rails 必要的一些三方库: +- Mac OS X +```bash + brew install imagemagick ghostscript libxml2 libxslt libiconv ``` + +- Ubuntu +```bash +sudo apt-get update +sudo apt-get install -y openssl libssl-dev imagemagick git ruby-dev nodejs libmariadb-dev libmysqlclient-dev shared-mime-info libpq-dev libxml2-dev libxslt-dev +sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y tzdata +sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +``` + +(2)安装 Ruby, Rails 运行环境:[如何快速正确的安装 Ruby, Rails 运行环境](https://ruby-china.org/wiki/install_ruby_guide) +```bash +#检验环境是否正确 +ruby -v +#ruby 2.4.x ... + +gem -v +#3.x.x + +bundle -v +#Bundler version 2.x.x + +rails -v +#Rails 5.2.x +``` + +(3)克隆稳定版本 +```bash git clone -b master https://gitlink.org.cn/Gitlink/forgeplus.git ``` -(2)安装依赖包 +(4)安装依赖包 ```bash -cd forgeplus && bundle install +#进入目录 +cd forgeplus +#删除Gemfile.lock +rm -rf Gemfile.lock +#安装依赖包 +bundle install ``` -(3)配置初始化文件:进入项目根目录执行以下命令 +(5)配置初始化文件:进入项目根目录执行以下命令 ```bash cp config/configuration.yml.example config/configuration.yml cp config/database.yml.example config/database.yml @@ -53,8 +87,8 @@ touch config/redis.yml touch config/elasticsearch.yml ``` -(4)配置数据库:数据库配置信息请查看/config/database.yml文件,项目默认采用mysql数据库, 如需更改,请自行修改配置信息,默认配置如下 -```bash +(6)配置数据库:数据库配置信息请查看/config/database.yml文件,项目默认采用mysql数据库, 如需更改,请自行修改配置信息,默认配置如下 +```yaml default: &default adapter: mysql2 host: 127.0.0.1 @@ -63,7 +97,7 @@ default: &default password: 123456 ``` -(5)配置gitea服务(可选):如需要部署自己的gitea平台,请参考[gitea官方平台文档](https://docs.gitea.io/zh-cn/install-from-binary/)。因目前gitea平台api受限,暂时推荐从forge平台获取[gitea部署文件](https://www.gitlink.org.cn/Gitlink/gitea-binary)进行部署 +(7)配置gitea服务(可选):如需要部署自己的gitea平台,请参考[gitea官方平台文档](https://docs.gitea.io/zh-cn/install-from-binary/)。因目前gitea平台api受限,暂时推荐从forge平台获取[gitea部署文件](https://www.gitlink.org.cn/Gitlink/gitea-binary)进行部署 - 配置gitea服务步骤: @@ -71,7 +105,7 @@ default: &default -- 修改forge平台的 config/configuration.yml中的gitea服务指向地址,如: -```ruby +```yaml gitea: access_key_id: 'root' access_key_secret: 'password' @@ -79,61 +113,59 @@ gitea: base_url: '/api/v1' ``` -(6)安装redis环境:请自行搜索各平台如何安装部署redis环境 +(8)配置/config/database.yml文件(安装redis环境:请自行搜索各平台如何安装部署redis环境) +```yaml +default: &default + url: redis://localhost:6379 + db: 1 -(7)安装imagemagick插件: -- Mac OS X -```bash - brew install imagemagick ghostscript +production: + <<: *default + url: redis://localhost:6379 ``` -- Linux -```bash -sudo apt-get install -y imagemagick -``` - -(8)创建数据库:开发环境为development, 生成环境为production +(9)创建数据库:开发环境为development, 生成环境为production ```bash rails db:create RAILS_ENV=development ``` -(9)导入数据表结构 +(10)导入数据表结构 ```bash bundle exec rake sync_table_structure:import_csv ``` -(10)执行migrate迁移文件:开发环境为development, 生成环境为production +(11)执行migrate迁移文件:开发环境为development, 生成环境为production ```bash rails db:migrate RAILS_ENV=development ``` -(11)clone前端代码:将前端代码克隆到public/react目录下,目录结构应该是: public/react/build +(12)clone前端代码:将前端代码克隆到public/react目录下,目录结构应该是: public/react/build ```bash git clone -b standalone https://gitlink.org.cn/Gitlink/build.git ``` -(12)启动redis(此处以macOS系统为例) +(13)启动redis(此处以macOS系统为例) ```bash redis-server& ``` -(13)启动sidekiq:开发环境为development, 生成环境为production +(14)启动sidekiq:开发环境为development, 生成环境为production ```bash bundle exec sidekiq -C config/sidekiq.yml -e production -d ``` -(14)启动rails服务 +(15)启动rails服务 ```bash rails s ``` -(15)浏览器访问:在浏览器中输入如下地址访问 +(16)浏览器访问:在浏览器中输入如下地址访问 ```bash http://localhost:3000/ ``` -(16)其他说明:通过页面注册以第一个用户为平台管理员用户 +(17)其他说明:通过页面注册以第一个用户为平台管理员用户 ## 页面展示 diff --git a/docker-compose.yml b/docker-compose.yml index 16f600df4..ef066bc16 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: MYSQL_DATABASE: educoder redis: - image: redis:3.2 + image: redis:6.2.5 container_name: redis restart: always ports: @@ -22,14 +22,17 @@ services: - ./redis_data:/data web: - image: guange/educoder:latest - command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 4000 -b '0.0.0.0'" + image: gitlink-ubuntu18.04:latest + build: + context: ../ + dockerfile: Dockerfile +# command: bash -c "rm -f tmp/pids/server.pid && rails s -p 4000 -b '0.0.0.0'" stdin_open: true tty: true volumes: - - .:/app + - .:/home/app/gitlink ports: - "4000:4000" depends_on: - mysql - - redis \ No newline at end of file + - redis