Skip to content

Commit

Permalink
initial sandstorm port
Browse files Browse the repository at this point in the history
  • Loading branch information
Sing-Li committed Sep 1, 2015
1 parent fe81ae5 commit 6497930
Show file tree
Hide file tree
Showing 29 changed files with 346 additions and 23 deletions.
8 changes: 5 additions & 3 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ rocketchat:markdown
rocketchat:me
#rocketchat:slashcommands-invite
rocketchat:mentions
rocketchat:oembed
rocketchat:webrtc
#rocketchat:external
#rocketchat:hubot
#rocketchat:oembed
rocketchat:webrtc-ib
#rocketchat:external
#rocketchat:irc

konecty:change-case
Expand Down Expand Up @@ -82,3 +82,5 @@ monbro:mongodb-mapreduce-aggregation
rocketchat:custom-oauth
rocketchat:gitlab
rocketchat:statistics
kenton:accounts-sandstorm

2 changes: 0 additions & 2 deletions .meteor/platforms
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
android
browser
ios
server
4 changes: 2 additions & 2 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jquery@1.11.3_2
json@1.0.3
kadira:blaze-layout@2.0.1
kadira:flow-router@2.4.0
kenton:accounts-sandstorm@0.1.4
kevohagan:sweetalert@1.0.0
konecty:autolinker@1.0.2
konecty:change-case@2.3.0
Expand Down Expand Up @@ -114,9 +115,8 @@ rocketchat:logger@0.0.1
rocketchat:markdown@0.0.1
rocketchat:me@0.0.1
rocketchat:mentions@0.0.1
rocketchat:oembed@0.0.1
rocketchat:statistics@0.0.1
rocketchat:webrtc@0.0.1
rocketchat:webrtc-ib@0.0.1
routepolicy@1.0.5
service-configuration@1.0.4
session@1.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.5:c17761bf-b2f4-49da-87b9-79a95da91252
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1440583526
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000
1 change: 1 addition & 0 deletions .sandstorm/.vagrant/machines/default/virtualbox/id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c17761bf-b2f4-49da-87b9-79a95da91252
1 change: 1 addition & 0 deletions .sandstorm/.vagrant/machines/default/virtualbox/index_uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0d8eab53d7a1444288ff01aef6a03573
27 changes: 27 additions & 0 deletions .sandstorm/.vagrant/machines/default/virtualbox/private_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAk1hkJc1e5h4yDnnOCJ29YUf0x1DhgSkGY0hcfWAubSEGS1HX
bxLIE+Al44jENNPrrdddtCKY+onxeefQo7FUFxVMEOM5JqFzpyq1Sliw9w7QmJef
DImS0z54ezqQ952W7BQc/XOndVpzvRPVREcRccOdGk5P60zoWZP/Oy4tviHcH7RM
faeBrs7ykD6RJKAjKwuMF3p/+FlPCPwql8cTifYZspFwFTja/XStk3PX4eLle5si
ZFN7SjsDa+FflUenmgkpW04E6TUaQHVhapHJCCbYRqwCrUX/5Yf2PakFPqfnRBaE
KKkGLRnVc7UrCDk21m/IZRmTHgSLAyDEGkFOIwIDAQABAoIBAHCJBAQzNJXA3i5c
LVY7U5bnJDbOuUyyjqRpcep3+T10CaChI088Iv+7JHUB0gkfClO9t12LRxejH4Eh
4iIDn9v5ch07zjyI9xHn9oqP7qji8cJ5mwoyUKdygQZtFqdn/wrT2chh+rYQnXD9
otcBCHvBEU40HanzFUrFVBxZCqq5fP69ujsOVghykyzI5mWIRNGFXyvN8HxjXMr6
mSiCvzEMscTZzdoCvy18lvDTWg5GyPLq9EM+4xQoEqlQv2RQEUmC2wC4JK09bJ8T
d19RGax1Nvbvw0ywWTgG/blGS0h7Q4aJziIL1Bv1IoIonn69wjL/qaWh+vqhL6QV
m87qh7ECgYEAwzy0kwO5Xo1mWZN4lJ8WrU7xh5TtsSJkfMlEQNsmhHAFN9B7p7MX
CrIAMd+U9z8ptxgFZwfoff4Qcb9QkHo8wZLj9vYWTAoJ0VyvVwUTwi4D5lHvFDe/
IX2N4pJv5AB3+xValyg+z6ShGKmWJuLhCYtcYFxdr8tZ45RlHYzv0V0CgYEAwTP1
F3dURItjPVQ7BSHXmPoSTSuhAjbQp+jWOIEa+wnM3K3OncfbICFqSwFsz1cjKDjz
fAMXw9is7s/T8CEm6u4DFKbZ2qlAcvq02oqZu1/6UZXxTXFdjfQaKpSQ4ZWMxVBE
nKIs/e/416zCH6zd1Xauus92xI+zse5iSn++JX8CgYBGu/ewS+kdGJ28VnGZZwoQ
QEnBlXOIea1uiHzyAnQyB2PclOw4FeqDNXpcl2ShL4EtlMZgTb0t6J6Ml4PY1HCu
sUlmcEIjyn9EGxBrtqsx7vn6uDSmXowg1hxRujxPntvZXCM2IJ6hHERBay+7Zveh
PZx6TPykdEhc66a2zhkVAQKBgAOwHTaUdYxVaNCL4hCIA9iMtXq5oXosV7FM1YIA
nOY72qg/vRjv7rPfT2sdHNmcXTRwWd19JZ/8a9inKPGFgHutjWuAf9oXrv5C4N7n
FGYqP9n81b1Xs6R5C2LSsS1NMIG3tYeT5O33/bUIPDBkmVtwx4cTXL4FzDVSSpgH
dja7AoGAMAXuTIrq1+L6sMQYgwx/9loN4KkdYAP7ZDlX+2uROzk2u/aCw9dGIJMs
R5JSS5+5oG2MRNTAnz/35qge5M9ucRdiNKdxO4jLK9e009m+wl4AxVFFRz0Bz8Nf
QYlzA2d5S3I1EJSUNjjDkEq9szaVeRmVKt40n3X/JKjTggX6Ibg=
-----END RSA PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"virtualbox":{"/opt/app":{"guestpath":"/opt/app","hostpath":"/home/sam/projects/Rocket.Chat/Rocket.Chat","disabled":false},"/host-dot-sandstorm":{"guestpath":"/host-dot-sandstorm","hostpath":"/home/sam/.sandstorm","disabled":false},"/vagrant":{"guestpath":"/vagrant","hostpath":"/home/sam/projects/Rocket.Chat/Rocket.Chat","disabled":false}}}
83 changes: 83 additions & 0 deletions .sandstorm/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# We base ourselves off Debian Jessie
config.vm.box = "debian/jessie64"

if Vagrant.has_plugin?("vagrant-vbguest") then
# vagrant-vbguest is a Vagrant plugin that upgrades
# the version of VirtualBox Guest Additions within each
# guest. If you have the vagrant-vbguest plugin, then it
# needs to know how to compile kernel modules, etc., and so
# we give it this hint about operating system type.
config.vm.guest = "debian"
end

# We forward port 6080, the Sandstorm web port, so that developers can
# visit their sandstorm app from their browser as local.sandstorm.io:6080
# (aka 127.0.0.1:6080).
config.vm.network :forwarded_port, guest: 6080, host: 6080

# Use a shell script to "provision" the box. This installs Sandstorm using
# the bundled installer.
config.vm.provision "shell", inline: "sudo bash /opt/app/.sandstorm/global-setup.sh"
# Then, do stack-specific and app-specific setup.
config.vm.provision "shell", inline: "sudo bash /opt/app/.sandstorm/setup.sh"

# Shared folders are configured per-provider since vboxsf can't handle >4096 open files,
# NFS requires privilege escalation every time you bring a VM up,
# and 9p is only available on libvirt.

# Calculate the number of CPUs and the amount of RAM the system has,
# in a platform-dependent way; further logic below.
cpus = nil
total_kB_ram = nil

host = RbConfig::CONFIG['host_os']
if host =~ /darwin/
cpus = `sysctl -n hw.ncpu`.to_i
total_kB_ram = `sysctl -n hw.memsize`.to_i / 1024
elsif host =~ /linux/
cpus = `nproc`.to_i
total_kB_ram = `grep MemTotal /proc/meminfo | awk '{print $2}'`.to_i
end
# Use the same number of CPUs within Vagrant as the system, with 1
# as a default.
#
# Use at least 512MB of RAM, and if the system has more than 2GB of
# RAM, use 1/4 of the system RAM. This seems a reasonable compromise
# between having the Vagrant guest operating system not run out of
# RAM entirely (which it basically would if we went much lower than
# 512MB) and also allowing it to use up a healthily large amount of
# RAM so it can run faster on systems that can afford it.
if cpus.nil?
cpus = 1
end
if total_kB_ram.nil? or total_kB_ram < 2048000
assign_ram_mb = 512
else
assign_ram_mb = (total_kB_ram / 1024 / 4)
end
# Actually apply these CPU/memory values to the providers.
config.vm.provider :virtualbox do |vb, override|
vb.cpus = cpus
vb.memory = assign_ram_mb

override.vm.synced_folder "..", "/opt/app"
override.vm.synced_folder ENV["HOME"] + "/.sandstorm", "/host-dot-sandstorm"
override.vm.synced_folder "..", "/vagrant"
end
config.vm.provider :libvirt do |libvirt, override|
libvirt.cpus = cpus
libvirt.memory = assign_ram_mb
libvirt.random_hostname = true

override.vm.synced_folder "..", "/opt/app", type: "9p", accessmode: "passthrough"
override.vm.synced_folder ENV["HOME"] + "/.sandstorm", "/host-dot-sandstorm", type: "9p", accessmode: "passthrough"
override.vm.synced_folder "..", "/vagrant", type: "9p", accessmode: "passthrough"
end
end
15 changes: 15 additions & 0 deletions .sandstorm/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -euo pipefail

# Make meteor bundle

METEOR_WAREHOUSE_DIR="${METEOR_WAREHOUSE_DIR:-$HOME/.meteor}"
METEOR_DEV_BUNDLE=$(dirname $(readlink -f "$METEOR_WAREHOUSE_DIR/meteor"))/dev_bundle

cd /opt/app
meteor build --directory /home/vagrant/
(cd /home/vagrant/bundle/programs/server && "$METEOR_DEV_BUNDLE/bin/npm" install)

# Copy our launcher script into the bundle so the grain can start up.
mkdir -p /home/vagrant/bundle/opt/app/.sandstorm/
cp /opt/app/.sandstorm/launcher.sh /home/vagrant/bundle/opt/app/.sandstorm/
30 changes: 30 additions & 0 deletions .sandstorm/global-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -euo pipefail
echo localhost > /etc/hostname
hostname localhost
curl https://install.sandstorm.io/ > /host-dot-sandstorm/caches/install.sh
SANDSTORM_CURRENT_VERSION=$(curl -fs "https://install.sandstorm.io/dev?from=0&type=install")
SANDSTORM_PACKAGE="sandstorm-$SANDSTORM_CURRENT_VERSION.tar.xz"
if [[ ! -f /host-dot-sandstorm/caches/$SANDSTORM_PACKAGE ]] ; then
curl --output "/host-dot-sandstorm/caches/$SANDSTORM_PACKAGE" "https://dl.sandstorm.io/$SANDSTORM_PACKAGE"
fi
bash /host-dot-sandstorm/caches/install.sh -d -e "/host-dot-sandstorm/caches/$SANDSTORM_PACKAGE"
modprobe ip_tables
# Make the vagrant user part of the sandstorm group so that commands like
# `spk dev` work.
usermod -a -G 'sandstorm' 'vagrant'
# Bind to all addresses, so the vagrant port-forward works.
sudo sed --in-place='' \
--expression='s/^BIND_IP=.*/BIND_IP=0.0.0.0/' \
/opt/sandstorm/sandstorm.conf
# TODO: update sandstorm installer script to ask about dev accounts, and
# specify a value for this option in the default config?
if ! grep --quiet --no-messages ALLOW_DEV_ACCOUNTS=true /opt/sandstorm/sandstorm.conf ; then
echo "ALLOW_DEV_ACCOUNTS=true" | sudo tee -a /opt/sandstorm/sandstorm.conf
sudo service sandstorm restart
fi
# Enable apt-cacher-ng proxy to make things faster if one appears to be running on the gateway IP
GATEWAY_IP=$(ip route | grep ^default | cut -d ' ' -f 3)
if nc -z "$GATEWAY_IP" 3142 ; then
echo "Acquire::http::Proxy \"http://$GATEWAY_IP:3142\";" > /etc/apt/apt.conf.d/80httpproxy
fi
16 changes: 16 additions & 0 deletions .sandstorm/launcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -euo pipefail

echo '** Starting mongo...'
/bin/niscud \
--fork --port 4002 --dbpath /var --noauth --bind_ip 127.0.0.1 \
--nohttpinterface --noprealloc --logpath /var/mongo.log &

# TODO: wait for niscu to be up
echo '** Starting Meteor...'

export MONGO_URL="mongodb://127.0.0.1:4002/meteor";
export ROOT_URL="http://127.0.0.1:8000";
export PORT="8000";

node /main.js
66 changes: 66 additions & 0 deletions .sandstorm/sandstorm-pkgdef.capnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@0xdb0b8a1059adf258;

using Spk = import "/sandstorm/package.capnp";
# This imports:
# $SANDSTORM_HOME/latest/usr/include/sandstorm/package.capnp
# Check out that file to see the full, documented package definition format.

const pkgdef :Spk.PackageDefinition = (
# The package definition. Note that the spk tool looks specifically for the
# "pkgdef" constant.

id = "1yqjjc9yru8e577pm95peu7t32ccf1xf0mepkvxj9ezch9amj82h",
# Your app ID is actually its public key. The private key was placed in
# your keyring. All updates must be signed with the same key.

manifest = (
# This manifest is included in your app package to tell Sandstorm
# about your app.

appTitle = (defaultText = "Rocket.Chat"),

appVersion = 0, # Increment this for every release.

appMarketingVersion = (defaultText = "0.6"),
# Human-readable representation of appVersion. Should match the way you
# identify versions of your app in documentation and marketing.

actions = [
# Define your "new document" handlers here.
( title = (defaultText = "New Rocket.Chat"),
command = .myCommand
# The command to run when starting for the first time. (".myCommand"
# is just a constant defined at the bottom of the file.)
)
],

continueCommand = .myCommand
# This is the command called to start your app back up after it has been
# shut down for inactivity. Here we're using the same command as for
# starting a new instance, but you could use different commands for each
# case.
),

sourceMap = (
# The following directories will be copied into your package.
searchPath = [
( sourcePath = "/home/vagrant/bundle" ),
( sourcePath = "/opt/meteor-spk/meteor-spk.deps" )
]
),

alwaysInclude = [ "." ]
# This says that we always want to include all files from the source map.
# (An alternative is to automatically detect dependencies by watching what
# the app opens while running in dev mode. To see what that looks like,
# run `spk init` without the -A option.)
);

const myCommand :Spk.Manifest.Command = (
# Here we define the command used to start up your server.
argv = ["/sandstorm-http-bridge", "8000", "--", "/opt/app/.sandstorm/launcher.sh"],
environ = [
# Note that this defines the *entire* environment seen by your app.
(key = "PATH", value = "/usr/local/bin:/usr/bin:/bin")
]
);
47 changes: 47 additions & 0 deletions .sandstorm/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -euo pipefail

cd /opt/

PACKAGE=meteor-spk-0.1.4
PACKAGE_FILENAME="$PACKAGE.tar.xz"
CACHE_TARGET="/host-dot-sandstorm/caches/${PACKAGE_FILENAME}"

# Fetch meteor-spk tarball if not cached
if [ ! -f "$CACHE_TARGET" ] ; then
curl https://dl.sandstorm.io/${PACKAGE_FILENAME} > "$CACHE_TARGET"
fi

# Extract to /opt
tar xf "$CACHE_TARGET"

# Create symlink so we can rely on the path /opt/meteor-spk
ln -s "${PACKAGE}" meteor-spk

# Add bash, and its dependencies, so they get mapped into the image.
# Bash runs the launcher script.
cp -a /bin/bash /opt/meteor-spk/meteor-spk.deps/bin/
cp -a /lib/x86_64-linux-gnu/libncurses.so.* /opt/meteor-spk/meteor-spk.deps/lib/x86_64-linux-gnu/
cp -a /lib/x86_64-linux-gnu/libtinfo.so.* /opt/meteor-spk/meteor-spk.deps/lib/x86_64-linux-gnu/

# Unfortunately, Meteor does not explicitly make it easy to cache packages, but
# we know experimentally that the package is mostly directly extractable to a
# user's $HOME/.meteor directory.
METEOR_RELEASE=1.1.0.2
METEOR_PLATFORM=os.linux.x86_64
METEOR_TARBALL_FILENAME="meteor-bootstrap-${METEOR_PLATFORM}.tar.gz"
METEOR_TARBALL_URL="https://d3sqy0vbqsdhku.cloudfront.net/packages-bootstrap/${METEOR_RELEASE}/${METEOR_TARBALL_FILENAME}"
METEOR_CACHE_TARGET="/host-dot-sandstorm/caches/${METEOR_TARBALL_FILENAME}"

# Fetch meteor tarball if not cached
if [ ! -f "$METEOR_CACHE_TARGET" ] ; then
curl "$METEOR_TARBALL_URL" > "${METEOR_CACHE_TARGET}.partial"
mv "${METEOR_CACHE_TARGET}"{.partial,}
fi

# Extract as unprivileged user, which is the usual meteor setup
cd /home/vagrant/
su -c "tar xf '${METEOR_CACHE_TARGET}'" vagrant
# Link into global PATH
ln -s /home/vagrant/.meteor/meteor /usr/bin/meteor

1 change: 1 addition & 0 deletions .sandstorm/stack
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
meteor
3 changes: 2 additions & 1 deletion client/lib/avatar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
if not username?
return

return "#{Meteor.absoluteUrl()}avatar/#{username}.jpg?_dc=#{random}"
# return "#{Meteor.absoluteUrl()}avatar/#{username}.jpg?_dc=#{random}"
return "/avatar/#{username}.jpg?_dc=#{random}"

Blaze.registerHelper 'avatarUrlFromUsername', getAvatarUrlFromUsername

Expand Down
3 changes: 2 additions & 1 deletion client/views/account/avatar/prompt.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2>
{{/unless}}
</div>
</div>

<!-- disable for sandstorm
{{#if suggestions.ready}}
{{> avatarSuggestion suggestions.avatars.gravatar}}
{{> avatarSuggestion suggestions.avatars.facebook}}
Expand All @@ -83,6 +83,7 @@ <h2>
{{else}}
{{_ "Loading_suggestion"}}
{{/if}}
-->
</div>
</div>

Expand Down
3 changes: 3 additions & 0 deletions client/views/app/sideNav/userStatus.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ <h4>{{username}}</h4>
<a href="" data-status="busy" class="status busy"><span>{{_ "Busy" context="male"}}</span></a>
<a href="" data-status="offline" class="status offline"><span>{{_ "Invisible"}}</span></a>
<a href="" id="account" class='account-link'><i class="icon-sliders"></i><span>{{_ "My_Account"}}</span></a>
<!-- disable admin and logout for sandstorm
{{#if isAdmin}}
<a href="" id="admin" class='account-link'><i class="icon-wrench"></i><span>{{_ "Administration"}}</span></a>
{{/if}}
<a href="" id="logout"><i class="icon-logout"></i><span>{{_ "Logout"}}</span></a>
-->
</div>
</nav>
{{/with}}
Expand Down
Loading

1 comment on commit 6497930

@Sing-Li
Copy link
Member Author

@Sing-Li Sing-Li commented on 6497930 Sep 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closes #473

Please sign in to comment.