Dokku

  • Deploy PostgREST to Dokku

    Here is a list of steps to deploy a PostgREST instance to Dokku.

    Create a new app.

    dokku apps:create pgrest-myproject

    Add a port mapping from 3000 (PostgREST container) to 80 (host).

    dokku ports:add pgrest-myproject http:80:3000

    Create a new PostgreSQL database using the dokku-postgres plugin and link it to our project.

    dokku postgres:create pgrest-myproject
    dokku posgres:link pgrest-myproject pgrest-myproject

    A new environment variable will be created:

    =====> pgrest-myproject
    DATABASE_URL: postgres://postgres:alongpass@dokku-postgres-pgrest-myproject:5432/pgrest_myproject

    But we need to define the same value in a variable named PGRST_DB_URI so PostgREST can access the database.

    dokku config:set pgrest-myproject PGRST_DB_URI="postgres://postgres:alongpass@dokku-postgres-pgrest-myproject:5432/pgrest_myproject"

    Pull and deploy the Docker image from dockerhub.

    docker pull postgrest/postgrest:latest
    docker tag postgrest/postgrest:latest dokku/postgrest:latest
    dokku git:from-image pgrest-myproject dokku/postgrest:latest

    Add a Let’s Encrypt TLS certificate with the Dokku letsencrypt plugin.

    dokku letsencrypt:set pgrest-myproject email <your-email>
    dokku letsencrypt:enable pgrest-myproject
  • Deploy Gitea to Dokku

    Requirements

    Steps

    Create an application.

    dokku apps:create gitea

    Expose the ports for http and ssh. By default, gitea exposes 3000 for http and 22 for ssh. We want our application to listen externally on port 80, but we need to map our ssh to a different port because 22 is used by the host.

    We will rely on the docker-options plugin to expose ssh properly.

    # expose container `http` port 3000 on host `http` port 80
    dokku proxy:ports-add gitea http:80:3000
    
    # expose the container port 22 on host port 2222
    dokku docker-options:add git deploy -p 2221:22

    Add a rule in your firewall to allow connections on 2221.

    sudo ufw allow 2221/tcp

    Create a storage directory for the Gitea files.

    sudo mkdir /var/lib/dokku/data/storage/gitea_data
    sudo chown user:user /var/lib/dokku/data/storage/gitea_data
    dokku storage:mount gitea /var/lib/dokku/data/storage/gitea_data:/data

    Pull and deploy the Docker image from dockerhub.

    docker pull gitea/gitea:latest
    docker tag gitea/gitea:latest dokku/gitea:latest
    dokku git:from-image gitea dokku/gitea:latest

    Add a Let’s encrypt TLS certificate with the Dokku letsencrypt plugin.

    dokku letsencrypt:set git email <your-email>
    dokku letsencrypt:enable git

    Now, go visit gitea.<yourdomain>, e.g., gitea.yourdomain.com.

    Configuration

    Most of the options are autopopulated, use the following settings as needed.

    • Get the database information from dokku postgres:info gitea.
    • Set the SSH port as 2221. Gitea will use this to format your projects’ SSH connection info in the UI.

    Resources

    No artificial intelligence was used in the making of this post.