Skip to content

Instantly share code, notes, and snippets.

@chrisjsimpson
Created August 1, 2021 19:03
Show Gist options
  • Save chrisjsimpson/77c7a642d0e702ff04f4a4e195927955 to your computer and use it in GitHub Desktop.
Save chrisjsimpson/77c7a642d0e702ff04f4a4e195927955 to your computer and use it in GitHub Desktop.

Revisions

  1. chrisjsimpson created this gist Aug 1, 2021.
    179 changes: 179 additions & 0 deletions notes.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,179 @@


    ## blank slate setup

    install dokku, visit in browser to complete install
    genrate ssh key for github actions/dokku server using ssh-keygen, and copy the private key to the github repo secrets.

    ### Create front-end app

    dokku apps:create front-end
    dokku git:initialize front-end
    dokku git:set front-end deploy-branch main;
    dokku docker-options:add front-end build --file=/home/dokku/front-end/Dockerfile;


    HOOK:
    vi front-end/hooks/pre-receive

    ```
    #!/usr/bin/env bash
    set -e
    set -o pipefail
    curl https://raw.githubusercontent.com/KarmaComputing/salon-booking-guru/main/front-end/Dockerfile > /home/dokku/front-end/Dockerfile
    cat | DOKKU_ROOT="/home/dokku" dokku git-hook front-end
    ```

    On local: do first push to trigger initial app build.

    git remote add dokku-front-end dokku@<ip-address>:front-end

    git push dokku-front-end main

    Visit application
    front-end.dokku.karmacomputing.co.uk



    ### Create database

    dokku apps:create database
    dokku git:initialize database
    dokku git:set database deploy-branch main;
    dokku docker-options:add database build --file=/home/dokku/database/Dockerfile;


    HOOK:
    vi database/hooks/pre-receive

    ```
    #!/usr/bin/env bash
    set -e
    set -o pipefail
    curl https://raw.githubusercontent.com/KarmaComputing/salon-booking-guru/main/database/Dockerfile > /home/dokku/database/Dockerfile
    cat | DOKKU_ROOT="/home/dokku" dokku git-hook database
    ```

    On local: do first push to trigger initial app build.

    git remote add dokku-database dokku@<ip-address>:database

    git push dokku-database main



    ### Create api app
    dokku apps:create api
    dokku git:initialize api
    dokku git:set api deploy-branch main;
    dokku docker-options:add api build --file=/home/dokku/api/Dockerfile;


    HOOK:
    vi api/hooks/pre-receive

    ```
    #!/usr/bin/env bash
    set -e
    set -o pipefail
    curl https://raw.githubusercontent.com/KarmaComputing/salon-booking-guru/main/api/Dockerfile > /home/dokku/api/Dockerfile
    cat | DOKKU_ROOT="/home/dokku" dokku git-hook front-end
    ```

    On local: do first push to trigger initial app build.

    git remote add dokku-api dokku@<ip-address>:api

    git push dokku-api main

    On the dokku server rebuild:
    ```
    dokku ps:rebuild api
    ```


    ## SSH setup

    - generate a key with ssh-keygen
    - copy the public key in ~/.ssh/authorized_keys # yes really
    - Add the key to dokku `cat ~/.ssh/id_rsa.pub | dokku ssh-keys:add github`


    ## Validate

    ```
    dokku@dokku:~$ dokku docker-options:report front-end
    =====> front-end docker options information
    Docker options build: --file=/home/dokku/salon-booking-guru/front-end/Dockerfile
    Docker options deploy: --restart=on-failure:10
    Docker options run:
    ```

    Add to `/home/dokku/front-end/hooks/pre-receive`:

    mkdir -p /home/dokku/front-end && curl https://raw.githubusercontent.com/KarmaComputing/salon-booking-guru/main/front-end/Dockerfile > /home/dokku/front-end/Dockerfile

    > If you need to reset / clear the options
    1. take a copy of *all* existing settings
    `dokku docker-options:report front-end`
    2. Clear the options `dokku docker-options:clear`
    3. Add the settings back you want for each stage
    e.g. `dokku docker-options:add front-end deploy --restart=on-failure:10`



    # Api setup env

    dokku config:set api SALON_BOOKING_GURU_DB_HOST=database.web

    dokku config:set api SALON_BOOKING_GURU_DB_PORT=5432

    dokku config:set api SALON_BOOKING_GURU_DB_PASSWORD="changeme"

    dokku config:set api SALON_BOOKING_GURU_DB_DBNAME="salon_booking_guru"

    dokku config:set api SALON_BOOKING_GURU_DB_USER="postgres"


    Verify settings:

    dokku config:show api

    # Database setup env

    dokku config:set database POSTGRES_PASSWORD="changeme"

    dokku config:set database POSTGRES_DB=salon_booking_guru

    # Networking

    dokku network:create mynetwork


    dokku network:set database attach-post-create mynetwork
    dokku network:set api attach-post-create mynetwork

    dokku ps:rebuild database
    dokku ps:rebuild api # or must re-push if never previously successful


    # Destroy / Uninstall

    > Warning: This will remove all dokku apps on the dokku server, by force.
    ```
    dokku apps:list | tail -n +2 | xargs --max-args 1 dokku apps:destroy --force
    ```


    ## Get the web addresses of apps deployed
    ```
    dokku domains:report
    ```