Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Ubuntu 22.04 and Ruby3 #6672

Merged
merged 12 commits into from
Aug 2, 2023
Merged
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
5 changes: 3 additions & 2 deletions .dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:focal AS base
FROM ubuntu:jammy AS base

ARG NODE_MAJOR=18
ARG BUNDLER_VERSION='2.3.17'
ARG BUNDLER_VERSION='2.4.13'
ARG USER=markus

# Required in order to ensure bind-mounts are owned by the correct user inside the container
Expand Down Expand Up @@ -69,6 +69,7 @@ ENV PATH="$GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH"
RUN apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends openssh-server \
python3 \
python3-dev \
python3-venv \
equivs

Expand Down
1 change: 1 addition & 0 deletions .dockerfiles/entrypoint-dev-rails.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ npm list &> /dev/null || npm ci
./venv/bin/python3 -m pip install --upgrade pip > /dev/null
./venv/bin/python3 -m pip install -r requirements-jupyter.txt > /dev/null
./venv/bin/python3 -m pip install -r requirements-scanner.txt > /dev/null
./venv/bin/python3 -m pip install -r requirements-qr.txt > /dev/null

# setup the database (checks for db existence first)
until pg_isready -q; do
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ on:
jobs:
test:
if: github.event.pull_request.draft == false
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
services:
postgres:
image: postgres:12
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Set up ruby and cache gems
uses: ruby/setup-ruby@v1
with:
ruby-version: ruby-2.7
ruby-version: ruby-3.0
bundler-cache: true
- name: Set up node and cache packages
uses: actions/setup-node@v3
Expand All @@ -66,13 +66,13 @@ jobs:
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements-jupyter.txt') }}-${{ hashFiles('requirements-scanner.txt') }}
key: ${{ runner.os }}-pip-${{ hashFiles('requirements-jupyter.txt') }}-${{ hashFiles('requirements-scanner.txt') }}-${{ hashFiles('requirements-qr.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install python packages
run: |
python3.9 -m venv venv
./venv/bin/pip install -r requirements-jupyter.txt -r requirements-scanner.txt
./venv/bin/pip install -r requirements-jupyter.txt -r requirements-scanner.txt -r requirements-qr.txt
- name: Configure server
run: |
sudo rm -f /etc/localtime
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
finish:
needs: test
if: github.event.pull_request.draft == false
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ gem 'redis', '~> 4.8.1'
gem 'combine_pdf'
gem 'prawn'
gem 'prawn-qrcode'
gem 'rmagick'
gem 'rmagick', '~> 5.2.0'
gem 'rtesseract'
gem 'zxing_cpp', require: 'zxing'

# Ruby miscellany
gem 'json'
Expand Down
20 changes: 9 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
chunky_png (1.3.12)
chunky_png (1.4.0)
combine_pdf (1.0.23)
matrix
ruby-rc4 (>= 0.1.5)
Expand Down Expand Up @@ -260,6 +260,7 @@ GEM
ast (~> 2.4.1)
pdf-core (0.9.0)
pg (1.5.3)
pkg-config (1.5.2)
pluck_to_hash (1.0.2)
activerecord (>= 4.0.2)
activesupport (>= 4.0.2)
Expand Down Expand Up @@ -349,12 +350,13 @@ GEM
resque (>= 1.27)
rufus-scheduler (~> 3.2, != 3.3)
rexml (3.2.5)
rmagick (2.16.0)
rmagick (5.2.0)
pkg-config (~> 1.4)
rouge (4.1.1)
rqrcode (1.1.2)
rqrcode (2.2.0)
chunky_png (~> 1.0)
rqrcode_core (~> 0.1)
rqrcode_core (0.1.2)
rqrcode_core (~> 1.0)
rqrcode_core (1.2.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
Expand Down Expand Up @@ -451,9 +453,6 @@ GEM
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.8)
zxing_cpp (0.1.1)
ffi (~> 1.1)
rmagick (~> 2.13)

PLATFORMS
ruby
Expand Down Expand Up @@ -509,7 +508,7 @@ DEPENDENCIES
responders
resque
resque-scheduler
rmagick
rmagick (~> 5.2.0)
rspec-rails (~> 6.0.3)
rtesseract
rubyzip
Expand All @@ -526,7 +525,6 @@ DEPENDENCIES
time-warp
unicorn
webmock
zxing_cpp

BUNDLED WITH
2.3.17
2.4.13
21 changes: 14 additions & 7 deletions app/jobs/split_pdf_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,23 @@ def perform(exam_template, _path, split_pdf_log, _original_filename = nil, _curr
original_pdf = File.binread(File.join(raw_dir, "#{split_page.id}.pdf"))

# convert PDF to an image
img = Magick::Image.from_blob(original_pdf) do
self.quality = 100
self.density = '200'
img = Magick::Image.from_blob(original_pdf) do |options|
options.quality = 100
options.density = '200'
end.first

qr_file_location = File.join(raw_dir, "#{split_page.id}.jpg")
img.crop(Magick::NorthWestGravity, img.columns, img.rows / 5.0).write(qr_file_location)
img.destroy!
code_regex = /(?<short_id>[\w-]+)-(?<exam_num>\d+)-(?<page_num>\d+)/
m = code_regex.match(ZXing.decode(qr_file_location)) || code_regex.match(RTesseract.new(qr_file_location).to_s)
python_exe = Rails.application.config.python
read_qr_py_file = Rails.root.join('lib/scanner/read_qr_code.py').to_s
stdout, status = Open3.capture2(python_exe, read_qr_py_file, qr_file_location)
if status.success?
m = code_regex.match(stdout)
else
m = code_regex.match(RTesseract.new(qr_file_location).to_s)
end
status = ''

david-yz-liu marked this conversation as resolved.
Show resolved Hide resolved
if m.nil?
Expand Down Expand Up @@ -234,9 +241,9 @@ def save_pages(exam_template, partial_exams, filename = nil, split_pdf_log = nil
next unless exam_template.automatic_parsing && Rails.application.config.scanner_enabled
begin
# convert PDF to an image
imglist = Magick::Image.from_blob(cover_pdf.to_pdf) do
self.quality = 100
self.density = '300'
imglist = Magick::Image.from_blob(cover_pdf.to_pdf) do |options|
options.quality = 100
options.density = '300'
end
rescue StandardError
next
Expand Down
2 changes: 1 addition & 1 deletion app/lib/markus_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def self.parse(input, **options)
if options[:encoding]
input = input.encode(Encoding::UTF_8, options[:encoding])
end
CSV.parse(input, options) do |row|
CSV.parse(input, **options) do |row|
yield row
valid_line_count += 1
rescue CsvInvalidLineError => e
Expand Down
3 changes: 2 additions & 1 deletion app/models/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def summary_test_result_json
# Generate a CSV summary of the most recent test results associated with an assignment.
def summary_test_result_csv
results = {}
headers = SortedSet.new
headers = Set.new
summary_test_results = self.summary_test_results.as_json

summary_test_results.each do |test_result|
Expand All @@ -648,6 +648,7 @@ def summary_test_result_csv

headers << header
end
headers = headers.sort

CSV.generate do |csv|
csv << [nil, *headers]
Expand Down
6 changes: 3 additions & 3 deletions app/models/exam_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ def save_cover
cover = pdf.pages[0]
cover_page = CombinePDF.new
cover_page << cover
imglist = Magick::Image.from_blob(cover_page.to_pdf) do
self.quality = 100
self.density = '300'
imglist = Magick::Image.from_blob(cover_page.to_pdf) do |options|
options.quality = 100
options.density = '300'
end
imglist.first.write(File.join(self.base_path, 'cover.jpg'))
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/annotation_categories/_annotation_text.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<% end %>
<% if annotation_text[:annotation_category].nil? %>
<div class='annotation-text-details'>
<%= t('activerecord.models.submission', {'count': 1}) + ': ' %>
<%= t('activerecord.models.submission', count: 1) + ': ' %>
<%= link_to annotation_text[:group_name],
edit_course_result_url(@current_course, annotation_text[:result_id]) %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class FixAnnotationLabelNullCategoryOk < ActiveRecord::Migration[4.2]
def self.up
change_column :annotation_labels, :annotation_category_id, :integer, {:null => true}
change_column :annotation_labels, :annotation_category_id, :integer, null: true
end

def self.down
change_column :annotation_labels, :annotation_category_id, :integer, {:null => false}
change_column :annotation_labels, :annotation_category_id, :integer, null: true
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AnnotationCategoriesAssignedToAssignments < ActiveRecord::Migration[4.2]
def self.up
add_column :annotation_categories, :assignment_id, :integer, {:null => false}
add_column :annotation_categories, :assignment_id, :integer, null: false
end

def self.down
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20091105182703_improve_db_indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.up

add_index :results, :submission_id, :unique => true, :name => "results_u1"

change_column :groups, :group_name, :string, {:limit => 30}
change_column :groups, :group_name, :string, limit: 30
add_index :groups, :group_name, :name => "groups_n1"
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class MakeCriterionWeightNotNullAgain < ActiveRecord::Migration[4.2]
def self.up
change_column :rubric_criteria, :weight, :float, {:null => false}
change_column :rubric_criteria, :weight, :float, null: false
end

def self.down
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class FixPrecisionOfFlexibleCriterionMax < ActiveRecord::Migration[4.2]
def self.up
change_column :flexible_criteria, :max, :decimal, {:precision => 10, :scale => 1, :null => false}
change_column :flexible_criteria, :max, :decimal, precision: 10, scale: 1, null: false
end

def self.down
change_column :flexible_criteria, :max, :decimal, {:precision => 10, :scale => 0, :null => false}
change_column :flexible_criteria, :max, :decimal, precision: 10, scale: 1, null: false
end
end
38 changes: 19 additions & 19 deletions db/migrate/20121028211448_testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ def self.up
end

create_table :test_support_files do |t|
t.string :file_name, { :null => false }
t.references :assignment, { :null => false }
t.text :description, { :null => false }
t.string :file_name, null: false
t.references :assignment, null: false
t.text :description, null: false
end

add_index :test_support_files,
["assignment_id"],
:name => "index_test_files_on_assignment_id"

create_table :test_scripts do |t|
t.integer "assignment_id", { :null => false }
t.float "seq_num", { :null => false }
t.string "script_name", { :null => false }
t.text "description", { :null => false }
t.integer "max_marks", { :null => false }
t.integer "assignment_id", null: false
t.float "seq_num", null: false
t.string "script_name", null: false
t.text "description", null: false
t.integer "max_marks", null: false
t.boolean "run_on_submission"
t.boolean "run_on_request"
t.boolean "halts_testing"
t.string "display_description", { :null => false }
t.string "display_run_status", { :null => false }
t.string "display_marks_earned", { :null => false }
t.string "display_input", { :null => false }
t.string "display_expected_output", { :null => false }
t.string "display_actual_output", { :null => false }
t.string "display_description", null: false
t.string "display_run_status", null: false
t.string "display_marks_earned", null: false
t.string "display_input", null: false
t.string "display_expected_output", null: false
t.string "display_actual_output", null: false
end

add_index :test_scripts,
Expand All @@ -49,12 +49,12 @@ def self.up
t.references :test_script
t.references :test_script_result
t.string "name"
t.string "completion_status", { :null => false }
t.integer "marks_earned", { :null => false }
t.string "completion_status", null: false
t.integer "marks_earned", null: false
t.integer "repo_revision"
t.text "input_description", { :null => false }
t.text "actual_output", { :null => false }
t.text "expected_output", { :null => false }
t.text "input_description", null: false
t.text "actual_output", null: false
t.text "expected_output", null: false
end

add_index :test_results,
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20230713153536_increase_group_name_length.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class IncreaseGroupNameLength < ActiveRecord::Migration[7.0]
def change
change_column :groups, :group_name, :string, {:limit => nil}
change_column :groups, :group_name, :string, limit: nil
end
end
15 changes: 15 additions & 0 deletions lib/scanner/read_qr_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys
import cv2
import zxingcpp


if __name__ == '__main__':
input_filename = sys.argv[1]
img = cv2.imread(input_filename)
results = zxingcpp.read_barcodes(img)
if len(results) == 0:
print("Could not find any barcode.")
sys.exit(1)
else:
result = results[0]
print(result.text)
4 changes: 2 additions & 2 deletions markus.control
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Depends:
# nodejs: for serving/managing javascript
nodejs (>= 18), nodejs (<< 19),
# ruby: required to run Rails
ruby (>= 1:2.7) | ruby2.7, ruby (<< 1:3) | ruby2.7,
ruby (>= 1:2.7) | ruby3.0, ruby (<< 1:3) | ruby3.0,
# ruby-dev: required to run rails
ruby-dev (>= 1:2.7) | ruby2.7-dev, ruby-dev (<< 1:3) | ruby2.7-dev,
ruby-dev (>= 1:2.7) | ruby3.0-dev, ruby-dev (<< 1:3) | ruby3.0-dev,
# rubygems-integration: required to install ruby gems
rubygems-integration,
# tesseract-ocr: required for scanned exams
Expand Down
Binary file modified markus_1.0_all.deb
Binary file not shown.
1 change: 1 addition & 0 deletions requirements-qr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zxing-cpp==2.0.0
Loading