{"title":"Dokku","description":"","section":"deployment","version":"v1.5","path":"deployment/dokku","canonical_url":"https://amberframework.org/docs/v1.5/deployment/dokku","markdown_url":"https://amberframework.org/docs/v1.5/deployment/dokku.md","inherited":true,"content_markdown":"# Dokku\n\n## Requirements\n\nBefore getting started, ensure you have a Dokku instance running with a new app.\nAn example app can be created following these steps:\n\n```text\n# on the Dokku host\ndokku apps:create amber-app\n\n# Setup postgres db\nsudo dokku plugin:install https://github.com/dokku/dokku-postgres.git\ndokku postgres:create amber-db\n\n# This sets the DATABASE_URL env var\ndokku postgres:link amber-db amber-app\n```\n\n## Define Buildpack\n\nBuildpacks tell Dokku how to build and deploy your application. Create a file named `.buildpacks` in the root of your project and with this:\n\n```text\nhttps://github.com/amberframework/heroku-buildpack-amber.git\n# If you need js / css compiled\nhttps://github.com/heroku/heroku-buildpack-nodejs.git\n```\n\n{% hint style=\"danger\" %}\nIf you want js / css to be compiled, you need to modify the `build` command in `package.json` to `\"build\": \"npm run release\",`. Because the nodejs buildpack expects `npm build` to compile the production assets.\n{% endhint %}\n\n{% hint style=\"danger\" %}\nNot defining a .buildpack file will cause Dokku to build your project using the\n`Dockerfile` as Dokku will auto-detect it, this will not work and cause issues.\n{% endhint %}\n\n## Define Crystal Version\n\nIt's best practice to lock your crystal version to the one you're using. Without\nthis the latest version of crystal will be used, potentially causing issues in\ndeployment.\n\nCreate a file named `.crystal-version` in the root of your project with the\nwanted crystal version:\n\n```\n0.31.1\n```\n\n## Create Procfile\n\nTo deploy your app to Dokku you're going to need a `Procfile`. Create a `Procfile` at the root of your Amber application and add the following:\n\n```yaml\nrelease: bin/amber db migrate\nweb: bin/{your-app-name}\n```\n\nThe Amber buildpack takes care of compiling the project for you.\n\n## Env Vars\n\n### Set Production Vars\n\nWhere ever your application runs, it needs to be in production mode.\n\n```bash\nssh dokku@{yourdokku.com} config:set {your-app-name} AMBER_ENV=production\n```\n\n### Set Encryption Key\n\nEnsure you first run:\n\n```bash\namber encrypt\n```\n\nTo be able to decrypt and use production environment you'll need to set `ENV[\"AMBER_ENCRYPTION_KEY\"]` to the value of your local projects `.encryption_key` file.\n\n{% hint style=\"danger\" %}\nNever add `.encryption_key` to github. Amber adds it by default to your `.gitignore` file.\n{% endhint %}\n\nCopy the key from `.encryption_key` and set it to env, like so:\n\n```bash\nssh dokku@{yourdokku.com} config:set {your-app-name} AMBER_ENCRYPTION_KEY={your_key}\n```\n\n### Pick up Env vars\n\nIn order for the buildpack to work properly your application has to:\n\n* Listen on the environment's port.\n* Connect to any services like redis / database.\n\nEnsure these settings are in your `settings.cr` file.\n\n```crystal\nAmber::Server.configure do |settings|\n  settings.host = \"0.0.0.0\"\n  settings.port = ENV[\"PORT\"].to_i if ENV[\"PORT\"]?\n  settings.redis_url = ENV[\"REDIS_URL\"] if ENV[\"REDIS_URL\"]?\n  settings.database_url = ENV[\"DATABASE_URL\"] if ENV[\"DATABASE_URL\"]?\nend\n```\n\n## Deploying\n\nAll that's left is to create a git repository, add the Dokku remote and push it there.\n\n```text\n$ git init\n$ git remote add dokku dokku@{yourdokku.com}:{your-app-name}\n$ git add -A\n$ git commit -m \"My first Amber app\"\n$ git push dokku master\n```\n\nMore information on how to deploy your app can be found on the [Dokku docs](http://dokku.viewdocs.io/dokku/deployment/application-deployment/#deploy-tutorial)"}