aptly-based-repository-setup.md 5.27 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 77
 $ aptly publish snapshot <snapshot-name>

 $ aptly publish drop <distribution-name> <publish-name>
78 79 80 81 82 83 84 85 86
```


### 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
87 88
### 1. Create mirrors from upstream repositories

89
```
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
90 91 92 93 94 95
# 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

96
```
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
97 98 99

### 2. Update the mirrors

100
```
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
101
# aptly mirror list -raw | xargs -n 1 aptly mirror update
102 103
```

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
104
### 3. Create snapshots from these mirrors
105

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
106 107
```
# aptly snapshot create <codename>-<version>-main-<date> from mirror testing-main
108

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

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

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

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
116 117 118
```
# aptly repo create hamara-packages
```
119

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

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
122 123 124 125 126 127 128 129 130 131
```
# aptly repo add hamara-packages <packages-directory>

```

### 6. Create snapshot of the repo

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

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
133 134 135 136
### 7. Merge the snapshots

```
# aptly snapshot merge <codename>-<version>-main-w-inhouse-<date> <codename>-<version>-main-<date> <codename>-<version>-inhouse-<date>
137 138
```

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
139
### 8. Publish the snapshots
140

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
141 142 143 144
```
# 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.
145

Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
146 147 148 149 150

### 9. Serve the published snapshots

```
aptly serve -listen=":8000"
151
```
Shivani Bhardwaj's avatar
Shivani Bhardwaj committed
152 153 154 155 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
**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
208

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