Creating remote apt repos on github
If you read my last blog post, you would know that I am really into deploying applications and systems with deb and rpm packages whenever possible. One of the things you will eventualy want to do, to make deb and rpm package deployment easier, is to create a remote apt or yum repo to host your packages. One of the cooler tricks I have come up with in recent times is creating apt/yum repos in obscure locations.
This aritical will go over how to host an apt repo inside of a git repo on github. This little trick has the following benifits:
- free hosting for you apt repo
- publicly availability
- provide a single location for source code and packages.
Yes, I am aware there are free services to host deb and rpm packages, but sometimes, for various reasons, these serices dont fit the bill. While turning github into a remote apt repo is a strange technique, I do find it to be very useful. Keep in mind, you can use this technique on various other free services which you wouldnt expect to funciton as a remote apt repository. Basicly, if you can upload a directory structure and files, you can turn it into an apt or yum repo.
Install Dependancies for Creating our Repo
- First, on our local system, we need to install some dependancies for creating our apt repo which we will upload to github.
For this step, you will need an Debian or Ubuntu system.
sudo apt-get install reprepro
Create the Repo Directory Stucture
Feel free to change "myrepo" to whatever you like. If you do, just remember to also do so in consecutive steps.
mkdir -p myrepo/{conf,incoming}
Setup The Core Apt Repo Config File
In this step we will create the main config file for our apt repo. There are many cusomization options in this step.
Suite is typicaly set to either
stable
orunstable
Codename can be anything you wish but is typicaly set to the short name release version of the Debian or Ubuntu distribution such as
wheezy
,sid
,jessie
,lucid
,precise
,trusty
,utopic
,vivid
Architecture is typicaly set as one of the following
i386
,amd64
orarmel
If you want to include multiple architectures in your repo, just include them on the architeres line but seperate each value with a space
More advanced documentation on
conf/distributions
files can be found herecd myrepo cat <<EOF >> conf/distributions Origin: Hackgnar Label: Hackgnar Github Suite: stable Codename: wheezy Architectures: armel Components: main Description: Debian ARM packages hosted on hackgnars github repository EOF
Add a deb package to your apt repo
- Before we finish up and upload our apt repo to github, we have to add some deb packages to it.
Make sure the deb packages you use in the following step are of the same architecture you used in the previous step.
reprepro includedeb wheezy ../my_deb_package.deb
If you get errors with the above command, try running the following instead:
reprepro -S utils includedeb wheezy ../my_deb_package.deb
Turn your Apt repo into a git repo and upload it
- This step requires that you have create a new git repo on github. If you have not, you can read how to do so here
- Also make sure that you have setup your github ssh keys so you can properly push your repo to github.
finally, this example uses
git@github.com:hackgnar/myrepo.git
but you will replace that with your initialized github repo.cd ~/src/myrepo git init git add -A git commit -a -m "initial commit" git remote add origin git@github.com:hackgnar/myrepo.git git push -u origin master
(Optional) Connect a system to your new apt repo and install something:
- This step shows you how to connect a new system to your newly created apt repo and install a package from it. Note that we have to install and use `
apt-transport-https
as a dependancy because apt-get does not support https by default. - make sure to replace
hackgnar
with the name you use for your github account - make sure to replace
myrepo
with the name you used for your github repo make sure to replace
my-package-name
with the name of the deb package you installed into your reposudo apt-get install apt-transport-https cat << EOF >> /etc/apt/sources.list deb https://raw.githubusercontent.com/hackgnar/myrepo/master main EOF sudo apt-get update sudo apt-get install my-package-name
Summary
If you have read this far, hopefully you found this weird tutorial to be useful. While this apt hosting technique may not work for everyone, I have found it to be very handy. Also, keep in mind that there are limitations to this technique. One such example is github file size limitations which will restrict the size of the deb packages you invlude in your repo. Let me know what you think and what other services you find that allow you to host deb packages using this technique.
Just a question, would it not be possible to use the `gh-pages` branch instead of `master`? That way I think the repo would be accessible under a https://hackgnar.github.io/myrepo URL, which I think is slightly nicer than going through raw.githubusercontent.com. I haven't tried this myself yet though.
ReplyDelete