Skip to content

Instantly share code, notes, and snippets.

@huksley
Last active January 12, 2024 17:24
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save huksley/70c8615f41c7871700c1dafbf518654c to your computer and use it in GitHub Desktop.
Save huksley/70c8615f41c7871700c1dafbf518654c to your computer and use it in GitHub Desktop.
mrsk - the missing manual

MRSK

This documentation adds important additions to the docs for mrsk deploy tool (see github.com/mrsked/mrsk)

Destination flag

You can use mrsk deploy --destination staging

This will read config/deploy.yml and config/deploy.staging.yml files, and also will read .env.staging file if it exists.

https://github.com/mrsked/mrsk/blob/9ec3895dab2772915c44f3a348e54de58981857d/lib/mrsk/cli/base.rb#L34

ENV vars

Both .env and .env.#destination are loaded into process env vars. So you can naturally use just process env and tools like chamber to load secrets.

So you can use them in deploy.yml this way:

servers:
  web:
    hosts: 
      - <%= ENV["APPHOST"] %>

YAML anchors

You can reference other parts of structure using &anchor and *ancho to keep to D.R.Y. principle, for example:

servers:
  web:
    hosts: 
      - &host 10.1.1.1
accessories:
  redis:
    image: redis:latest
    host: *host

Using vars in config/deploy.yml

mrsk uses ERB Ruby module to read config:

https://github.com/mrsked/mrsk/blob/9ec3895dab2772915c44f3a348e54de58981857d/lib/mrsk/configuration.rb#L29

So you can use all of these in deploy.yml:

<% Ruby code -- inline with output %>
<%= Ruby expression -- replace with result %>

Mounting files in accessories

You can provide locally located file to be mounted as volume for the accessories. Files are uploaded and put into the home folder for SSH user.

For example:

service: test
accessories:
  registry:
    image: registry:2
    host: 10.1.1.1
    port: 5000
    files:
      # Will be placed to ${USER}/test-registry folder
      # and mounted inside the container at the specified path
      - ./config/htpasswd:/etc/docker/registry/htpasswd
    env:
      clear:
        REGISTRY_HTTP_ADDR: 0.0.0.0:5000
        REGISTRY_AUTH: htpasswd
        REGISTRY_HTTP_SECRET: asecretforlocaldevelopment
        REGISTRY_AUTH_HTPASSWD_PATH: /etc/docker/registry/htpasswd
        REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm

When you do mrsk accessory boot registry

It will upload the local file config/htpasswd to the host, and then launch docker with the --volume ${LOCALPATH}:/etc/docker/registry/htpasswd argument.

Notes

  • File will never be updated, to update it you need to remove the accessory (sic!) and then boot it again manually.
  • If local file ends with .erb it will be read as ERB template, with env.clear: vars available.

Mounting directories in accessories

service: test
accessories:
  registry:
    image: registry:2
    host: 10.1.1.1
    port: 5000
    directories:
      # Will be copied to ${USER}/test-registry folder
      # and mounted inside the container at the specified path
      - ./config:/etc/docker/registry/

The same syntax allows to mount local directories inside accessories, by copying local files to the remote host first, then constructing a volume argument to the docker command.

Please note, that files in that directory are removed automatically when you remove accessory and copied from local host only when you boot accessory.

@PabloC
Copy link

PabloC commented May 9, 2023

Thanks for this!

@huksley
Copy link
Author

huksley commented May 15, 2023

@danthegoodman1
Copy link

PR some of these back in! They are open to README enhancements, I've made one myself

@huksley
Copy link
Author

huksley commented Aug 21, 2023

@huksley
Copy link
Author

huksley commented Aug 29, 2023

MRSK renamed to kamal https://kamal-deploy.org/ 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment