Skip to content

Instantly share code, notes, and snippets.

@michaelklishin
Last active October 31, 2023 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelklishin/473390eaf012e2edeb72936f183192a7 to your computer and use it in GitHub Desktop.
Save michaelklishin/473390eaf012e2edeb72936f183192a7 to your computer and use it in GitHub Desktop.

How to set up a RabbitMQ package (apt) mirror

Below is a very brief version that demonstrates how a mirror of Team RabbitMQ's apt repository can be set up and hosted by anyone.

It assumes basic familiarity with Debian-based Linux and Nginx. There are only two tools involved:

  • apt-mirror to sync the repo (please sync from ppa1.novemberain.com which has a very ample traffic quota in comparison to our Cloudsmith account)
  • Nginx to serve the synchronized static files

A few more things that have to be set up

  • A certificate and private key pair Nginx will use to serve HTTPS traffic. They can be obtained from Cloudflare or any other way
  • A hostname Nginx will use

The above setup can happily run on a really basic VM from any providers you like. For example, a basic Digital Ocean droplet 50 GiB of storage (built-in or an extra volume) would do. Such setup would usually cost between USD 6 and USD 16 per month, depending on how much disk space you'd like to provision ahead of time.

How to set up a mirror of Team RabbitMQ's apt repository (e.g. ppa1.novemberain.com)

  1. Run apt update -y; apt upgrade -y
  2. Install apt-mirror with apt install -y apt-mirror
  3. Create an apt mirror list: touch /etc/apt/mirror.list
  4. Edit /etc/apt/mirror.list (see below)
  5. Run apt-mirror
  6. Wait for all packages to be synced (about 15 GiB worth)
  7. Inspect the local copy: /var/spool/apt-mirror/mirror/ppa1.novemberain.com/
  8. Install Nginx
  9. Obtain a pair of certificates to serve packages over HTTPS, for example, from Cloudflare
  10. Install the certificates
  11. Configure Nginx to serve the files under /var/spool/apt-mirror (see below)
  12. Set up DNS records to point to the newly synchronized mirror
  13. Use a VM or container to test the mirror on recent Ubuntu and Debian distributions, except configure /etc/apt/sources.list.d/rabbitmq.list to use the new mirror
  14. Optional: copy Cloudsmith signing keys (https://ppa1.novemberain.com/gpg.E495BB49CC4BBE5B.key, https://ppa1.novemberain.com/gpg.9F4587F226208342.key) to /var/spool/apt-mirror/mirror/ppa1.novemberain.com/public/ or a similar location so that they can be downloaded from your mirror's host and not ppa1.novemberain.com or Cloudsmith.io
  15. Voilà! You have your own mirror of the apt repositories maintained by Team RabbitMQ
  16. To sync the packages, schedule apt-mirror to run every couple of days or a week, depending on your needs

/etc/apt/mirror.list Contents

############# config ##################
#
# set base_path    /var/spool/apt-mirror
#
# set mirror_path  $base_path/mirror
# set skel_path    $base_path/skel
# set var_path     $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch  <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############

#
# Erlang
#

deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-erlang/deb/ubuntu lunar main
deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-erlang/deb/ubuntu jammy main
deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-erlang/deb/ubuntu focal main
deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-erlang/deb/ubuntu bionic main

deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-erlang/deb/debian buster main
deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-erlang/deb/debian bullseye main

#
# RabbitMQ
#

deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-server/deb/ubuntu lunar main
deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-server/deb/ubuntu jammy main
deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-server/deb/ubuntu focal main
deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-server/deb/ubuntu bionic main

deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-server/deb/debian buster main
deb https://ppa1.novemberain.com/rabbitmq/rabbitmq-server/deb/debian bullseye main

Nginx Server Definition

server {
              listen 80;
              listen 443 ssl;
              server_name ppa.yourdomain.com;
              ssl_certificate /etc/ssl/certs/yourdomain.com.pem;
              ssl_certificate_key /etc/ssl/private/yourdomain.com.key;


              location / {
                      alias /var/spool/apt-mirror/mirror/ppa1.novemberain.com/;
                      try_files $uri $uri/ =404;
              }

              location /mirrors {
                      alias /var/spool/apt-mirror/mirror/ppa1.novemberain.com/;
                      try_files $uri $uri/ =404;
              }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment