Skip to content

Instantly share code, notes, and snippets.

@Luchanso
Forked from kjlape/Dockerfile
Created November 3, 2024 09:32
Show Gist options
  • Save Luchanso/5c403ad3df8e6afb26325615b5e54a7a to your computer and use it in GitHub Desktop.
Save Luchanso/5c403ad3df8e6afb26325615b5e54a7a to your computer and use it in GitHub Desktop.

Revisions

  1. @kjlape kjlape revised this gist Oct 26, 2024. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -23,5 +23,4 @@ On your local machine…
    - Ensure the credentials you gave it are configured in your kamal secrets
    - Run the steps to deploy
    - Optional: Replace the ngrok url with your freshly deployed docker registry
    - I also have a [video about this on YouTube](FREE Docker Registry for Rails Apps No Cloud Required! 🎯
    https://youtu.be/9MkqGQbcqkI)
    - I also have a [video about this on YouTube](https://youtu.be/9MkqGQbcqkI)
  2. @kjlape kjlape revised this gist Oct 26, 2024. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -22,4 +22,6 @@ On your local machine…
    - Copy the ngrok url, and place it in your kamal config under `registry`/`server`
    - Ensure the credentials you gave it are configured in your kamal secrets
    - Run the steps to deploy
    - Optional: Replace the ngrok url with your freshly deployed docker registry
    - Optional: Replace the ngrok url with your freshly deployed docker registry
    - I also have a [video about this on YouTube](FREE Docker Registry for Rails Apps No Cloud Required! 🎯
    https://youtu.be/9MkqGQbcqkI)
  3. @kjlape kjlape created this gist Oct 25, 2024.
    1 change: 1 addition & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    FROM registry:2
    25 changes: 25 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    ### Problem

    Kamal smooths over a lot of the rough edges of hosting an app on a server you control.
    One problem that needs a little more sanding is that kamal requires us to have a docker registry to push our images to.
    Unless you're doing open source, you probably want these app images to stay private!
    Until we get an official answer from kamal here's a workaround that I've been using.

    Be aware that you _still need some kind of public image hosting_ due to limitations in kamal as of version 2.2.2.
    There's a hack at the bottom of this document to work around this limitation as well.

    ### Steps to deploy
    - Change values in the deploy config to suit your setup
    - Run `kamal deploy`
    - Run `kamal htpasswd-set <username> <password>` to set as many credentials as you need or rotate keys
    - Enjoy!

    ### Optional: Self-host (Do this before deploying)
    On your local machine…
    - `docker run --volume ./auth:/auth --rm --entrypoint htpasswd httpd:2 -Bb /auth/htpasswd <username> <password>`
    - `docker run --volume ./auth:/auth --rm --port 5000:5000 -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry:2`
    - In another terminal `ngrok http 5000`
    - Copy the ngrok url, and place it in your kamal config under `registry`/`server`
    - Ensure the credentials you gave it are configured in your kamal secrets
    - Run the steps to deploy
    - Optional: Replace the ngrok url with your freshly deployed docker registry
    37 changes: 37 additions & 0 deletions deploy.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    service: docker-registry
    image: my-company/docker-registry
    servers:
    web:
    - 1.3.3.7

    proxy:
    ssl: true
    host: docker.my-company.com
    app_port: 5000
    healthcheck:
    path: /

    registry:
    username: username
    server: <some url>.ngrok-free.app
    password:
    - KAMAL_REGISTRY_PASSWORD

    builder:
    arch: arm64 # This is the platform I tested on, but it should work on any platform.

    volumes:
    - auth:/auth

    env:
    clear:
    REGISTRY_HTTP_ADDR: 0.0.0.0:5000
    REGISTRY_AUTH: htpasswd
    REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
    REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd

    aliases:
    shell: app exec --interactive --reuse "sh"
    htpasswd-set: server exec docker run --volume auth:/auth --rm --entrypoint htpasswd httpd:2 -Bb /auth/htpasswd
    htpasswd-delete: server exec docker run --volume auth:/auth --rm --entrypoint htpasswd httpd:2 -D /auth/htpasswd
    htpasswd-print: server exec docker run --volume auth:/auth --rm --entrypoint cat httpd:2 /auth/htpasswd