Skip to content

Commit

Permalink
Initial commit with basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerflint committed Oct 26, 2017
0 parents commit dfbbb2a
Show file tree
Hide file tree
Showing 12 changed files with 593 additions and 0 deletions.
362 changes: 362 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Crystal

This is a Crystal engine used to launch Crystal apps on [Nanobox](http://nanobox.io). It installs all binaries to run a Crystal app.

# Usage
To use the Crystal engine, specify `crystal` as your engine in your [boxfile.yml](http://docs.nanobox.io/app-config/boxfile/).

```yaml
run.config:
engine: crystal
```
## Crystal on Nanobox
For more information about using Crystal on Nanobox, view the [Crystal guides](http://guides.nanobox.io/crystal/).
## Help & Support
This is an engine provided by [Nanobox](http://nanobox.io). If you are running into an issue with the engine, feel free to [create a new issue on this project](https://github.com/nanobox-io/nanobox-engine-crystal/issues/new).
58 changes: 58 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"

config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", "2048", "--ioapic", "on"]
end

config.vm.synced_folder ".", "/vagrant"

# install docker
config.vm.provision "shell", inline: <<-SCRIPT
if [[ ! `which docker > /dev/null 2>&1` ]]; then
# add docker's gpg key
apt-key adv \
--keyserver hkp://p80.pool.sks-keyservers.net:80 \
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D
# add the source to our apt sources
echo \
"deb https://apt.dockerproject.org/repo ubuntu-trusty main \n" \
> /etc/apt/sources.list.d/docker.list
# update the package index
apt-get -y update
# ensure the old repo is purged
apt-get -y purge lxc-docker
# install docker
apt-get -y install docker-engine
fi
SCRIPT

# start docker
config.vm.provision "shell", inline: <<-SCRIPT
if [[ ! `service docker status | grep "start/running"` ]]; then
# start the docker daemon
service docker start
fi
SCRIPT

# wait for docker to be running
config.vm.provision "shell", inline: <<-SCRIPT
echo "Waiting for docker sock file"
while [ ! -S /var/run/docker.sock ]; do
sleep 1
done
SCRIPT

# pull the build image to run tests in
config.vm.provision "shell", inline: <<-SCRIPT
echo "Pulling the build image"
docker pull nanobox/build
SCRIPT
end
17 changes: 17 additions & 0 deletions bin/boxfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# -*- mode: bash; tab-width: 2; -*-
# vim: ts=2 sw=2 ft=bash noet

set -e

cat <<-END
run.config:
cache_dirs:
- lib
- .shards
build_triggers:
- shards.yml
- shards.lock
END

exit 0
25 changes: 25 additions & 0 deletions bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
# -*- mode: bash; tab-width: 2; -*-
# vim: ts=2 sw=2 ft=bash noet

set -e

# source the Nos framework
. /opt/nanobox/nos/common.sh

# initialize Nos with the original arguments
nos_init "$@"

# source common lib
. ${engine_lib_dir}/crystal.sh

# install crystal
install_runtime_packages

# setup crystal env vars
setup_crystal_env

# Fetch crystal shards
fetch_shards

exit 0
5 changes: 5 additions & 0 deletions bin/cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# -*- mode: bash; tab-width: 2; -*-
# vim: ts=2 sw=2 ft=bash noet

exit 0
5 changes: 5 additions & 0 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# -*- mode: bash; tab-width: 2; -*-
# vim: ts=2 sw=2 ft=bash noet

exit 0
19 changes: 19 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# -*- mode: bash; tab-width: 2; -*-
# vim: ts=2 sw=2 ft=bash noet

set -e

# source the Nos framework
. /opt/nanobox/nos/common.sh

# initialize Nos with the original arguments
nos_init "$@"

# source common lib
. ${engine_lib_dir}/crystal.sh

# copy the release into the live code directory
publish_release

exit 0
1 change: 1 addition & 0 deletions files/env.d/LD_LIBRARY_PATH
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/data/lib:/usr/lib:/usr/local/lib
1 change: 1 addition & 0 deletions files/env.d/LIBRARY_PATH
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/data/lib:/usr/lib:/usr/local/lib
74 changes: 74 additions & 0 deletions lib/crystal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# -*- mode: bash; tab-width: 2; -*-
# vim: ts=2 sw=2 ft=bash noet

# Copy the code into the live directory which will be used to run the app
publish_release() {
nos_print_bullet "Moving build into live app directory..."
rsync -a $(nos_code_dir)/ $(nos_app_dir)
}

# Determine the crystal runtime to install. This will first check
# within the Boxfile, then will rely on default_runtime to
# provide a sensible default
runtime() {
echo $(nos_validate \
"$(nos_payload "config_runtime")" \
"string" "$(default_runtime)")
}

# Provide a default crystal version.
default_runtime() {
echo "crystal-0.23"
}

# Install the crystal runtime along with any dependencies.
install_runtime_packages() {
pkgs=("$(runtime)")

# add any client dependencies
pkgs+=("$(query_dependencies)")

nos_install ${pkgs[@]}
}

# Setup environment variables that the crystal compiler
# and runtime use for building and running the app
setup_crystal_env() {
nos_template_file \
"env.d/LD_LIBRARY_PATH" \
"$(nos_etc_dir)/env.d/LD_LIBRARY_PATH"

nos_template_file \
"env.d/LIBRARY_PATH" \
"$(nos_etc_dir)/env.d/LIBRARY_PATH"
}

# Uninstall build dependencies
uninstall_build_packages() {
pkgs=()

# if pkgs isn't empty, let's uninstall what we don't need
if [[ ${#pkgs[@]} -gt 0 ]]; then
nos_uninstall ${pkgs[@]}
fi
}

# Fetch crystal shards from shard.yml
fetch_shards() {
if [[ -f $(nos_code_dir)/shard.yml ]]; then

cd $(nos_code_dir)
nos_run_process "Fetching crystal shards" \
"crystal deps"
cd - >/dev/null
fi
}

# compiles a list of dependencies that will need to be installed
query_dependencies() {
deps=()

# todo: add deps

echo "${deps[@]}"
}
9 changes: 9 additions & 0 deletions travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sudo: required

services:
- docker

before_install:
- docker pull nanobox/build

script: sudo test/run_all.sh

0 comments on commit dfbbb2a

Please sign in to comment.