User Tools

Site Tools


dokku_gitlab

Dokku

Todo

Add ssh key

cat ~/.ssh/id_rsa.pub | ssh root@DOKKU_DOMAIN dokku ssh-keys:add KEY_NAME

Create app and database

A base app is needed for the review app to be cloned from.

For details see http://dokku.viewdocs.io/dokku/deployment/application-deployment/

Create app

dokku apps:create ruby-rails-sample
dokku postgres:create rails-database
dokku postgres:link rails-database ruby-rails-sample

Push app to dokku manually

cd ruby-rails-sample
git remote add dokku dokku@dokku.me:ruby-rails-sample # Add remote
git push dokku master # Push master branch to remote

Handy commands

List apps

dokku apps:report

Restart/Rebuild App

dokku ps:rebuild ruby-rails-sample

List domains

dokku domains:report

Port mapping

dokku proxy:report

Run command on dokku server within Gitlab

ssh -t dokku@$DOKKU_SERVER -- --force apps:destroy "$APP_NAME"

Import Database (mariadb)

@see https://github.com/dokku/dokku-mariadb#commands

dokku mariadb:import composer-gitlab-update-gui-database < ./c1cgu.sql

Show/set environment variables

dokku config:export --format shell composer-gitlab-update-gui
dokku config:set composer-gitlab-update-gui FLOW_CONTEXT=Production/Dokku

Configuration

  • Change default port mapping: dokku config:set –global DOKKU_PROXY_PORT_MAP=http:81:5000
  • Procfile : Start application e.g. web: bundle exec puma -C config/puma.rb
  • app.json : Run command at deployment time, sent .env vars
  • .buildpacks : Define a buildpack e.g.
    https://github.com/heroku/heroku-buildpack-nodejs.git#v131
    https://github.com/heroku/heroku-buildpack-php.git#v145
  • Set PHP version and enable extensions in composer.json:
    {
        "require": {
          "php": "~5.6.0",
          "ext-gd": "*",
          "ext-xsl": "*"
        }
    }
  • Set Nodejs, yarn, npm version in package.json:
    {
    ...
      "engines": {
        "node": "10.12.0",
        "yarn": "1.12.1",
        "npm": "6.4.1"
      },
    ...
    }

Example Jobs

stages:
  - deploy

variables:
  APP_NAME: ruby-rails-sample
  DOKKU_SERVER: dokku.knallimall.org
  DOKKU_SSH_PORT: 22
deploy:
  image: ilyasemenov/gitlab-ci-git-push
  stage: deploy
  environment:
    name: production
    url: https://$APP_NAME.$DOKKU_SERVER/
  only:
    - master
  script:
    - git-push ssh://dokku@$DOKKU_SERVER:$DOKKU_SSH_PORT/$APP_NAME

review_app:
  image: ilyasemenov/gitlab-ci-git-push
  stage: deploy
  environment:
    name: review-$CI_COMMIT_REF_NAME
    url: https://$CI_COMMIT_REF_NAME.$DOKKU_SERVER/
    on_stop: stop_review_app # Destroy app when branch is deleted @see https://docs.gitlab.com/ee/ci/yaml/#environmenton_stop
  only:
    - branches
  except:
    - master
  script:
    - mkdir -p ~/.ssh && echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
    - ssh-keyscan -H $DOKKU_SSH_PORT "$DOKKU_SERVER" >> ~/.ssh/known_hosts
    - ssh -t dokku@$DOKKU_SERVER -- apps:clone --ignore-existing --skip-deploy "$APP_NAME" "$CI_COMMIT_REF_NAME"
    - git-push ssh://dokku@$DOKKU_SERVER:$DOKKU_SSH_PORT/$CI_COMMIT_REF_NAME

stop_review_app:
  image: ilyasemenov/gitlab-ci-git-push
  stage: deploy
  environment:
    name: review-$CI_COMMIT_REF_NAME
    action: stop
  when: manual
  script:
    - mkdir -p ~/.ssh && echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
    - ssh-keyscan -H $DOKKU_SSH_PORT "$DOKKU_SERVER" >> ~/.ssh/known_hosts
    - ssh -t dokku@$DOKKU_SERVER -- --force apps:destroy "$CI_COMMIT_REF_NAME"
dokku_gitlab.txt · Last modified: 2018/11/04 20:18 by admin