This repository has been archived by the owner on Nov 14, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rvm use ruby-1.9.3-p392@picoappz --create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "rubygems" | ||
require 'rake' | ||
require 'rake/testtask' | ||
require_relative 'lib/app' | ||
|
||
task :default => :test | ||
|
||
desc "run tests" | ||
task :test do | ||
# just run tests, nothing fancy | ||
Dir["test/**/*.rb"].sort.each { |test| load test } | ||
end | ||
|
||
desc "Build files and upload to s3" | ||
task :build do | ||
PicoAppz.new.build | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" > | ||
<head> | ||
<title><%= title %></title> | ||
</head> | ||
<body> | ||
<h1>Welboooooooooom one</h1> | ||
<p>Now hosted on Amazon S3!</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'fog' | ||
require 'erubis' | ||
require './lib/server-files.rb' | ||
include ServerFiles | ||
|
||
class PicoAppz | ||
|
||
def initialize | ||
end | ||
|
||
def build | ||
render_templates | ||
upload_to_s3 | ||
end | ||
|
||
private | ||
|
||
def render_templates | ||
puts 'building' | ||
Dir["./app/views/**/*.erb"].each do |file| | ||
puts "processing #{file}" | ||
template = File.read(file) | ||
rendered_file = Erubis::Eruby.new(template).result({:title => "picoappz"}) | ||
output_file = file.gsub(/\.erb/,'').gsub(/\/app\/views/,"/public") | ||
File.open(output_file, 'w') {|f| f.write(rendered_file) } | ||
end | ||
end | ||
|
||
def upload_to_s3 | ||
puts 'uploading' | ||
Dir["./public/**/*.*"].each do |file| | ||
unless File.directory?(file) | ||
mimetype = `file -Ib #{file}`.gsub(/\n/,"") | ||
filename = file.gsub(/\.\/public\//,'') | ||
puts "uploading #{file} to #{filename}" | ||
write_file(filename, File.read(file), :content_type => mimetype) | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module ServerFiles | ||
|
||
# TODO how to allow a server to write files without exposing the shared secrets... | ||
# Thinking a write ONLY ec2 key PER server | ||
# the other thought was this always posts back to the requesting server which writes the file and knows where the data came from | ||
# so these boxes have no sensative data on them | ||
def connection | ||
@connection ||= Fog::Storage.new( | ||
:provider => 'AWS', | ||
:aws_access_key_id => ENV['AMAZON_ACCESS_KEY_ID'], | ||
:aws_secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY']) | ||
end | ||
|
||
def get_file(filename) | ||
begin | ||
file = directory.files.get(filename) | ||
file.body | ||
rescue | ||
'' | ||
end | ||
end | ||
|
||
def write_commits(project_key, after_commit, commit_key, push) | ||
commits_data = get_file(project_key) | ||
@commits = JSON.parse(commits_data) rescue {} | ||
@commits[after_commit] = {:uri => commit_key, :push => push } | ||
write_file(project_key, @commits.to_json) | ||
end | ||
|
||
def write_file(filename, body, options = {}) | ||
file_options = { | ||
:key => filename, | ||
:body => body, | ||
:public => true | ||
} | ||
if options[:content_type] | ||
file_options[:content_type] = options[:content_type] | ||
end | ||
file = directory.files.new(file_options) | ||
file.save | ||
end | ||
|
||
def directory | ||
directory = connection.directories.create( | ||
:key => "www.picoappz.com", | ||
:public => true | ||
) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" > | ||
<head> | ||
<title>Picoappz Error</title> | ||
</head> | ||
<body> | ||
<h1>Picoappz Had a Error</h1> | ||
<p>We are sorry, did you hit the right url, if so and you found a error let me know!</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" > | ||
<head> | ||
<title>picoappz</title> | ||
</head> | ||
<body> | ||
<h1>Welboooooooooom one</h1> | ||
<p>Now hosted on Amazon S3!</p> | ||
</body> | ||
</html> |