Open your production env file with amber encrypt
then edit the database URL, and disable or enable logs. Also see Encrypt.
If you have assets and you're using NPM, use npm install . && npm run release
to compile/minify .css
and .js
files.
Installcrystal
and shards
commands (See installation guide). You can compile bin/amber
tool using shards build amber
in your production project to migrate your database.
Then copy your project repository and ensure to setup AMBER_ENCRYPTION_KEY
and AMBER_ENV=production
in your environments variables. You can get your encryption key from .encryption_key
file in your development machine. Then inside your project's folder, install your shards dependencies with shards install --production
and compile your executable with shards build <your-app> --release
.
Finally run your project executable with bin/<your-app>
.
Also you can try to cross-compile to avoid install these dependencies but this feature is a bit buggy on most OS.
​Alpine Linux is great to use crystal build --static
flag, though.
Compilation may take a while because --release
enables compiler optimizations. You can avoid --release
if you server is low end (less 256 RAM)
Amber performance is still acceptable on non-release mode
You may need sudo permission if you're using port 80 or ports < 1000
You can use iptables
to redirect port 80 to 8080 or whatever port are you using in production.
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
Optionally you can setup a system service to monitor your app very easy, and configure a .git/hook/post-receive
to deploy like Heroku using git push production
. Amber Team is already using a systemd service to manage Amber Framework Website and thepost-receive
hook below to manage deployment using git.
#!/bin/bashset -e​export AMBER_ENV=production​if [ "$GIT_DIR" = "." ]; then# The script has been called as a hook; chdir to the working copycd ..unset GIT_DIRfi​# try to obtain the usual system PATHif [ -f /etc/profile ]; thenPATH=$(source /etc/profile; echo $PATH)export PATHfi​# get the current branchhead="$(git symbolic-ref HEAD)"​# read the STDIN to detect if this push changed the current branchwhile read oldrev newrev refnamedo[ "$refname" = "$head" ] && breakdone​# abort if there's no update, or in case the branch is deletedif [ -z "${newrev//0}" ]; thenexitfi​# check out the latest code into the working copyumask 002git reset --hard​logfile=log/deploy.log​if [ -z "${oldrev//0}" ]; then# this is the first push; this branch was just createdmkdir -p log tmp binchmod 0775 log tmp bintouch $logfilechmod 0664 $logfile​# init submodulesgit submodule update --recursive --init 2>&1 | tee -a $logfileelse# log timestampecho ==== $(date) ==== >> $logfile​#################################################################################### BEGIN: Amberframework specific Code #####################################################################################​shards install​if [ -f bin/amber ]; thenecho "amber already installed"elsecrystal build lib/amber/src/amber/cli.cr -o bin/amber --statsfi​echo "Migrating..."./bin/amber db create migrate || trueecho "Building application in release mode"crystal build src/amberframework.cr -o bin/amberframework --release --statssystemctl status amberframeworksudo systemctl restart amberframeworksystemctl status amberframeworkfi
Then add your production repository to your development machine using git remote add
git remote add production <user>@<ip>:/home/<user>/<repository>
<user>
is a valid user with your public ssh key inside ~/.ssh/authorized_keys
<ip>
is your production machine IP (you can use a domain as well).
<repository>
is your project with your.git
folder inside.