Commit 4f61b801 authored by jz143's avatar jz143

seperate web and signing worker [untested code]

parent a2fc9a99
......@@ -64,7 +64,8 @@ gem 'simple_form'
# authentication
# gem 'devise', "~> 3.5.2"
gem 'net-ssh'
gem 'net-ssh', '~> 3.1.0'
gem 'net-scp', '~> 1.2.1'
# authorization
gem "pundit"
......
......@@ -129,7 +129,7 @@ GEM
mysql2 (0.3.20)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (3.0.1)
net-ssh (3.1.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
paperclip (4.3.1)
......@@ -243,7 +243,8 @@ DEPENDENCIES
jbuilder (~> 2.0)
jquery-rails
mysql2 (~> 0.3.18)
net-ssh
net-scp (~> 1.2.1)
net-ssh (~> 3.1.0)
paperclip (~> 4.3)
plist!
pundit
......@@ -259,3 +260,6 @@ DEPENDENCIES
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)
BUNDLED WITH
1.11.2
......@@ -17,6 +17,14 @@ class AppFilesController < ApplicationController
def download
@app_file = AppFile.find(params[:app_file_id])
respond_to do |format|
format.zip do
if params[:download_token] == @app_file.download_token
send_file @app_file.archive.path
else
render nothing: true
end
end
format.apk do
send_file @app_file.archive.path
@app_file.increment!(:download_count)
......@@ -24,11 +32,15 @@ class AppFilesController < ApplicationController
format.plist do
render 'manifest.plist'
@app_file.increment!(:download_count)
end
format.ipa do
send_file @app_file.signed_ipa_location, :type => 'application/octet-stream'
@app_file.increment!(:download_count)
if @app_file.signed?
send_file @app_file.signed_ipa_location, :type => 'application/octet-stream'
else
render json: { :error => 'Signed ipa is not available yet' }
end
end
end
end
......
require 'open-uri'
class BuildIpaJob < ActiveJob::Base
queue_as :default
queue_as :mac_server
def perform(app_file_id)
# get corresponding app_file record
app_file = AppFile.find(app_file_id)
if app_file.platform != 'iOS'
return # this job doesn't sign non-iOS apps
# this job doesn't sign non-iOS apps
unless app_file.is_ios_app?
return
end
log = ""
......@@ -18,16 +21,17 @@ class BuildIpaJob < ActiveJob::Base
begin
log << "#{self.class.name} using tmp dir: #{tmpdir}\n"
# ensure we have the .app file on this machine
# NOTE - in the future, add the ability to copy from remote
unless File.file?(app_file.archive.path)
raise "App file (#{app_file.archive.path}) doesn't exist on worker"
# fetch app file from remote web server (assuming we are worker on another machine)
# we use remote's HTTP send_file here to reduce ruby workload
File.open(File.join(tmpdir, 'Unsigned.app.zip'), "wb") do |file|
# XXX: this looks like a hack
default_url_options = Rails.application.config.action_mailer.default_url_options
include Rails.application.routes.url_helpers
open(app_app_file_download_url(app_file.app, app_file, default_url_options), "rb") do |read_file|
file.write(read_file.read)
end
end
# copy file to tmp folder
# NOTE - future: copy file from sshfs to tmp folder
FileUtils.copy_file(app_file.archive.path, File.join(tmpdir, 'Unsigned.app.zip'))
# Mac automatically zips .app folder, so we need to unzip it
log << "Unzipping archive...\n"
IO.popen(['unzip', File.join(tmpdir, 'Unsigned.app.zip'), '-d', File.join(tmpdir, 'UnsignedArchiveContent')]) do |unzip_io|
......@@ -81,10 +85,8 @@ class BuildIpaJob < ActiveJob::Base
raise "Signing script exited with non-zero status (#{$?})"
end
# save ipa file to the same directory as unsigned .app file
FileUtils.copy_file(File.join(tmpdir, 'Signed.ipa'), app_file.signed_ipa_location)
app_file.signed!
app_file.pending_transfer_to_web!
FetchedSignedIpaJob.perform_later app_file.id
rescue => e
app_file.signing_failed!
log << "Fatal error: " << e.to_s << "\n"
......
......@@ -7,7 +7,7 @@ class AppFile < ActiveRecord::Base
has_attached_file :archive
validates_attachment_file_name :archive, matches: [/apk\Z/, /zip\Z/]
enum code_signing_status: [ :unsigned, :signing, :signing_failed, :signed ]
enum code_signing_status: { unsigned: 0, downloading_to_mac: 4, signing: 1, signing_failed: 2, pending_transfer_to_web: 5, downloading_to_web: 6, download_to_web_failed: 7, signed: 3 }
after_commit :queue_for_ios_code_signing, :on => :create
def signed_ipa_location
......@@ -18,10 +18,13 @@ class AppFile < ActiveRecord::Base
puts "code_signing_status = " + code_signing_status
puts "platform = " + platform
puts "id = " + id.to_s
# if is_ios_app? && code_signing_status == :unsigned
# puts "QUEUEING THE APP"
if is_ios_app?
# make a secret random key for direct download
require 'securerandom'
download_token = SecureRandom.hex
BuildIpaJob.perform_later id
# end
end
end
def is_ios_app?
......
web_server:
host: localhost
user:
signing_worker:
host: localhost
user:
web:
host: appstore.colab.duke.edu
user: appstore
signing_worker:
host: istudio-osxserver.oit.duke.edu
user: appstore
......@@ -11,22 +11,24 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151124175550) do
ActiveRecord::Schema.define(version: 20160321154537) do
create_table "app_files", force: :cascade do |t|
t.string "platform"
t.string "version"
t.integer "download_count", default: 0
t.integer "download_count", default: 0
t.integer "app_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "archive_file_name"
t.string "archive_content_type"
t.integer "archive_file_size"
t.datetime "archive_updated_at"
t.integer "user_id"
t.integer "code_signing_status", default: 0
t.integer "code_signing_status", default: 0
t.text "code_signing_log"
t.string "download_token"
t.string "signed_ipa_path_on_signing_server"
end
add_index "app_files", ["app_id"], name: "index_app_files_on_app_id"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment