aptly-based-repository-setup.md 5.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
# Aptly Setup Walkthorugh

### Terminology
#### mirror
Copy of a remote repository.
Mutable: Yes

#### repo
Repository that contains packages.
- Local (Testing)
  The local copy of the repository you’re trying to build. Should be accessible to the user testing
  and serving it.
  Server: Aptly HTTP Server
  Mutable: Yes
- Published (Production)
  The public and published version with GPG keys. Should be in a publicly accessible folder.
  Server: nginx
  Mutable: Shoud not be


#### snapshot
A locked version of a repo or mirror.
Mutable: No

### Things to take care of
 - You should only publish a snapshot. This will make sense if we have to rollback to a previous
   state.
 - Packages should only be replaced in the local repo.
 - Configuration of maximum open files should be highest else aptly would crash complaining
   that you have reached the maximum number of open files.
 - Always create a new snapshot after making any changes.
 - Avoid creating contents index unless necessary because it
   - takes long time
   - leads to several lock issues as new packages arrive to the server and cannot be added to the
     repository because of Aptly DB being locked 
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
36 37


38
### Procedure
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
39 40 41 42 43 44 45 46 47 48
1. Create Debian testing multi-component mirrors
2. Update the created mirrors
3. Create a snapshots of the mirrors
4. Create an empty repo
5. Add hamara packages with force replace option to the repo created in above step
6. Create a snapshot from this repo
7. Merge the new snapshot with the snapshot of main component
8. Publish merged snapshot, contrib snapshot and non-free snapshot
9. Add the appropriate sources to apt sources
10. Add your GPG key to APT with apt-key
49 50 51 52 53


On the side,
Add a hook in GitLab to repeat steps 4-7 above on every successful build of Hamara packages

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
54

55
### Useful commands
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
56 57
 ```
 $ aptly mirror create <mirror-name> http://deb.debian.org/debian <distribution> [<component>]
58
 
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
59
 $ aptly mirror update <mirror-name>
60 61 62
 
 $ aptly mirror list
 
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
63
 $ aptly mirror show <mirror-name>
64
 
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
65
 $ aptly snapshot create <snapshot-name> from mirror <mirror-name>
66 67 68
 
 # Note: Make sure to have successfully updated the mirror before running this command.
 
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
69
 $ aptly repo create <repo-name> from snapshot <some-snapshot>
70
 
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
71
 $ aptly repo add <repo-name> <hamara_package_directory>
72
 
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
73
 $ aptly snapshot create <snapshot-name> from repo <repo-name>
74
 
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
75 76
 $ aptly publish snapshot <snapshot-name>

77 78 79 80 81
 # Note: If the snapshot needs to be published with the source packages (`.dsc`, `*tar*` and so),
 use the following command

 $ aptly publish snapshot -architectures=source,<other-archs> <snapshot-name>

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
82
 $ aptly publish drop <distribution-name> <publish-name>
83 84 85 86 87 88 89 90
```

### Setup of a repository with multi components ( main, contrib, non-free)


[Multi component setup of repository](https://www.aptly.info/doc/feature/multi-component/)


Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
91 92
### 1. Create mirrors from upstream repositories

93
```
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
94 95 96 97 98 99
# aptly mirror create testing-main http://deb.debian.org/debian testing main

# aptly mirror create testing-contrib http://deb.debian.org/debian testing contrib

# aptly mirror create testing-non-free http://deb.debian.org/debian testing non-free

100
```
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
101 102 103

### 2. Update the mirrors

104
```
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
105
# aptly mirror list -raw | xargs -n 1 aptly mirror update
106 107
```

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
108
### 3. Create snapshots from these mirrors
109

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
110 111
```
# aptly snapshot create <codename>-<version>-main-<date> from mirror testing-main
112

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
113
# aptly snapshot create  <codename>-<version>-contrib-<date> from mirror testing-contrib
114

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
115 116
# aptly snapshot create  <codename>-<version>-non-free-<date> from mirror testing-non-free
```
117

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
118
### 4. Create a repo for Hamara inhouse packages
119

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
120 121 122
```
# aptly repo create hamara-packages
```
123

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
124
### 5. Add Hamara inhouse packages to the newly created repo
125

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
126 127 128 129 130 131 132 133 134 135
```
# aptly repo add hamara-packages <packages-directory>

```

### 6. Create snapshot of the repo

```
# aptly create snapshot <codename>-<version>-inhouse-<date> from repo hamara-packages
```
136

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
137 138 139 140
### 7. Merge the snapshots

```
# aptly snapshot merge <codename>-<version>-main-w-inhouse-<date> <codename>-<version>-main-<date> <codename>-<version>-inhouse-<date>
141 142
```

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
143
### 8. Publish the snapshots
144

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
145 146 147 148
```
# aptly publish snapshot -skip-contents -skip-signing -component=,, <codename>-version-main-w-inhouse-<date> <codename>-<version>-contrib-<date> <codename>-<version>-non-free-<date>
```
**NOTE**: Use `skip-signing` only for testing purposes.
149

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
150 151 152 153 154

### 9. Serve the published snapshots

```
aptly serve -listen=":8000"
155
```
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
**NOTE**: Serve on a port that is accessible to you.


Check out the perfect multi-component published repo on `<server-address>:8000`


## HELP!

Following things are still left to be done and require help. Please note that you would require access to entire infrastructure in order to be able to do this.

1. Updations to .gitlab-ci.yml

Deployment procedure of the local packages from gitlab to the server is to be added and tested.

Added: No
Tested: No

TBD by: Shivani Bhardwaj


2. Dockerfile

A Dockerfile replicating all the procedure written above is required to be written.

Added: No
Tested: No

TBD by: -


3. nginx configuration for hosting

nginx.conf to serve the published repos is required to be added on the server.

Added: No
Tested: No

TBD by: Shivani Bhardwaj


4. GPG key signing of packages

Currently the published repo is not signed. Use the Hamara GPG key to sign the repos before publishing them.

Done: No
Tested: No

TBD by: -


5. Adding package source to the repos

Currently only `.deb` files have been added to the repo but the source files like `.dsc`, `*tar*` should also be there. Figure out how to do that.

Done: No
Tested: No
212

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
213
TBD by: -