├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── NOTE.md ├── README.md ├── develop ├── auth_config.yml ├── creds.txt ├── devcompose.yml ├── fillrepo.py ├── golang │ └── Dockerfile ├── htpasswd ├── server.key └── server.pem ├── img ├── conf.png ├── history.png ├── info.png └── parents.png └── project ├── DFalpine ├── DFdebian ├── main.go ├── resources ├── map.css └── treant.css ├── src ├── checker │ ├── checker.go │ ├── manifest.go │ ├── parents.go │ ├── repository.go │ └── tags.go ├── conf │ └── conf.go ├── db │ ├── alias.go │ ├── db.go │ ├── delete.go │ ├── get.go │ ├── put.go │ ├── schema.go │ └── upgrade.go ├── dt │ └── dt.go ├── handler │ ├── deleteimage.go │ ├── info.go │ ├── main.go │ ├── managerepos.go │ ├── render.go │ ├── repograph.go │ ├── updateall.go │ └── upgradedb.go ├── qurl │ ├── qurl.go │ └── qurl_test.go ├── say │ └── say.go └── utils │ └── utils.go └── templates ├── catalogbar.html ├── info.html ├── managerepos.html ├── manifestbar.html ├── repobar.html ├── repograph.html ├── tagbar.html └── topbar.html /.gitignore: -------------------------------------------------------------------------------- 1 | project/asapdrf.db 2 | project/pkg 3 | project/src/github.com 4 | project/main 5 | project/resources/treant-js 6 | 7 | develop/app 8 | develop/registry* 9 | 10 | asapdrf.db* 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Build 27.1 2 | == 3 | (2020.07.03) 4 | - CSS fixes [issue #16](https://github.com/Evedel/bow/issues/16) 5 | 6 | Build 26.1 7 | == 8 | (2018.02.06) 9 | - Added alpine based image, as requested in [pr #1](https://github.com/Evedel/bow/pull/12), changed labelling system. 10 | 11 | Build 26 12 | == 13 | (2017.11.19) 14 | - Fix: free format for service name in bearer token [issue #10](https://github.com/Evedel/bow/issues/10) 15 | 16 | Build 25 17 | == 18 | (2017.09.01) 19 | - Add: namespace level [issue #9](https://github.com/Evedel/bow/issues/9) 20 | - Add: filters on graph page [issue #9](https://github.com/Evedel/bow/issues/9) 21 | - Fix: list not only [first 100](https://github.com/docker/distribution/blob/b6e0cfbdaa1ddc3a17c95142c7bf6e42c5567370/registry/handlers/catalog.go#L16) but all of the images [issue #9](https://github.com/Evedel/bow/issues/9) 22 | - Add: timewatch for handlers and daemons 23 | - Add: script to fill test repo 24 | - Fix: loops brake parentgraph when there were copies in repo 25 | 26 | Build 24 27 | == 28 | (2017.02.18) 29 | - Fix: Wrong permissions when creating /var/lib/bow/ as non-root user [issue #8](https://github.com/Evedel/bow/issues/8) 30 | - Rename smurf names in checker, underscore to camel in db/schema/recursive 31 | 32 | Build 23 33 | == 34 | (2017.02.18) 35 | - Fix: Can't authenticate when using a password with percent symbol [issue #7](https://github.com/Evedel/bow/issues/7) 36 | - Fix: Actualised Tests 37 | 38 | Build 22 39 | == 40 | (2017.02.04) 41 | - Fix: panic in parents search for committed images [issue #5](https://github.com/Evedel/bow/issues/5) 42 | - Autoscroll to chosen element 43 | 44 | Build 21 45 | == 46 | (2016.12.23) 47 | - Added ugly button to force bow to update all info 48 | - DB refactoring finished 49 | - db.tag : deleted, created alias, added precreation of non-existed buckets for new tag 50 | - db.catalog : the same as for db.tag 51 | - QURL refactoring finished 52 | - Fixed isues where bow was not able to make bearer auth reqest for HEAD/DELET/headers requests 53 | - Nice & compact method capable to serv all reqest 54 | - Fix: error when registry storage was changed externally 55 | - Fix: random order of repos/names/tags 56 | - Fix: error for non-existing catalogs just after creation 57 | - Fix: db.upgrade for the most old versions 58 | 59 | Build 20 60 | == 61 | (2016.12.04) 62 | - Added possibility to login through bearer token 63 | - Added explicit secure/insecure checkbox in repo config 64 | - DB schema redesign 65 | - add '_info' bucket to store confings, move configs into it and create upgrade way 66 | - from 'repo.go' to general 'db' middleware 67 | - add db versions, check it in each restart, do upgrade if needed 68 | - Splitted 'db' => 'put', 'get', 'delete', 'schema', 'upgrade' and 'alias' 69 | - Splitted main.go => package 'handler' + package 'main' 70 | - Added full test env (auth server, basic auth registry and token based auth) + gitignore 71 | - Fixed error in blob size conversion 72 | 73 | Build 19 74 | == 75 | (2016.11.01) 76 | - API compatibility covered by tests 77 | - Fixed time conversion bug for Manifest Daemon 78 | - Upgrade moved from db to utils 79 | - Size conversion moved from db to utils 80 | - MakeQueryToRepo now operate with http status codes 81 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /NOTE.md: -------------------------------------------------------------------------------- 1 | __BS_LOG_SILENT__ -- level of output logging 2 | nothing - ful logging, default 3 | `yes` - only error and warn mesages 4 | `super` - without any output 5 | 6 | __BS_DB_PATH__ -- path to store your db 7 | `/var/lib/bow` 8 | 9 | __BS_DB_NAME__ -- name of db and db file 10 | `asapdrf.db` 11 | 12 | __BS_SERVE_ADD__ -- port to serve 13 | `:19808` - default port for app 14 | 15 | __BS_CHECKER_TIMEOUT__ -- timeout for daemons tictac in seconds 16 | `300` -- default time to renew data 17 | 18 | __BS_TIME_WATCH__ -- timewatch for daemons and handlers 19 | `yes` - print time of execution in log (level2) 20 | 21 | 22 | BoltDB levels 23 | ``` 24 | {DB} --{ _info } => [ version:V ] 25 | \ 26 | (b){repositories} ,{ _info } => [ host:bow.example.com pass:test scheme:https user:test secure:false] 27 | \ / 28 | (br){reponame[N]}-*-{ _names }-*-{ imagename }---[ datetime => last_name ] 29 | \ \ : 30 | (brc){catalog} '--{ _namesgraph } : 31 | \ : 32 | (brcn){imagename[N]}--*--[ _valid => 0 || 1 ] : 33 | \ \-{ _namepair }-[namespace : name] : 34 | \ \-{ _uploads }---[ date => count ] : 35 | \ : 36 | (brcnt){tags}--* : 37 | \ : 38 | [ _valid => 0 || 1 ]--*--{ _uploads }---[ date => count ] : 39 | \ : 40 | \--[ digest => header:digest ]................: 41 | \ 42 | \--{ history }--[ datetime => (command + blob:{sha256, size} ] 43 | *--{ _totalsizehuman }--[ datetime => size ] 44 | |--{ _totalsizebytes }--[ datetime => size ] 45 | '--[ _parent => name:tag ] 46 | ``` 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Bow 2 | == 3 | ## As simple as possible docker registry frontend/UI 4 | 5 | Pictures 6 | == 7 | 8 | ![](https://raw.githubusercontent.com/Evedel/bow/master/img/conf.png) 9 | 10 | ![](https://raw.githubusercontent.com/Evedel/bow/master/img/info.png) 11 | 12 | ![](https://raw.githubusercontent.com/Evedel/bow/master/img/history.png) 13 | 14 | ![](https://raw.githubusercontent.com/Evedel/bow/master/img/parents.png) 15 | 16 | Features 17 | == 18 | - V2 registries support only (secure, self-signed and insecure, DNS and IP:PORT) 19 | - internal DB ([BoltBD](https://github.com/boltdb/bolt)) gives it the ability to store info, and as the result, it responses much faster than after direct API call, and can provide more data 20 | - the app can pars, store and show info from registry such as: 21 | - image layers info: 22 | - name / tag 23 | - image size and a number of pushes 24 | - upload and push dates 25 | - an image creating commands history 26 | - it is possible to set multiple repositories and watch all registries in one place 27 | - show statistics pretty, draw curves of uploads number and image sizes for a tag with respects to dates 28 | - find a parent of an image, in case, the parent in the same repo (it is clickable!) 29 | - show tree-graph of parents for image 30 | - enabled image deletion (registry --version >= 2.4.0) 31 | - __(new)__ API compatibility checks 32 | - __(the newest)__ Bearer token auth support (secure and self-signed auth servers) 33 | - __(killerfeature)__ Namespace layer and parents graph filters 34 | 35 | Image deletion 36 | == 37 | To enable image deletion you need to: 38 | 1. Run your registry with the flag `-e REGISTRY_STORAGE_DELETE_ENABLED=true` 39 | Example: 40 | ``` 41 | docker run -d -p 5000:5000 --restart=always --name registry \ 42 | -v ./auth:/auth \ 43 | -e "REGISTRY_AUTH=htpasswd" \ 44 | -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ 45 | -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \ 46 | -e REGISTRY_STORAGE_DELETE_ENABLED=true \ 47 | registry:2 48 | ``` 49 | 2. Set up cron to run garbage collection 50 | Example: 51 | `10 * * * * docker exec registry bin/registry garbage-collect /etc/docker/registry/config.yml` 52 | 3. Also be aware, that there is a known [issue](https://github.com/docker/distribution/issues/1939) in docker registry 2.6.2 and earlier. It means, that if you delete an image from a repository, you will not able to push __the exactly same__ image in that repository. To fix it, you will need to perform rebuilding of image with `--no-cache` mode each time or restarting the registry `docker restart registry` once after deletion. 53 | 54 | See more: 55 | https://github.com/docker/docker-registry/issues/988#issuecomment-224280919 56 | https://docs.docker.com/registry/configuration/#delete 57 | https://docs.docker.com/registry/garbage-collection/#/how-garbage-collection-works 58 | 59 | Bearer token auth 60 | == 61 | What is it and how it works see [docker documentation](https://docs.docker.com/registry/spec/auth/token/). 62 | Bow was tested to work with [cesanta/docker_auth](https://github.com/cesanta/docker_auth) in [this configuration](develop/devcompose.yml). 63 | 64 | Prospects 65 | == 66 | I can say that this app almost fit my needs, so in all likelihood, soon, I will not improve it hardly, but this is the list of ideas just for case: 67 | - info for the whole repository: size, number of pushes so on so on soon 68 | - add button 'Don't Track', to store repo data but not update it 69 | - add tests for bearer token and image deletion 70 | 71 | How to start to use Bow 72 | == 73 | ``` 74 | docker run -d \ 75 | --name=Bow \ 76 | -e BS_LOG_SILENT=yes \ 77 | -e BS_TIME_WATCH=no \ 78 | -v ~/db/bow:/var/lib/bow \ 79 | -p 5001:19808 \ 80 | evedel/bow 81 | ``` 82 | 83 | There are some parameters, that can be set only as [environment variables](https://github.com/Evedel/bow/blob/master/NOTE.md). 84 | Short descriptions with default value: 85 | - ``BS_LOG_SILENT=""`` -- logging level, default is full logging 86 | - ``BS_DB_PATH="/var/lib/bow"`` -- path to store your db 87 | - ``BS_DB_NAME="asapdrf.db"`` -- name of db and db file 88 | - ``BS_SERVE_ADD="19808"`` -- port address to serve 89 | - ``BS_CHECKER_TIMEOUT="300"`` -- seconds, time to renew data 90 | - ``BS_TIME_WATCH="yes"`` -- print time of execution for qurl queries and page-renderers 91 | 92 | The full list of available tags can be found at [hub.docker.com](https://hub.docker.com/r/evedel/bow/tags/). 93 | 94 | ``evedel/bow:latest`` -- the last build based on debian:jessie image (68MB) 95 | ``evedel/bow:debian-latest`` -- the same last build based on debian image (68MB) 96 | ``evedel/bow:alpine-latest`` -- the last alpine based build (4.7MB) 97 | ``evedel/bow:debian-$(buildNumber)`` -- tagged previously [released versions](https://github.com/Evedel/bow/blob/master/CHANGELOG.md) based on debian (68MB). 98 | ``evedel/bow:alpine-$(buildNumber)`` -- tagged previously [released versions](https://github.com/Evedel/bow/blob/master/CHANGELOG.md) based on alpine (4.7MB). 99 | ``evedel/bow:$(buildNumber)`` -- tagged previously [released versions](https://github.com/Evedel/bow/blob/master/CHANGELOG.md) based on debian. 100 | 101 | 102 | How to start contribute to Bow 103 | == 104 | If you have interest, you can easily start with 105 | ``` 106 | git clone https://github.com/evedel/bow.git 107 | cd bow && git clone https://github.com/fperucic/treant-js project/resources/treant-js 108 | docker-compose -f develop/devcompose.yml up -d 109 | docker exec -it develop_golang_1 go get 110 | docker exec -it develop_golang_1 go test -v qurl -repo='https://UsErNaMe:PaSsWoRd@myownregistry.org' 111 | docker exec -it develop_golang_1 go run main.go 112 | ``` 113 | Code and packages 114 | == 115 | This app is written on golang with use of standard packages and: 116 | https://github.com/boltdb/bolt -- BoltDB 117 | https://github.com/fatih/color -- to make cli shiny 118 | https://github.com/wader/disable_sendfile_vbox_linux -- to develop on docker-machine 119 | http://www.chartjs.org/ -- to draw best graphs ever 120 | https://github.com/fperucic/treant-js -- to draw parents graphs 121 | -------------------------------------------------------------------------------- /develop/auth_config.yml: -------------------------------------------------------------------------------- 1 | server: # Server settings. 2 | # Address to listen on. 3 | addr: ":4999" 4 | # TLS certificate and key. 5 | #example.org 6 | certificate: "/server.pem" 7 | key: "/server.key" 8 | 9 | 10 | token: # Settings for the tokens. 11 | issuer: "Auth Service" # Must match issuer in the Registry config. 12 | expiration: 900 13 | 14 | 15 | # Static user map. 16 | users: 17 | # Password is specified as a BCrypt hash. Use htpasswd -B to generate. 18 | # admin:admin test:test badchar:examplepassword!%#$#$% 19 | "admin": 20 | password: "$2y$05$kUmTkns0WvC/e3euqya0G.PsVZlOpgDtGfy9Bjaf0caETBYv06l3y" 21 | "test": 22 | password: "$2y$05$vl9p1Z1nO/9QZLj3.dixiOaDJ0.d6uEpv7fJ1Jps0oiynYsyeiiTa" 23 | "badchar": 24 | password: "$2y$05$8PEr9A45y3LmLxcmu0kUw.FGS1Sbo4AjLeFVj2AhSvkxsqd.XfGCO" 25 | 26 | acl: 27 | # Admin has full access to everything. 28 | - match: {account: "admin"} 29 | actions: ["*"] 30 | - match: {account: "badchar"} 31 | actions: ["*"] 32 | # User "test" has full access to ubuntu image but nothing else. 33 | - match: {account: "test", name: "ubuntu"} 34 | actions: [] 35 | # All logged in users can pull all images. 36 | - match: {account: "/.+/"} 37 | actions: ["pull"] 38 | # Anonymous users can pull "hello-world". 39 | - match: {account: "", name: "hello-world"} 40 | actions: ["pull"] 41 | # Access is denied by default. 42 | -------------------------------------------------------------------------------- /develop/creds.txt: -------------------------------------------------------------------------------- 1 | Token 2 | admin:admin 3 | Basic 4 | test:test 5 | badchar:examplepassword!%#$#$% 6 | -------------------------------------------------------------------------------- /develop/devcompose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | 4 | golang: 5 | build: ./golang/ 6 | image: golang-1.9 7 | volumes: 8 | - ../project:/app 9 | - ../:/var/lib/bow 10 | ports: 11 | - 19808:19808 12 | links: 13 | - dockerauth:auth.example.org 14 | - registry_token:reg.example.org 15 | cap_add: 16 | - SYS_ADMIN 17 | environment: 18 | - GOPATH=/app 19 | - GOROOT=/usr/local/go 20 | - PATH=$GOPATH/bin:$GOROOT/bin:$PATH 21 | command: sleep 90000000 22 | 23 | dockerauth: 24 | image: cesanta/docker_auth 25 | ports: 26 | - "4999:4999" 27 | expose: 28 | - "4999" 29 | extra_hosts: 30 | - "auth.example.org:127.0.0.1" 31 | volumes: 32 | - ./auth_config.yml:/auth_config.yml:ro 33 | - ./server.key:/server.key 34 | - ./server.pem:/server.pem 35 | command: --v=2 --alsologtostderr /auth_config.yml 36 | 37 | registry_token: 38 | image: registry:2 39 | ports: 40 | - "5000:5000" 41 | volumes: 42 | - ./registry/t:/var/lib/registry 43 | - ./server.key:/server.key 44 | - ./server.pem:/server.pem 45 | extra_hosts: 46 | - "reg.example.org:127.0.0.1" 47 | links: 48 | - dockerauth:auth.example.org 49 | environment: 50 | - REGISTRY_AUTH=token 51 | - REGISTRY_AUTH_TOKEN_REALM=https://auth.example.org:4999/auth 52 | - REGISTRY_AUTH_TOKEN_SERVICE="Docker registry" 53 | - REGISTRY_AUTH_TOKEN_ISSUER="Auth Service" 54 | - REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry 55 | - REGISTRY_AUTH_TOKEN_ROOTCERTBUNDLE=/server.pem 56 | - REGISTRY_STORAGE_DELETE_ENABLED=true 57 | 58 | registry_basic: 59 | image: registry:2 60 | ports: 61 | - "5001:5000" 62 | volumes: 63 | - ./registry/b:/var/lib/registry 64 | - ./htpasswd:/auth/htpasswd 65 | environment: 66 | - "REGISTRY_AUTH=htpasswd" 67 | - "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" 68 | - "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" 69 | - "REGISTRY_STORAGE_DELETE_ENABLED=true" 70 | - REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry 71 | -------------------------------------------------------------------------------- /develop/fillrepo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import subprocess as sp 4 | import random as rd 5 | import os as os 6 | 7 | addr = 'localhost:5001' 8 | base = 'evedel/bow' 9 | dftn = 'Dockerfile-test' 10 | 11 | BranchCoef = 8 12 | lParent = base + ":latest" 13 | 14 | def shell(c): 15 | sto, ste = sp.Popen((c).split(), stdout=sp.PIPE).communicate() 16 | if ste == None: 17 | print("Done: " + c) 18 | else: 19 | print("Error: " + c + '\n' + sto + '\n' + ste) 20 | 21 | 22 | 23 | def genDockerfile(parent, adddir): 24 | DF='FROM ' + parent + '\n' + \ 25 | 'ADD ./golang ' + adddir + ' \n' 26 | f = open(dftn, 'w') 27 | f.write(DF) 28 | 29 | def fillRepoInherited(): 30 | numPushed = 0 31 | l1name = addr + '/' + lParent 32 | shell('docker tag ' + lParent + ' ' + l1name) 33 | shell('docker push ' + l1name) 34 | numPushed += 1 35 | 36 | for i in range(BranchCoef): 37 | l2name = addr + '/' + str(i) + '-' + base + ':latest' 38 | genDockerfile(l1name, '/' + str(i)) 39 | shell('docker build . -f ' + dftn + ' -t ' + l2name) 40 | shell('docker push ' + l2name) 41 | numPushed += 1 42 | for j in range(BranchCoef): 43 | l3name = addr + '/' + str(i) + '-' + base + '-' + str(j) + ':latest' 44 | genDockerfile(l2name, '/' + str(i) + '/' + str(j)) 45 | shell('docker build . -f ' + dftn + ' -t ' + l3name) 46 | shell('docker push ' + l3name) 47 | numPushed += 1 48 | shell('docker rmi ' + l3name) 49 | for k in range(BranchCoef): 50 | l3name = addr + '/' + str(i) + '-' + base + '-' + str(j) + ':' + str(k) 51 | genDockerfile(l2name, '/' + str(i) + '/' + str(j)) 52 | shell('docker build . -f ' + dftn + ' -t ' + l3name) 53 | shell('docker push ' + l3name) 54 | numPushed += 1 55 | shell('docker rmi ' + l3name) 56 | shell('docker rmi ' + l2name) 57 | os.remove(dftn) 58 | shell('docker rmi ' + l1name) 59 | print('Done: pushed ' + str(numPushed) + ' images ') 60 | 61 | def fillRepoInline(): 62 | numPushed = 0 63 | l1name = addr + '/' + lParent 64 | shell('docker tag ' + lParent + ' ' + l1name) 65 | shell('docker push ' + l1name) 66 | numPushed += 1 67 | 68 | for i in range(BranchCoef**3): 69 | l2name = addr + '/' + str(i).zfill(4) + '-' + base + ':latest' 70 | genDockerfile(l1name, '/' + str(i)) 71 | shell('docker build . -f ' + dftn + ' -t ' + l2name) 72 | shell('docker push ' + l2name) 73 | shell('docker rmi ' + l2name) 74 | numPushed += 1 75 | 76 | os.remove(dftn) 77 | shell('docker rmi ' + l1name) 78 | print('Done: pushed ' + str(numPushed) + ' images ') 79 | 80 | sto, ste = sp.Popen(("docker login " + addr + " -p test -u test").split(), stdout=sp.PIPE).communicate() 81 | 82 | if (ste == None): 83 | print(sto.decode('utf-8')[:-1] + " [" + addr + "]") 84 | # fillRepoInherited() 85 | fillRepoInline() 86 | -------------------------------------------------------------------------------- /develop/golang/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | RUN apt-get update &&\ 4 | apt-get -y upgrade &&\ 5 | apt-get install -y git nano wget &&\ 6 | wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz &&\ 7 | tar -xvf go1.9.linux-amd64.tar.gz &&\ 8 | rm go1.9.linux-amd64.tar.gz &&\ 9 | mv go /usr/local &&\ 10 | apt-get clean autoremove 11 | 12 | WORKDIR /app 13 | -------------------------------------------------------------------------------- /develop/htpasswd: -------------------------------------------------------------------------------- 1 | test:$2y$05$IfD3GFdaRAro2fmSNqN5xOP38eKeVb9xNjPAC.lkanEsWfasesPEm 2 | badchar:$2y$05$8PEr9A45y3LmLxcmu0kUw.FGS1Sbo4AjLeFVj2AhSvkxsqd.XfGCO 3 | -------------------------------------------------------------------------------- /develop/server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDI14NB16onEH+L 3 | 0MizGSzNsiNWqNFGQK/bosF0Nl29qguQlTCCLDNE4IhX6Uh2fnuRcIhNHbGxZKXm 4 | TaXotI7psKvwQveYCRDAIW6MpLMegFyO3CZjxLrkdFdDwulMUo+c+jQY6EsZm16p 5 | 5/o6VbsolcPPqc7LOWGMt/E89lTH5LNZU7JTu9TsSHZX8IPm8obsmdB8/3A6mnQb 6 | I2oFdFSK8n1EQRtmI4AuA6v05ccHBMGEzL5d2RoTzzS4k50ZYw/QfZtNoKPa8T69 7 | x20kRzSpXUA5ifIHK6b8QqyljsdpjodbcXOQo/dQtEa+csrEGbvkGF/rag9zHws1 8 | ibfXLsNNAgMBAAECggEAVAxsb4dzO3naBobPFrQ4XbRouYFYYs/7SCzqTFncDN02 9 | jcEBVdhtdCuKo0+K9Zuk1o6DW9JLZHM8Qg7ImYPGMuGucpNzzfotOlpDSzQ5iVAq 10 | a9aRcjsIA0b0pfTRcREz7HuAhdPgacztZqkfvH3YHvndwe/MDJvsyNjJabukayn6 11 | BOYvifqmbD978K497SK9ywum/Sm0wWlHWdyuJV5VFgVdgs6NKsk6+fmCqvD6x9QC 12 | ICh+LJkzxokrCxlE9DL83NNnrMw67coVG/z21XiH8yISXrGL51YYehXMHO2pnQWk 13 | dxSCszTRxTC1M/hPH2w+ikvpcD6f+ejnfTMI18j9AQKBgQDxWJ7g8p2DpS0VC3DE 14 | whpppwc7ENFk74gXo34thzwVec/Dz5VCp+y26hpKw5mcHnurmO/JgmxAH6vGRWmT 15 | 5hrVYqHue9q9w3p39SAbm16auWUMqLHjnBS8GoL2dmvjxrT4zsQ1gMnK/xAhSIZm 16 | iHuiiIi6Qvr61YJEfUZIJzqe4QKBgQDVCU+AE64ZDwvrvgUbsGcuL/WxqQhMHkRn 17 | c9FxauS4OL7tbVC58kICFKhG4nIHnhQXUeYem7JxmYNai/2C4tJiHrOW3Qy17U0e 18 | bm2ucYXjXQe8+hQgLrJ7sOjkcAxoSZpjQC7gwoNy/1iqj2RFGLHjTrtQo/i4gC7J 19 | nMdUCCBN7QKBgGVYUV8kggBF3Ch6JWB6IZ08Bk1HQqaf7wX+IX38y7446IXRJVxY 20 | J46nv2KlwFtOcaAdGJQFsG883WTkwPDaL2prgJQkbjZBX6v/wvvUwmU2dLhcHlb1 21 | s79JYrUcBTIgvt279aiB7DrR4HQZgFaN+VzG+KM+fSXXglxAPsMNthABAoGAcDpY 22 | bFNxyve3Qvi2vjB/GsDfQTmYCmmDhbBo7MPwO/CA/JkzBtJN3cS+JaGTitnHIcXe 23 | Yc+KAPhrT18iLTqKtHASEe7fjFO35cks9NIPQ4i10+M2iQGwuyKmffldP+9Oauzc 24 | BUHTd9h3AFtL6m6o/+NxIHlRRPkaLNHv3B/vzL0CgYEAkfve/3RmmpMxMDjNQNaO 25 | 7SkNJMGrCaNLsP+wlhwnc3gVAeFqg7wlI9pGJ822Mtc4yFT3bJiImtBhD0ohCpxl 26 | 5xrq/pVhRWOqUzNNmZYJpOd4XNUDOFZ6v4b4Z6vfnMBlEayrgDcikCGLzIU222Wp 27 | omDUXYxXJBX1334BG078qKQ= 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /develop/server.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIID6TCCAtGgAwIBAgIJAILkVBsqmn4OMA0GCSqGSIb3DQEBCwUAMIGKMQswCQYD 3 | VQQGEwJBVTEOMAwGA1UECAwFU3RhdGUxDTALBgNVBAcMBENpdHkxEzARBgNVBAoM 4 | CkV2YSBQdHlMdGQxDTALBgNVBAsMBFVuaXQxFDASBgNVBAMMC2V4YW1wbGUub3Jn 5 | MSIwIAYJKoZIhvcNAQkBFhNleGFtcGxlQGV4YW1wbGUub3JnMB4XDTE2MTEzMDA4 6 | MDkxMFoXDTE3MTEzMDA4MDkxMFowgYoxCzAJBgNVBAYTAkFVMQ4wDAYDVQQIDAVT 7 | dGF0ZTENMAsGA1UEBwwEQ2l0eTETMBEGA1UECgwKRXZhIFB0eUx0ZDENMAsGA1UE 8 | CwwEVW5pdDEUMBIGA1UEAwwLZXhhbXBsZS5vcmcxIjAgBgkqhkiG9w0BCQEWE2V4 9 | YW1wbGVAZXhhbXBsZS5vcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB 10 | AQDI14NB16onEH+L0MizGSzNsiNWqNFGQK/bosF0Nl29qguQlTCCLDNE4IhX6Uh2 11 | fnuRcIhNHbGxZKXmTaXotI7psKvwQveYCRDAIW6MpLMegFyO3CZjxLrkdFdDwulM 12 | Uo+c+jQY6EsZm16p5/o6VbsolcPPqc7LOWGMt/E89lTH5LNZU7JTu9TsSHZX8IPm 13 | 8obsmdB8/3A6mnQbI2oFdFSK8n1EQRtmI4AuA6v05ccHBMGEzL5d2RoTzzS4k50Z 14 | Yw/QfZtNoKPa8T69x20kRzSpXUA5ifIHK6b8QqyljsdpjodbcXOQo/dQtEa+csrE 15 | GbvkGF/rag9zHws1ibfXLsNNAgMBAAGjUDBOMB0GA1UdDgQWBBTVHvFNpYuWmXo6 16 | Qxr6YKcBY148ezAfBgNVHSMEGDAWgBTVHvFNpYuWmXo6Qxr6YKcBY148ezAMBgNV 17 | HRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBLK2tMTjTJKjrBqxU3YYg7pQw3 18 | M18t6z13nVwhu/vWeYT+pt/aFsAsaNtN9j4yYGCblk3Qv5j37PPht65nzeOfTnJw 19 | SH35wKsrXDxqYbFm8uuOj4ujY7k26OXLMJAkJIwhHFpNDIqLqyKvF8iByG/PJiHL 20 | WENkHjkFNeIsNUt/rxn9KHpWE3SHmRKyUtIuMtqtuFmXGiOOTic+4qdFz0FqdKM6 21 | 16CZqI7zdw30UQhtyJPEWhwbl9faIie4jYitrIyAR7JVzqKMakxnc4FAune6HvnP 22 | CvbJJlvLv5/Hyw7pXhgtTudl9+bBoqiBMVS/FstXJlGBRd3I/fNoKxCDMmZ+ 23 | -----END CERTIFICATE----- 24 | -------------------------------------------------------------------------------- /img/conf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evedel/bow/163e3b69f2a8502daeab252fbdb4cff0617c13e1/img/conf.png -------------------------------------------------------------------------------- /img/history.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evedel/bow/163e3b69f2a8502daeab252fbdb4cff0617c13e1/img/history.png -------------------------------------------------------------------------------- /img/info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evedel/bow/163e3b69f2a8502daeab252fbdb4cff0617c13e1/img/info.png -------------------------------------------------------------------------------- /img/parents.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Evedel/bow/163e3b69f2a8502daeab252fbdb4cff0617c13e1/img/parents.png -------------------------------------------------------------------------------- /project/DFalpine: -------------------------------------------------------------------------------- 1 | FROM golang:1.9.3-alpine3.7 AS artifact 2 | WORKDIR /go 3 | ADD . /go 4 | RUN apk add --no-cache git 5 | ENV GOBIN "/go/bin" 6 | RUN go env 7 | RUN go get -v && rm bin/go 8 | RUN go build -v -o bow 9 | RUN chmod +x bow 10 | 11 | FROM alpine:3.7 12 | RUN apk add --no-cache ca-certificates 13 | WORKDIR /evedel 14 | COPY --from=artifact /go/bow /evedel/bow 15 | COPY ./templates /evedel/templates 16 | COPY ./resources /evedel/resources 17 | CMD ["/evedel/bow"] 18 | -------------------------------------------------------------------------------- /project/DFdebian: -------------------------------------------------------------------------------- 1 | FROM debian:jessie AS artifact 2 | RUN apt-get update &&\ 3 | apt-get install -y git wget &&\ 4 | wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz &&\ 5 | tar -xvf go1.9.linux-amd64.tar.gz &&\ 6 | rm go1.9.linux-amd64.tar.gz &&\ 7 | mv go /usr/local &&\ 8 | apt-get clean autoremove 9 | WORKDIR /go 10 | COPY . /go 11 | ENV GOBIN "/go/bin" 12 | ENV GOPATH "/go" 13 | ENV GOROOT "/usr/local/go" 14 | ENV PATH "${GOPATH}/bin:${GOROOT}/bin:${PATH}" 15 | RUN go env && ls -l 16 | RUN go get -v && rm bin/go 17 | RUN go build -v -o bow 18 | RUN chmod +x bow 19 | 20 | FROM debian:jessie 21 | RUN apt-get update && apt-get install -y ca-certificates 22 | WORKDIR /evedel 23 | COPY --from=artifact /go/bow /evedel/bow 24 | COPY ./templates /evedel/templates 25 | COPY ./resources /evedel/resources 26 | CMD ["/evedel/bow"] 27 | -------------------------------------------------------------------------------- /project/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "db" 5 | "say" 6 | "conf" 7 | "handler" 8 | "checker" 9 | 10 | "net/http" 11 | 12 | _ "github.com/wader/disable_sendfile_vbox_linux" 13 | ) 14 | func main() { 15 | conf.Init() 16 | db.Init() 17 | 18 | http.Handle("/resources/", http.StripPrefix("/resources/", http.FileServer(http.Dir("resources")))) 19 | 20 | http.HandleFunc("/managerepos/", handler.ManageRepos) 21 | http.HandleFunc("/info", handler.Info) 22 | http.HandleFunc("/upgrade/", handler.UpgradeDB) 23 | http.HandleFunc("/delete", handler.DeleteImage) 24 | http.HandleFunc("/graph", handler.RepoGraph) 25 | http.HandleFunc("/update", handler.UpdateAll) 26 | http.HandleFunc("/", handler.Main) 27 | 28 | go checker.DaemonManager() 29 | 30 | say.L2("Server listening at [" + conf.Env["servadd"] + "]") 31 | if err := http.ListenAndServe(conf.Env["servadd"], nil); err != nil { 32 | say.L3(err.Error() + "\nListenAndServe()\nmain()\nmain.go\nmain") 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /project/resources/map.css: -------------------------------------------------------------------------------- 1 | body{ 2 | font-family: Courier; 3 | font-size: 12px; 4 | background-color: #222225; 5 | /*background: 6 | radial-gradient(black 15%, transparent 20%) 0 0, 7 | radial-gradient(black 15%, transparent 20%) 8px 8px, 8 | radial-gradient(rgba(255,255,255,.1) 15%, transparent 20%) 0 1px, 9 | radial-gradient(rgba(255,255,255,.1) 15%, transparent 20%) 8px 9px; 10 | background-color:#222225; 11 | background-size:16px 16px; 12 | */ 13 | /* overflow: hidden; */ 14 | } 15 | .preload * { 16 | -webkit-transition: none !important; 17 | -moz-transition: none !important; 18 | -ms-transition: none !important; 19 | -o-transition: none !important; 20 | } 21 | a:link, a:visited{ 22 | float: left; 23 | white-space: nowrap; 24 | overflow: hidden; 25 | text-overflow: ellipsis; 26 | width: 90%; 27 | background-color: #446688; 28 | color: black; 29 | padding: 10px 0px; 30 | text-align: center; 31 | text-decoration: none; 32 | font-weight: bold; 33 | display: inline-block; 34 | transition: 1s ease-out; 35 | transition-delay: 0.1s; 36 | border: solid 1px white; 37 | } 38 | a:hover, a:active{ 39 | background-color: #6BC0EA; 40 | opacity: 0.85; 41 | transition: 0.3s ease-out; 42 | transition-delay: 0.05s; 43 | } 44 | button{ 45 | float: left; 46 | white-space: nowrap; 47 | overflow: hidden; 48 | text-overflow: ellipsis; 49 | width: 10%; 50 | background-color: #446688; 51 | color: black; 52 | padding: 10.5px 0px; 53 | text-align: center; 54 | text-decoration: none; 55 | font-weight: bold; 56 | display: inline-block; 57 | transition: 1s ease-out; 58 | transition-delay: 0.1s; 59 | border: solid 1px white; 60 | } 61 | button:hover{ 62 | background-color: #6BC0EA; 63 | opacity: 0.85; 64 | transition: 0.3s ease-out; 65 | transition-delay: 0.05s; 66 | } 67 | ::-webkit-scrollbar-track 68 | { 69 | background-color: #0e121d; 70 | } 71 | ::-webkit-scrollbar 72 | { 73 | width: 6px; 74 | background-color: #F5F5F5; 75 | } 76 | ::-webkit-scrollbar-thumb 77 | { 78 | background-color: #6BC0EA; 79 | } 80 | a.namelink:link, a.namelink:visited{ 81 | padding: 0px 0px; 82 | text-align: left; 83 | text-decoration: underline; 84 | border: none; 85 | } 86 | a.namelink:hover, a.namelink:active{ 87 | background-color: #446688; 88 | opacity: 1; 89 | color: white; 90 | font-weight: normal; 91 | } 92 | a.chosen{ 93 | background-color: #0e121d; 94 | color: white; 95 | } 96 | div.topbar{ 97 | position: relative; 98 | width: 100%; 99 | height: 50px; 100 | font-size: 16px; 101 | background-color: #446688; 102 | overflow: hidden; 103 | border: solid 1px white; 104 | } 105 | div.topbar a:link, div.topbar a:visited{ 106 | width: 10%; 107 | float: right; 108 | padding: 15px 0px; 109 | text-align: center; 110 | text-decoration: none; 111 | font-weight: bold; 112 | overflow: hidden; 113 | transition: 0.4s ease-out; 114 | transition-delay: 0.01s; 115 | } 116 | div.topbar a:hover, div.topbar a:active{ 117 | background-color: #6BC0EA; 118 | transition: 0.4s ease-out; 119 | transition-delay: 0.01s; 120 | } 121 | div p { 122 | position: relative; 123 | color: white; 124 | background-color: #446688; 125 | padding: 0px 10px; 126 | text-align: center; 127 | display: inline-block; 128 | transition-delay: 0.01s; 129 | } 130 | 131 | div.emptyrepos{ 132 | position: relative; 133 | width: 100%; 134 | height: 50%; 135 | float: left; 136 | } 137 | div.managerepos{ 138 | width: 75%; 139 | float: right; 140 | } 141 | form#managerepoform{ 142 | color: #6bc0ea; 143 | padding: 10px 0px; 144 | } 145 | div.managerepos a:link, div.managerepos a:visited{ 146 | width: 10%; 147 | color: black; 148 | } 149 | div.managerepos a:hover, div.managerepos a:active{ 150 | color: black; 151 | } 152 | div.manifestbar{ 153 | width: 60%; 154 | height: 90%; 155 | display: inline-block; 156 | } 157 | div.content{ 158 | border: solid 1px white; 159 | } 160 | .tabs div { 161 | display: none; 162 | overflow-y: auto; 163 | height: 90%; 164 | background-color: #446688; 165 | } 166 | .tabs input { 167 | display: none; 168 | } 169 | .tabs label { 170 | width: 12%; 171 | display: inline-block; 172 | padding: 15px 25px; 173 | font-weight: bold; 174 | text-align: center; 175 | background-color: #446688; 176 | border: solid 1px white; 177 | color: black; 178 | transition: 0.3s ease-out; 179 | transition-delay: 0.05s; 180 | } 181 | .tabs label:hover { 182 | background-color: #6BC0EA; 183 | opacity: 0.85; 184 | transition: 0.3s ease-out; 185 | transition-delay: 0.05s; 186 | } 187 | .tabs input:checked + label { 188 | background-color: #0e121d; 189 | color: white; 190 | } 191 | #tab1:checked ~ #content1, 192 | #tab2:checked ~ #content2, 193 | #tab3:checked ~ #content3{ 194 | display: block; 195 | } 196 | 197 | @media screen and (max-width: 680px) { 198 | .tabs label { 199 | font-size: 0; 200 | } 201 | .tabs label:before { 202 | font-size: 18px; 203 | } 204 | } 205 | @media screen and (max-width: 100%) { 206 | .tabs label { 207 | padding: 15px; 208 | } 209 | } 210 | 211 | table.historytable{ 212 | width: 100%; 213 | text-align: center; 214 | background-color: #446688; 215 | } 216 | table.historytable tr{ 217 | padding: 10px 0px; 218 | width: 100%; 219 | display: inline-flex; 220 | border-bottom: solid black 1px; 221 | transition: 0.7s ease-out; 222 | transition-delay: 0.05s; 223 | } 224 | table.historytable tr:hover{ 225 | background-color: #0e121d; 226 | color: #006699; 227 | transition: 0.7s ease-out; 228 | transition-delay: 0.05s; 229 | } 230 | table.historytable td{ 231 | min-width: 150px; 232 | font-size: 12px; 233 | } 234 | table.historytable th{ 235 | min-width: 150px; 236 | font-size: 12px; 237 | } 238 | 239 | table.infotable { 240 | float: left; 241 | width: 60%; 242 | padding: 10px 10px; 243 | } 244 | table.infotable td{ 245 | border-bottom: solid rgba(255, 255, 255, 0.2) 1px; 246 | border-left: solid rgba(255, 255, 255, 0.2) 1px; 247 | } 248 | a.danger{ 249 | width: 10%; 250 | position: relative; 251 | float: left; 252 | background-color: #650f22; 253 | color: #0e121d; 254 | top: 50%; 255 | transform: translateY(-50%); 256 | } 257 | a.danger:hover, a.danger:active{ 258 | background-color: #8c0120; 259 | opacity: 1; 260 | color: white; 261 | } 262 | 263 | #uploadsgraph { 264 | display: block; 265 | float: left; 266 | width: 50%; 267 | height: 60%; 268 | } 269 | #sizegraph { 270 | display: block; 271 | float: left; 272 | width: 50%; 273 | height: 60%; 274 | } 275 | 276 | div.sidebar{ 277 | width: 9%; 278 | height: 90%; 279 | display: inline-block; 280 | } 281 | 282 | p.filtername{ 283 | float: left; 284 | white-space: nowrap; 285 | overflow: hidden; 286 | text-overflow: ellipsis; 287 | width: 90%; 288 | background-color: #FFFFFF; 289 | color: black; 290 | padding: 10px 0px; 291 | text-align: center; 292 | text-decoration: none; 293 | font-weight: bold; 294 | border: solid 1px white; 295 | } 296 | 297 | div.sidebar div.label{ 298 | height: 10%; 299 | } 300 | 301 | div.sidebar div.links{ 302 | width: 100%; 303 | height: 90%; 304 | display: inline-block; 305 | overflow-y: auto; 306 | overflow-x: hidden; 307 | } 308 | -------------------------------------------------------------------------------- /project/resources/treant.css: -------------------------------------------------------------------------------- 1 | .Treant { position: relative; overflow: hidden; padding: 0 !important; } 2 | .Treant > .node, 3 | .Treant > .pseudo { position: absolute; display: block; visibility: block; } 4 | .Treant.loaded .node, 5 | .Treant.loaded .pseudo { visibility: visible; } 6 | .Treant > .pseudo { width: 0; height: 0; border: none; padding: 0; } 7 | .Treant .collapse-switch { 8 | width: 100%; 9 | height: 100%; 10 | display: block; 11 | border: 1px solid black; 12 | position: absolute; 13 | top: 0px; 14 | right: 0px; 15 | cursor: pointer; 16 | } 17 | .Treant .collapsed .collapse-switch { 18 | background-color: #868DEE; 19 | } 20 | 21 | .chart { 22 | position: relative; 23 | height: 90%; 24 | width: 90%; 25 | border-radius: 1px; 26 | } 27 | .node { 28 | color: #9CB5ED; 29 | border: 1px solid #C8C8C8; 30 | border-radius: 3px; 31 | } 32 | .node p { 33 | font-size: 15px; 34 | line-height: 20px; 35 | height: 20px; 36 | padding: 3px; 37 | margin: 0; 38 | display: table-cell; 39 | } 40 | #parents-tree{ 41 | width: 60%; 42 | height: 90%; 43 | display: inline-block; 44 | } 45 | -------------------------------------------------------------------------------- /project/src/checker/checker.go: -------------------------------------------------------------------------------- 1 | package checker 2 | 3 | import ( 4 | "say" 5 | "conf" 6 | "time" 7 | "strconv" 8 | ) 9 | 10 | var runchannel = make( map[string]chan int) 11 | 12 | 13 | func DaemonManager() { 14 | t, _ := strconv.Atoi(conf.Env["checker_time"]) 15 | runchannel["repo"] = make(chan int,1) 16 | runchannel["tags"] = make(chan int,1) 17 | runchannel["mnft"] = make(chan int,1) 18 | runchannel["prnt"] = make(chan int,1) 19 | 20 | say.L2("DaemonManager: Sleep time is : " + conf.Env["checker_time"] + " seconds") 21 | for { 22 | say.L1("DaemonManager: TicTac") 23 | go checkRepos(runchannel["repo"]) 24 | go checkTags(runchannel["tags"]) 25 | go checkManifests(runchannel["mnft"]) 26 | go checkParents(runchannel["prnt"]) 27 | time.Sleep(time.Duration(t) * time.Second) 28 | } 29 | } 30 | 31 | func StartManual() { 32 | say.L2("DaemonManager: Started all checkers manually") 33 | go checkRepos(runchannel["repo"]) 34 | go checkTags(runchannel["tags"]) 35 | go checkManifests(runchannel["mnft"]) 36 | go checkParents(runchannel["prnt"]) 37 | } 38 | 39 | func RunCheckTags(){ 40 | go checkTags(runchannel["tags"]) 41 | } 42 | -------------------------------------------------------------------------------- /project/src/checker/manifest.go: -------------------------------------------------------------------------------- 1 | package checker 2 | 3 | import( 4 | "dt" 5 | "db" 6 | "say" 7 | "qurl" 8 | "utils" 9 | 10 | "time" 11 | "strings" 12 | "strconv" 13 | "encoding/json" 14 | ) 15 | 16 | func checkManifests(runchannel chan int){ 17 | defer dt.Watch(time.Now(), "Check Manifest Demon") 18 | 19 | runchannel <- 1 20 | say.L1("CheckManifests Daemon: started work") 21 | repos := db.GetRepos() 22 | for er, _ := range repos { 23 | repoinfo := db.GetRepoPretty(er) 24 | catalog := db.GetCatalog(er) 25 | for _, en := range catalog { 26 | dbtags := db.GetTags(er, en) 27 | for _, et := range dbtags { 28 | Reqt := "/v2/" + en + "/manifests/" + et 29 | if body, _, ok := qurl.MakeQuery(Reqt, "GET", repoinfo, map[string]string{}); ok { 30 | ihdr := map[string]string{"Accept": "application/vnd.docker.distribution.manifest.v2+json"} 31 | if _, ohdr, ok := qurl.MakeQuery(Reqt, "GET", repoinfo, ihdr); !ok { 32 | say.L3("CheckManifests Daemon: cannot recieve digest header from registry, stopping work") 33 | <- runchannel 34 | } else { 35 | olddidg := db.GetValueFromBucket([]string{ er, "catalog", en, et}, "digest") 36 | newdidg := ohdr["Docker-Content-Digest"][0] 37 | if (olddidg != newdidg){ 38 | var ch interface{} 39 | totalsize := 0 40 | fsshaarr := body.(map[string]interface{})["fsLayers"].([]interface{}) 41 | historyarr := body.(map[string]interface{})["history"].([]interface{}) 42 | db.DeleteBucket([]string{ er, "catalog", en, et, "history" }) 43 | for i, _ := range fsshaarr { 44 | fssha := fsshaarr[i].(map[string]interface{})["blobSum"].(string) 45 | var fssize string 46 | if _, fsshdr, okcl := qurl.MakeQuery("/v2/" + en + "/blobs/" + fssha, "HEAD", repoinfo, map[string]string{}); !okcl { 47 | say.L3("CheckManifests Daemon: cannot recieve content length header from registry, stopping work") 48 | fssize = "0" 49 | } else { 50 | fssize = fsshdr["Content-Length"][0] 51 | } 52 | history := historyarr[i].(map[string]interface{})["v1Compatibility"].(string) 53 | historynew := history 54 | if fsshanum, err := strconv.Atoi(fssize); err != nil { 55 | say.L3(err.Error()) 56 | } else { 57 | // Cut the carriage return 58 | if last := len(historynew) - 1; last >= 0 { 59 | historynew = historynew[:last] 60 | } 61 | historynew = historynew + ",\"blobSum\":\"" + 62 | fssha + "\", \"blobSize\":\"" + 63 | utils.FromByteToHuman(fsshanum) + "\"}" 64 | totalsize += fsshanum 65 | } 66 | if err := json.Unmarshal([]byte(history), &ch); err != nil { 67 | say.L3(err.Error()) 68 | } else { 69 | created := ch.(map[string]interface{})["created"].(string) 70 | var indx int 71 | if indx = strings.Index(created, "T"); indx > -1 { 72 | created = created[:indx] + " " + created[indx+1:] 73 | if indx = strings.Index(created, "."); indx > -1 { 74 | created = created[:indx] 75 | } 76 | } 77 | if indx > -1 { 78 | db.PutSimplePairToBucket([]string{ er, "catalog", en, et, "history" }, created, historynew) 79 | } 80 | } 81 | } 82 | sizedt := time.Now().Local().Format("2006-01-02 15:04:05") 83 | shortsizedt := time.Now().Local().Format("2006-01-02") 84 | db.PutSimplePairToBucket([]string{ er, "catalog", en, et, "_totalsizehuman" }, sizedt, utils.FromByteToHuman(totalsize)) 85 | db.PutSimplePairToBucket([]string{ er, "catalog", en, et, "_totalsizebytes" }, sizedt, strconv.Itoa(totalsize)) 86 | db.PutTagDigest(er, en, et, shortsizedt, newdidg) 87 | } else { 88 | say.L1("CheckManifests Daemon: digests are the same, shouldnot update anything, stopping work") 89 | } 90 | } 91 | } else { 92 | if body != nil { 93 | if body.(int) == 404 { 94 | say.L2("CheckManifests Daemon: Page with name [" + en + "/" + et + "] not found. Asuming it isn't valid in the moment") 95 | db.PutSimplePairToBucket([]string{ er, "catalog", en }, "_valid", "0") 96 | } else { 97 | say.L3("CheckManifests Daemon: cannot recieve response from registry, stopping work") 98 | } 99 | } 100 | } 101 | } 102 | } 103 | } 104 | say.L1("CheckManifests Daemon: finished work") 105 | <- runchannel 106 | } 107 | -------------------------------------------------------------------------------- /project/src/checker/parents.go: -------------------------------------------------------------------------------- 1 | package checker 2 | 3 | import( 4 | "dt" 5 | "db" 6 | "say" 7 | 8 | "time" 9 | "utils" 10 | "strings" 11 | "encoding/json" 12 | ) 13 | 14 | func checkParents(runchannel chan int){ 15 | defer dt.Watch(time.Now(), "Check Parents Demon") 16 | 17 | runchannel <- 1 18 | say.L1("CheckParents Daemon: started work") 19 | repos := db.GetRepos() 20 | for key, value := range repos { 21 | if value == "" { 22 | names := db.GetAllPairsFromBucket([]string{key, "catalog"}) 23 | for keyn, valuen := range names { 24 | if valuen == "" { 25 | tags := db.GetAllPairsFromBucket([]string{key, "catalog", keyn}) 26 | for keyt, valuet := range tags { 27 | if (valuet == "") && (keyt[0:1] != "_"){ 28 | say.L1("CheckParents Daemon: check [" + key + "->" + keyn + ":" + keyt + "]") 29 | if _, ok := db.GetAllPairsFromBucket([]string{key, "catalog", keyn, keyt})["history"]; !ok { 30 | db.PutBucketToBucket([]string{key, "catalog", keyn, keyt, "history"}) 31 | } 32 | history := db.GetAllPairsFromBucket([]string{key, "catalog", keyn, keyt, "history"}) 33 | histarr := []string{} 34 | var tmpstr string 35 | cmd := db.GetAllPairsFromBucket([]string{key, "_names", keyn + ":" + keyt}) 36 | for _, valh := range history { 37 | var ch interface{} 38 | if err := json.Unmarshal([]byte(valh), &ch); err != nil { 39 | say.L3(err.Error()) 40 | } else { 41 | tmpstr = "" 42 | if ch.(map[string]interface{})["container_config"].(map[string]interface{})["Cmd"] != nil { 43 | for valji, valj := range ch.(map[string]interface{})["container_config"].(map[string]interface{})["Cmd"].([]interface{}) { 44 | if strings.Contains(valj.(string), " CMD ") || 45 | strings.Contains(valj.(string), " WORKDIR ") || 46 | strings.Contains(valj.(string), " ENTRYPOINT ") || 47 | strings.Contains(valj.(string), " VOLUME ") || 48 | strings.Contains(valj.(string), " EXPOSE "){ 49 | tmpstr = "" 50 | break 51 | } else { 52 | tmpstr += valj.(string) 53 | if (valji < len(ch.(map[string]interface{})["container_config"].(map[string]interface{})["Cmd"].([]interface{}))-1) { 54 | tmpstr += " " 55 | } 56 | } 57 | } 58 | } 59 | if tmpstr != "" { 60 | histarr = append(histarr, tmpstr) 61 | } 62 | } 63 | } 64 | var cmdslice []string 65 | cmdneedaddition := true 66 | for _, valcmd := range cmd { 67 | if err := json.Unmarshal([]byte(valcmd), &cmdslice); err != nil { 68 | say.L3(err.Error()) 69 | } else { 70 | if ! utils.IsSliceDifferent(histarr, cmdslice) { 71 | cmdneedaddition = false 72 | break 73 | } 74 | } 75 | } 76 | if cmdneedaddition { 77 | sizedt := time.Now().Local().Format("2006-01-02 15:04:05") 78 | fullcmd, _ := json.Marshal(histarr) 79 | db.PutSimplePairToBucket([]string{ key, "_names", keyn + ":" + keyt }, sizedt, string(fullcmd)) 80 | } 81 | say.L1("Finding parent for [ " + keyn + ":" + keyt + " ]") 82 | if pn, pt, pok := FindParent(histarr, key, keyn, keyt); pok { 83 | db.PutSimplePairToBucket([]string{ key, "catalog", keyn, keyt, "_parent" }, "name", pn) 84 | db.PutSimplePairToBucket([]string{ key, "catalog", keyn, keyt, "_parent" }, "tag", pt) 85 | } else { 86 | db.PutSimplePairToBucket([]string{ key, "catalog", keyn, keyt, "_parent" }, "name", "") 87 | db.PutSimplePairToBucket([]string{ key, "catalog", keyn, keyt, "_parent" }, "tag", "") 88 | } 89 | } 90 | } 91 | } 92 | } 93 | } 94 | db.DeleteBucket([]string{key, "_namesgraph"}) 95 | BuildParentsGraph(key) 96 | } 97 | say.L1("CheckParents Daemon: finished work") 98 | <- runchannel 99 | } 100 | 101 | func FindParent(childcmd []string, repo string, namei string, tagi string) (name string, tag string, ok bool){ 102 | say.L1("Searching for parent of [ " + namei + ":" + tagi + " ]") 103 | ok = false 104 | names := db.GetAllPairsFromBucket([]string{repo, "_names"}) 105 | maxname := "" 106 | maxlayers := 0 107 | for kn, _ := range names { 108 | if strings.Split(kn, ":")[0] != namei { 109 | // cmd := map[datetime_of_push]commands_in_manifest 110 | cmd := db.GetAllPairsFromBucket([]string{repo, "_names", kn}) 111 | for _, vc := range cmd { 112 | var parentcmd interface{} 113 | if err := json.Unmarshal([]byte(vc), &parentcmd); err != nil { 114 | say.L3(err.Error()) 115 | // return -- don't shure why it was return 116 | // if one of cmd broken, we can skeap only this exact comand 117 | break 118 | } else { 119 | initParentLen := len(parentcmd.([]interface{})) 120 | if (maxlayers <= initParentLen) { 121 | // already has better parent 122 | if initParentLen != 0 { 123 | for _, eccmd := range childcmd { 124 | for ipcmd, epcmd := range parentcmd.([]interface{}) { 125 | if epcmd == eccmd { 126 | parentcmd = append(parentcmd.([]interface{})[:ipcmd], parentcmd.([]interface{})[ipcmd+1:]...) 127 | break 128 | } 129 | } 130 | } 131 | if len(parentcmd.([]interface{})) == 0 { 132 | if (maxlayers < initParentLen) && (len(childcmd) != initParentLen) { 133 | // else it has same length and layers => it is exact copy 134 | maxlayers = initParentLen 135 | maxname = kn 136 | } 137 | } 138 | } 139 | } 140 | } 141 | } 142 | } 143 | } 144 | if maxlayers == 0 { 145 | say.L1("Parent not found") 146 | } else { 147 | say.L1("Parent is [ "+ maxname +" ]") 148 | ok = true 149 | s := strings.Split(maxname, ":") 150 | name = s[0] 151 | tag = s[1] 152 | } 153 | return 154 | } 155 | 156 | func BuildParentsGraph(repo string){ 157 | say.L1("Building parents tree for [ " + repo + " ]") 158 | fullnames := []string{} 159 | names := db.GetAllPairsFromBucket([]string{repo, "catalog"}) 160 | for kn, _ := range names { 161 | tags := db.GetAllPairsFromBucket([]string{repo, "catalog", kn}) 162 | for kt, _ := range tags { 163 | if kt[0:1] != "_" { 164 | fullnames = append(fullnames, kn + ":" + kt) 165 | } 166 | } 167 | } 168 | 169 | Depth := 0 170 | Base := [][]string{} 171 | Base = append(Base, []string{repo, "_namesgraph"}) 172 | db.PutBucketToBucket(Base[0]) 173 | 174 | for (len(fullnames) > 0) && (Depth < 100) { 175 | tmpBase := [][]string{} 176 | for i := len(fullnames)-1; i > -1; i-- { 177 | s := strings.Split(fullnames[i], ":") 178 | n := s[0] 179 | t := s[1] 180 | np := db.GetValueFromBucket([]string{ repo, "catalog", n, t, "_parent" }, "name") 181 | tp := db.GetValueFromBucket([]string{ repo, "catalog", n, t, "_parent" }, "tag") 182 | 183 | for j := 0; j < len(Base); j++ { 184 | if ( np + ":" + tp == Base[j][len(Base[j])-1] ) || (( Depth == 0 ) && ( np + ":" + tp == ":" )) { 185 | say.L1("Found parents [ " + np + ":" + tp + " => " + n + ":" + t + " ]") 186 | tmpPath := append(Base[j], n + ":" + t) 187 | cpPath := make([]string, len(tmpPath)) 188 | copy(cpPath, tmpPath) 189 | tmpBase = append(tmpBase, cpPath) 190 | db.PutBucketToBucket(tmpPath) 191 | fullnames = append(fullnames[:i], fullnames[i+1:]...) 192 | } 193 | } 194 | } 195 | Base = tmpBase 196 | Depth++ 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /project/src/checker/repository.go: -------------------------------------------------------------------------------- 1 | package checker 2 | 3 | import( 4 | "dt" 5 | "db" 6 | "say" 7 | "qurl" 8 | "utils" 9 | 10 | "time" 11 | "strings" 12 | ) 13 | 14 | func checkRepos(runchannel chan int){ 15 | defer dt.Watch(time.Now(), "Check Repositories Demon") 16 | 17 | runchannel <- 1 18 | say.L1("CheckRepos Daemon: started work") 19 | repos := db.GetRepos() 20 | for e, _ := range repos { 21 | repoinfo := db.GetRepoPretty(e) 22 | Req := "/v2/_catalog?n=&last=" 23 | 24 | arrstr := make([]string, 0) 25 | repeat := true 26 | for repeat { 27 | repeat = false 28 | if body, headers, ok := qurl.MakeQuery(Req, "GET", repoinfo, map[string]string{}); ok { 29 | arrint := body.(map[string]interface{})["repositories"].([]interface{}) 30 | for _, e := range arrint { 31 | // after tag was deleted by 'delete' button in UI 32 | // if it was the last tag in namespace/name 33 | // the slice will be empty, and manifest will return 404 34 | Reqtag := "/v2/" + e.(string) + "/tags/list" 35 | if body, _, ok := qurl.MakeQuery(Reqtag, "GET", repoinfo, map[string]string{}); ok { 36 | if body.(map[string]interface{})["tags"] != nil { 37 | arrstr = append(arrstr, e.(string)) 38 | } 39 | } else { 40 | say.L3("CheckRepos Daemon: cannot recieve response from registry, stopping work") 41 | break; 42 | } 43 | } 44 | if link, okh := headers["Link"]; okh { 45 | // until 46 | // Link:[; rel="next"] 47 | // | Req | 48 | from := strings.Index(link[0], "<") 49 | to := strings.Index(link[0], "&") 50 | if ((from != -1) && (to != -1)) { 51 | Req = link[0][from+1 : to] 52 | repeat = true 53 | } 54 | } 55 | } else { 56 | say.L3("CheckRepos Daemon: cannot recieve response from registry, stopping work") 57 | } 58 | } 59 | 60 | dbcatalog := db.GetCatalog(e) 61 | if utils.IsSliceDifferent(dbcatalog, arrstr) { 62 | db.AddCatalog(e, arrstr) 63 | } 64 | 65 | } 66 | say.L1("CheckRepos Daemon: finished work") 67 | <-runchannel 68 | } 69 | -------------------------------------------------------------------------------- /project/src/checker/tags.go: -------------------------------------------------------------------------------- 1 | package checker 2 | 3 | import( 4 | "dt" 5 | "db" 6 | "say" 7 | "qurl" 8 | "utils" 9 | 10 | "time" 11 | ) 12 | 13 | func checkTags(runchannel chan int){ 14 | defer dt.Watch(time.Now(), "Check Tags Demon") 15 | 16 | runchannel <- 1 17 | say.L1("CheckTags Daemon: started work") 18 | repos := db.GetRepos() 19 | for er, _ := range repos { 20 | repoinfo := db.GetRepoPretty(er) 21 | catalog := db.GetCatalog(er) 22 | for _, en := range catalog { 23 | Reqt := "/v2/" + en + "/tags/list" 24 | if body, _, ok := qurl.MakeQuery(Reqt, "GET", repoinfo, map[string]string{}); ok { 25 | dbtags := db.GetTags(er, en) 26 | arrint := make([]interface{}, 0) 27 | if body.(map[string]interface{})["tags"] == nil { 28 | db.PutSimplePairToBucket([]string{ er, "catalog", en }, "_valid", "0") 29 | } else { 30 | db.PutSimplePairToBucket([]string{ er, "catalog", en }, "_valid", "1") 31 | arrint = body.(map[string]interface{})["tags"].([]interface{}) 32 | } 33 | arrstr := make([]string, len(arrint)) 34 | for i, _ := range arrint { 35 | arrstr[i] = arrint[i].(string) 36 | } 37 | if utils.IsSliceDifferent(dbtags, arrstr) { 38 | db.AddTags(er, en, arrstr) 39 | } 40 | } else { 41 | if body != nil { 42 | if body.(int) == 404 { 43 | say.L2("CheckTags Daemon: Page with name [" + en + "] not found. Asuming it isn't valid in the moment") 44 | db.PutSimplePairToBucket([]string{ er, "catalog", en }, "_valid", "0") 45 | } else { 46 | say.L3("CheckTags Daemon: cannot recieve response from registry, stopping work") 47 | } 48 | } 49 | } 50 | } 51 | } 52 | say.L1("CheckTags Daemon: finished work") 53 | <- runchannel 54 | } 55 | -------------------------------------------------------------------------------- /project/src/conf/conf.go: -------------------------------------------------------------------------------- 1 | package conf 2 | 3 | import ( 4 | "os" 5 | "strconv" 6 | ) 7 | 8 | var Env map[string] string 9 | 10 | func Init() { 11 | Env = make (map[string] string) 12 | 13 | var val string 14 | if val = os.Getenv("BS_LOG_SILENT"); val != "" { 15 | Env["log_silent"] = val 16 | } else { 17 | Env["log_silent"] = "no" 18 | } 19 | if val = os.Getenv("BS_TIME_WATCH"); val != "" { 20 | Env["timewatch"] = val 21 | } else { 22 | Env["timewatch"] = "no" 23 | } 24 | if val = os.Getenv("BS_SERVE_ADD"); val != "" { 25 | Env["servadd"] = val 26 | } else { 27 | Env["servadd"] = ":19808" 28 | } 29 | if val = os.Getenv("BS_DB_PATH"); val != "" { 30 | Env["dbpath"] = val 31 | } else { 32 | Env["dbpath"] = "/var/lib/bow" 33 | } 34 | os.Mkdir(Env["dbpath"], 0700) 35 | if val = os.Getenv("BS_DB_NAME"); val != "" { 36 | Env["dbname"] = val 37 | } else { 38 | Env["dbname"] = "asapdrf" 39 | } 40 | if val = os.Getenv("BS_CHECKER_TIMEOUT"); val != "" { 41 | if _, err := strconv.Atoi(val); err != nil { 42 | Env["checker_time"] = "300" 43 | } else { 44 | Env["checker_time"] = val 45 | } 46 | } else { 47 | Env["checker_time"] = "300" 48 | } 49 | if val = os.Getenv("BS_LOG_LEVEL"); val != "" { 50 | if val == "1" || val == "2" || val == "3" || val == "4" { 51 | Env["log_level"] = val 52 | } 53 | } else { 54 | Env["log_level"] = "1" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /project/src/db/alias.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import( 4 | "say" 5 | "strings" 6 | "strconv" 7 | ) 8 | 9 | func GetRepos() (repos map[string]string){ 10 | pairs := GetAllPairsFromBucket([]string{}) 11 | delete(pairs, "_info"); 12 | return pairs 13 | } 14 | 15 | func GetRepoPretty(repo string) (pretty map[string]string){ 16 | return GetAllPairsFromBucket([]string{repo, "_info"}) 17 | } 18 | 19 | func CreateRepo(params map[string][]string) { 20 | say.L1("DB: Created new repo") 21 | name := params["name"][0] 22 | PutSimplePairToBucket([]string{name, "_info"}, "host", params["host"][0]) 23 | PutSimplePairToBucket([]string{name, "_info"}, "pass", params["pass"][0]) 24 | PutSimplePairToBucket([]string{name, "_info"}, "user", params["user"][0]) 25 | PutSimplePairToBucket([]string{name, "_info"}, "scheme", params["scheme"][0]) 26 | PutSimplePairToBucket([]string{name, "_info"}, "name", name) 27 | if _, ok := params["secure"]; ok { 28 | PutSimplePairToBucket([]string{name, "_info"}, "secure", "true") 29 | } else { 30 | PutSimplePairToBucket([]string{name, "_info"}, "secure", "false") 31 | } 32 | PutBucketToBucket([]string{name, "catalog"}) 33 | PutBucketToBucket([]string{name, "_namesgraph"}) 34 | PutBucketToBucket([]string{name, "_names"}) 35 | } 36 | 37 | func DeleteRepo(repo string){ 38 | DeleteBucket([]string{repo}) 39 | } 40 | 41 | func PutTagDigest(er, en, et, shortsizedt, didgesr string) { 42 | uploadsnt := GetValueFromBucket([]string{ er, "catalog", en, et, "_uploads"}, shortsizedt) 43 | if uploadsnt == "" { 44 | PutSimplePairToBucket([]string{ er, "catalog", en, et, "_uploads"}, shortsizedt, "1") 45 | } else { 46 | val, _ := strconv.Atoi(string(uploadsnt)) 47 | val++ 48 | PutSimplePairToBucket([]string{ er, "catalog", en, et, "_uploads"}, shortsizedt, strconv.Itoa(val)) 49 | } 50 | uploadsnn := GetValueFromBucket([]string{ er, "catalog", en,"_uploads"}, shortsizedt) 51 | if uploadsnn == "" { 52 | PutSimplePairToBucket([]string{ er, "catalog", en, "_uploads"}, shortsizedt, "1") 53 | } else { 54 | val, _ := strconv.Atoi(string(uploadsnn)) 55 | val++ 56 | PutSimplePairToBucket([]string{ er, "catalog", en, "_uploads"}, shortsizedt, strconv.Itoa(val)) 57 | } 58 | PutSimplePairToBucket([]string{ er, "catalog", en, et}, "digest", didgesr) 59 | } 60 | 61 | func GetTags( er, en string) (tags []string){ 62 | tagsdb := GetAllPairsFromBucket([]string{ er, "catalog", en}) 63 | delete(tagsdb, "_valid") 64 | delete(tagsdb, "_uploads") 65 | delete(tagsdb, "_namepair") 66 | for et, _ := range tagsdb { 67 | if valid := GetValueFromBucket([]string{ er, "catalog", en, et}, "_valid"); valid == "1" { 68 | tags = append(tags, et) 69 | } 70 | } 71 | return 72 | } 73 | 74 | func AddTags( er, en string, tags []string){ 75 | tagsdb := GetAllPairsFromBucket([]string{ er, "catalog", en}) 76 | delete(tagsdb, "_valid") 77 | delete(tagsdb, "_uploads") 78 | delete(tagsdb, "_namepair") 79 | for etdb, _ := range tagsdb { 80 | PutSimplePairToBucket([]string{ er, "catalog", en, etdb}, "_valid", "0") 81 | } 82 | for _, etrp := range tags { 83 | // Just put new pairs, 'couse it will check and create bucket of tag in case it isn't exist 84 | PutSimplePairToBucket([]string{ er, "catalog", en, etrp}, "_valid", "1") 85 | PutBucketToBucket([]string{ er, "catalog", en, etrp, "_uploads"}) 86 | PutBucketToBucket([]string{ er, "catalog", en, etrp, "history"}) 87 | PutBucketToBucket([]string{ er, "catalog", en, etrp, "_totalsizehuman"}) 88 | PutBucketToBucket([]string{ er, "catalog", en, etrp, "_totalsizebytes"}) 89 | PutBucketToBucket([]string{ er, "catalog", en, etrp, "_parent"}) 90 | PutBucketToBucket([]string{ er, "_names", en + ":" + etrp}) 91 | } 92 | } 93 | 94 | func GetCatalog(er string) (catalog []string){ 95 | catalogdb := GetAllPairsFromBucket([]string{ er, "catalog"}) 96 | for en, _ := range catalogdb { 97 | if valid := GetValueFromBucket([]string{ er, "catalog", en}, "_valid"); valid == "1" { 98 | catalog = append(catalog, en) 99 | } 100 | } 101 | return 102 | } 103 | 104 | func AddCatalog(er string, catalog []string) { 105 | catalogdb := GetAllPairsFromBucket([]string{ er, "catalog"}) 106 | for endb, _ := range catalogdb { 107 | PutSimplePairToBucket([]string{ er, "catalog", endb}, "_valid", "0") 108 | } 109 | for _, enrp := range catalog { 110 | PutSimplePairToBucket([]string{ er, "catalog", enrp}, "_valid", "1") 111 | PutBucketToBucket([]string{ er, "catalog", enrp, "_uploads"}) 112 | PutBucketToBucket([]string{ er, "catalog", enrp, "_namepair"}) 113 | if len(GetAllPairsFromBucket([]string{ er, "catalog", enrp, "_namepair" })) == 0 { 114 | PutBucketToBucket([]string{ er, "catalog", enrp, "_namepair"}) 115 | idx := strings.Index(enrp, "/") 116 | if idx != -1 { 117 | PutSimplePairToBucket([]string{ er, "catalog", enrp, "_namepair"}, enrp[:idx], enrp[idx+1:]) 118 | } else { 119 | PutSimplePairToBucket([]string{ er, "catalog", enrp, "_namepair"}, "_none", enrp) 120 | } 121 | } 122 | } 123 | } 124 | 125 | func GetCatalogStructure(er string) (catalog []map[string]string){ 126 | catalogdb := GetAllPairsFromBucket([]string{ er, "catalog"}) 127 | for en, _ := range catalogdb { 128 | if valid := GetValueFromBucket([]string{ er, "catalog", en}, "_valid"); valid == "1" { 129 | elem := make(map[string]string) 130 | elem["fullname"] = en 131 | np := GetAllPairsFromBucket([]string{ er, "catalog", en, "_namepair"}) 132 | for n, p := range np { 133 | elem["namespace"] = n 134 | elem["nameshort"] = p 135 | } 136 | catalog = append(catalog, elem) 137 | } 138 | } 139 | return 140 | } 141 | -------------------------------------------------------------------------------- /project/src/db/db.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "say" 5 | "conf" 6 | "time" 7 | "github.com/boltdb/bolt" 8 | ) 9 | 10 | var DB *bolt.DB 11 | 12 | func Init(){ 13 | say.L2("DB: INIT: Start") 14 | var err error 15 | if DB, err = bolt.Open(conf.Env["dbpath"] + "/" + conf.Env["dbname"] + ".db", 0600, 16 | &bolt.Options{Timeout: 1 * time.Second}); err != nil { 17 | say.L3("DB: INIT: OPEN FILE: " + err.Error()) 18 | } 19 | if err = DB.Update(func(tx *bolt.Tx) error { 20 | if _, err := tx.CreateBucketIfNotExists([]byte("repositories")); err != nil { 21 | return err 22 | } else { 23 | return nil 24 | } 25 | }); err != nil { 26 | say.L3("DB: INIT: CREATE ROOT POINT: " + err.Error()) 27 | } 28 | 29 | for Upgrade() {} 30 | 31 | say.L2("DB: INIT: Done") 32 | } 33 | 34 | func Upgrade() (repeat bool){ 35 | repeat = true 36 | say.L1("DB: INIT: DB Upgrade: Start") 37 | if _, ok := GetAllPairsFromBucket([]string{})["_info"]; !ok { 38 | PutBucketToBucket([]string{"_info"}) 39 | } 40 | info := GetAllPairsFromBucket([]string{"_info"}) 41 | if len(info) == 0 { 42 | upto1() 43 | } else { 44 | if version, ok := info["version"]; ok { 45 | say.L2("DB: INIT: DB Upgrade: Version: " + version) 46 | switch version{ 47 | case "1": 48 | upto2() 49 | case "2": 50 | upto3() 51 | default: 52 | say.L2("DB: INIT: DB Upgrade: Actual version") 53 | repeat = false 54 | } 55 | } else { 56 | upto1() 57 | } 58 | } 59 | say.L1("DB: INIT: DB Upgrade: Finish") 60 | return 61 | } 62 | -------------------------------------------------------------------------------- /project/src/db/delete.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "say" 5 | "errors" 6 | "github.com/boltdb/bolt" 7 | ) 8 | 9 | func DeleteBucket(path []string) { 10 | var err error 11 | b := make([]*bolt.Bucket, len(path)+1) 12 | pathstr := "" 13 | if len(path) > 0 { 14 | pathstr = path[0] 15 | } 16 | for i := 1; i < len(path); i++ { 17 | pathstr = pathstr + "->" + path[i] 18 | } 19 | say.L1("DB: DELETE BUCKET: open bucket for DELETE [ " + pathstr + " ]") 20 | if err := DB.Update(func(tx *bolt.Tx) error { 21 | b[0] = tx.Bucket([]byte("repositories")) 22 | for i, e := range path { 23 | if b[i] != nil { 24 | b[i+1] = b[i].Bucket([]byte(e)) 25 | } else { 26 | return errors.New("DB: DELETE BUCKET: There is no such bucket [ " + path[i-1] + " ]") 27 | } 28 | } 29 | if b[len(path)] == nil { 30 | return errors.New("DB: DELETE BUCKET: There is no such bucket [ " + path[len(path)-1] + " ]") 31 | } 32 | say.L1("DB: DELETE BUCKET: deleting bucket [ " + path[len(path)-1] + " ]") 33 | if err = b[len(path)-1].DeleteBucket([]byte(path[len(path)-1])); err != nil { 34 | return err 35 | } 36 | return nil 37 | }); err != nil { 38 | say.L3(err.Error()) 39 | } 40 | say.L1("DB: DELETE BUCKET: Done") 41 | } 42 | 43 | func DeleteKey(path []string, key string ) { 44 | b := make([]*bolt.Bucket, len(path)+1) 45 | pathstr := "" 46 | if len(path) > 0 { 47 | pathstr = path[0] 48 | } 49 | for i := 1; i < len(path); i++ { 50 | pathstr = pathstr + "->" + path[i] 51 | } 52 | say.L1("DB: DELETE KEY: open bucket for DELETE [ " + pathstr + " ]") 53 | if err := DB.Update(func(tx *bolt.Tx) error { 54 | b[0] = tx.Bucket([]byte("repositories")) 55 | for i, e := range path { 56 | if b[i] != nil { 57 | b[i+1] = b[i].Bucket([]byte(e)) 58 | } else { 59 | return errors.New("DB: DELETE KEY: There is no such bucket [ " + path[i-1] + " ]") 60 | } 61 | } 62 | if b[len(path)] == nil { 63 | return errors.New("DB: DELETE KEY: There is no such bucket [ " + path[len(path)-1] + " ]") 64 | } 65 | if b[len(path)].Get([]byte(key)) == nil { 66 | return errors.New("DB: DELETE KEY: There is no such key [ " + key + " ]") 67 | } else { 68 | say.L1("DB: DELETE KEY: deleting key [ " + key + " ]") 69 | if err := b[len(path)].Delete([]byte(key)); err != nil { 70 | return err 71 | } 72 | return nil 73 | } 74 | }); err != nil { 75 | say.L3(err.Error()) 76 | } 77 | say.L1("DB: DELETE KEY: Done") 78 | } 79 | -------------------------------------------------------------------------------- /project/src/db/get.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "say" 5 | "errors" 6 | "github.com/boltdb/bolt" 7 | ) 8 | 9 | func GetAllPairsFromBucket(path []string) (pairs map[string]string){ 10 | b := make([]*bolt.Bucket, len(path)+1) 11 | pairs = make(map[string]string) 12 | pathstr := "" 13 | if len(path) > 0 { 14 | pathstr = path[0] 15 | } 16 | for i := 1; i < len(path); i++ { 17 | pathstr = pathstr + "->" + path[i] 18 | } 19 | if pathstr == "" { 20 | pathstr = "RootPoint" 21 | } 22 | say.L1("DB: GET BUCKET: open bucket for READ [ " + pathstr + " ]") 23 | if err := DB.View(func(tx *bolt.Tx) error { 24 | b[0] = tx.Bucket([]byte("repositories")) 25 | for i, e := range path { 26 | if b[i] != nil { 27 | b[i+1] = b[i].Bucket([]byte(e)) 28 | } else { 29 | return errors.New("DB: GET BUCKET: There is no such bucket [ " + path[i-1] + " ]") 30 | } 31 | } 32 | if b[len(path)] == nil { 33 | return errors.New("DB: GET BUCKET: There is no such bucket [ " + path[len(path)-1] + " ]") 34 | } 35 | if err := b[len(path)].ForEach(func(k, v []byte) error { 36 | pairs[string(k)] = string(v) 37 | return nil 38 | }); err != nil { 39 | return err 40 | } 41 | return nil 42 | }); err != nil { 43 | say.L3(err.Error()) 44 | } 45 | say.L1("DB: GET BUCKET: Done") 46 | return 47 | } 48 | 49 | func GetValueFromBucket(path []string, key string) (value string){ 50 | b := make([]*bolt.Bucket, len(path)+1) 51 | pathstr := "" 52 | if len(path) > 0 { 53 | pathstr = path[0] 54 | } 55 | for i := 1; i < len(path); i++ { 56 | pathstr = pathstr + "->" + path[i] 57 | } 58 | say.L1("DB: GET VALUE: open bucket for READ [ " + pathstr + "=>" + key + " ]") 59 | if err := DB.View(func(tx *bolt.Tx) error { 60 | b[0] = tx.Bucket([]byte("repositories")) 61 | for i, e := range path { 62 | if b[i] != nil { 63 | b[i+1] = b[i].Bucket([]byte(e)) 64 | } else { 65 | return errors.New("DB: GET VALUE: There is no such bucket [ " + path[i-1] + " ]") 66 | } 67 | } 68 | if b[len(path)] == nil { 69 | return errors.New("DB: GET VALUE: There is no such bucket [ " + path[len(path)-1] + " ]") 70 | } 71 | value = string(b[len(path)].Get([]byte(key))) 72 | return nil 73 | }); err != nil { 74 | say.L3(err.Error()) 75 | } 76 | say.L1("DB: GET VALUE: Done") 77 | return 78 | } 79 | -------------------------------------------------------------------------------- /project/src/db/put.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "say" 5 | "github.com/boltdb/bolt" 6 | ) 7 | 8 | func PutSimplePairToBucket(path []string, key string, value string){ 9 | var err error 10 | b := make([]*bolt.Bucket, len(path)+1) 11 | pathstr := "" 12 | if len(path) > 0 { 13 | pathstr = path[0] 14 | } 15 | for i := 1; i < len(path); i++ { 16 | pathstr = pathstr + "->" + path[i] 17 | } 18 | say.L1("DB: PUT PAIR: open bucket for WRITE [ " + pathstr + " ]") 19 | if err := DB.Update(func(tx *bolt.Tx) error { 20 | b[0] = tx.Bucket([]byte("repositories")) 21 | for i, e := range path { 22 | if b[i] != nil { 23 | b[i+1] = b[i].Bucket([]byte(e)) 24 | } else { 25 | say.L1("DB: PUT PAIR: creating bucket [ " + path[i-1] + " ]") 26 | if b[i], err = b[i-1].CreateBucketIfNotExists([]byte(path[i-1])); err != nil { 27 | return err 28 | } 29 | } 30 | } 31 | if b[len(path)] == nil { 32 | say.L1("DB: PUT PAIR: creating bucket [ " + path[len(path)-1] + " ]") 33 | if b[len(path)], err = b[len(path)-1].CreateBucketIfNotExists([]byte(path[len(path)-1])); err != nil { 34 | return err 35 | } 36 | } 37 | say.L1("DB: PUT PAIR: putting key in bucket [ " + key + " ]") 38 | b[len(path)].Put([]byte(key), []byte(value)) 39 | return nil 40 | }); err != nil { 41 | say.L3(err.Error()) 42 | } 43 | say.L1("DB: PUT PAIR: Done") 44 | } 45 | 46 | func PutBucketToBucket(path []string){ 47 | var err error 48 | b := make([]*bolt.Bucket, len(path)+1) 49 | pathstr := "" 50 | if len(path) > 0 { 51 | pathstr = path[0] 52 | } 53 | for i := 1; i < len(path); i++ { 54 | pathstr = pathstr + "->" + path[i] 55 | } 56 | say.L1("DB: CREATE BUCKET: open bucket for WRITE [ " + pathstr + " ]") 57 | if err := DB.Update(func(tx *bolt.Tx) error { 58 | b[0] = tx.Bucket([]byte("repositories")) 59 | for i, e := range path { 60 | if b[i] != nil { 61 | b[i+1] = b[i].Bucket([]byte(e)) 62 | } else { 63 | say.L1("DB: CREATE BUCKET: creating bucket [ " + path[i-1] + " ]") 64 | if b[i], err = b[i-1].CreateBucketIfNotExists([]byte(path[i-1])); err != nil { 65 | return err 66 | } 67 | } 68 | } 69 | if b[len(path)-1].Bucket([]byte(path[len(path)-1])) == nil { 70 | say.L1("DB: CREATE BUCKET: creating bucket [ " + path[len(path)-1] + " ]") 71 | if b[len(path)], err = b[len(path)-1].CreateBucketIfNotExists([]byte(path[len(path)-1])); err != nil { 72 | return err 73 | } 74 | } else { 75 | say.L1("DB: CREATE BUCKET: bucket already exist [ " + pathstr + " ]") 76 | } 77 | return nil 78 | }); err != nil { 79 | say.L3(err.Error()) 80 | } 81 | say.L1("DB: CREATE BUCKET: Done") 82 | } 83 | -------------------------------------------------------------------------------- /project/src/db/schema.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import ( 4 | "say" 5 | 6 | "errors" 7 | "strings" 8 | 9 | "github.com/boltdb/bolt" 10 | ) 11 | 12 | type Schema struct { 13 | Key string 14 | Children map[string]Schema 15 | } 16 | 17 | func GetSchemaFromPoint(path []string, filter string)(schema Schema){ 18 | b := []*bolt.Bucket{} 19 | pathstr := "" 20 | if len(path) > 0 { 21 | pathstr = path[0] 22 | } 23 | for i := 1; i < len(path); i++ { 24 | pathstr = pathstr + "->" + path[i] 25 | } 26 | say.L1("DB: GET SCHEMA: open bucket for READ [ " + pathstr + " ]") 27 | if err := DB.View(func(tx *bolt.Tx) error { 28 | b = append(b, tx.Bucket([]byte("repositories"))) 29 | for i, e := range path { 30 | if b[i] != nil { 31 | b = append(b, b[i].Bucket([]byte(e))) 32 | } else { 33 | return errors.New("DB: GET SCHEMA: There is no such bucket [ " + path[i-1] + " ]") 34 | } 35 | } 36 | if b[len(path)] == nil { 37 | return errors.New("DB: GET SCHEMA: There is no such bucket [ " + path[len(path)-1] + " ]") 38 | } 39 | schema, _ = buildSchemaRecursive(b[len(path)], "root", filter, false) 40 | return nil 41 | }); err != nil { 42 | say.L3(err.Error()) 43 | } 44 | say.L1("DB: GET SCHEMA: Done") 45 | return 46 | } 47 | 48 | func buildSchemaRecursive(b *bolt.Bucket, s string, f string, b0 bool) (_sch Schema, bi bool) { 49 | bl := false 50 | if (f == "") || (b0) { 51 | bl = true 52 | } else { 53 | bl = strings.Contains(s, f) 54 | bi = bl 55 | } 56 | 57 | _psc := make(map[string]Schema) 58 | _ = b.ForEach(func(k, v []byte) error { 59 | bk := b.Bucket([]byte(k)) 60 | if (bk != nil) { 61 | schtmp, bn := buildSchemaRecursive(bk, string(k), f, bl) 62 | if bl || bn { 63 | _psc[string(k)] = schtmp 64 | bi = true 65 | } 66 | return nil 67 | } 68 | return nil 69 | }); 70 | _sch = Schema{s, _psc} 71 | return 72 | } 73 | 74 | func Schema2json(schema Schema) (json string) { 75 | cnum := len(schema.Children) 76 | if cnum == 0 { 77 | json = "{\"text\":{\"name\":\"" + schema.Key + "\"}}" 78 | } else { 79 | json = "{\"text\":{\"name\":\"" + schema.Key + "\"}, \"children\": [" 80 | iter := 0 81 | for k, _ := range schema.Children { 82 | iter++ 83 | json += Schema2json(schema.Children[k]) 84 | if iter < cnum { 85 | json += "," 86 | } 87 | } 88 | json += "]}" 89 | } 90 | return 91 | } 92 | -------------------------------------------------------------------------------- /project/src/db/upgrade.go: -------------------------------------------------------------------------------- 1 | package db 2 | 3 | import( 4 | "say" 5 | "utils" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | func upto3(){ 11 | say.L2("DB: INIT: DB Upgrade: Need upgrade") 12 | repos := GetRepos() 13 | for er, _ := range repos { 14 | names := GetAllPairsFromBucket([]string{er, "catalog"}) 15 | for en, _ := range names { 16 | if en != "_valid" { 17 | PutBucketToBucket([]string{ er, "catalog", en, "_namepair"}) 18 | idx := strings.Index(en, "/") 19 | if idx != -1 { 20 | PutSimplePairToBucket([]string{ er, "catalog", en, "_namepair"}, en[:idx], en[idx+1:]) 21 | } else { 22 | PutSimplePairToBucket([]string{ er, "catalog", en, "_namepair"}, "_none", en) 23 | } 24 | } 25 | } 26 | } 27 | PutSimplePairToBucket([]string{"_info"}, "version", "3") 28 | } 29 | 30 | func upto2(){ 31 | say.L2("DB: INIT: DB Upgrade: Need upgrade") 32 | repos := GetRepos() 33 | for er, _ := range repos{ 34 | repofull := GetAllPairsFromBucket([]string{er}) 35 | PutSimplePairToBucket([]string{er, "_info"}, "host", repofull["repohost"]) 36 | PutSimplePairToBucket([]string{er, "_info"}, "pass", repofull["repopass"]) 37 | PutSimplePairToBucket([]string{er, "_info"}, "user", repofull["repouser"]) 38 | if scheme, ok := repofull["reposcheme"]; ok { 39 | PutSimplePairToBucket([]string{er, "_info"}, "scheme", scheme) 40 | DeleteKey([]string{er}, "reposcheme") 41 | } else { 42 | PutSimplePairToBucket([]string{er, "_info"}, "scheme", "http") 43 | } 44 | PutSimplePairToBucket([]string{er, "_info"}, "name", er) 45 | PutSimplePairToBucket([]string{er, "_info"}, "secure", "true") 46 | DeleteKey([]string{er}, "repohost") 47 | DeleteKey([]string{er}, "repopass") 48 | DeleteKey([]string{er}, "repouser") 49 | } 50 | PutSimplePairToBucket([]string{"_info"}, "version", "2") 51 | } 52 | 53 | func upto1(){ 54 | say.L2("DB: INIT: DB Upgrade: Version: 0") 55 | say.L2("DB: INIT: DB Upgrade: Need upgrade") 56 | PutSimplePairToBucket([]string{"_info"}, "version", "1") 57 | } 58 | 59 | func UpgradeOldParentNames(){ 60 | say.L2("DB UPGRADE: make upgrade for old parent names") 61 | repos := GetRepos() 62 | for key, value := range repos { 63 | if value == "" { 64 | names := GetAllPairsFromBucket([]string{key, "_names"}) 65 | for keyn, valuen := range names { 66 | if valuen != "" { 67 | DeleteKey([]string{key, "_names" }, keyn) 68 | } 69 | } 70 | } 71 | } 72 | } 73 | 74 | func UpgradeFalseNumericImage(){ 75 | say.L2("DB UPGRADE: make upgrade for false numeric image") 76 | repos := GetRepos() 77 | for key, value := range repos { 78 | if value == "" { 79 | imagenames := GetAllPairsFromBucket([]string{key, "catalog"}) 80 | for keyi, _ := range imagenames { 81 | if _, err := strconv.Atoi(keyi); err == nil { 82 | DeleteBucket([]string{key, "catalog", keyi}) 83 | } 84 | } 85 | } 86 | } 87 | } 88 | 89 | func UpgradeTotalSize(){ 90 | say.L2("DB UPGRADE: make upgrade for total size") 91 | repos := GetRepos() 92 | for key, value := range repos { 93 | if value == "" { 94 | imagenames := GetAllPairsFromBucket([]string{key, "catalog"}) 95 | for keyi, _ := range imagenames { 96 | tags := GetAllPairsFromBucket([]string{key, "catalog", keyi}) 97 | for keyt, _ := range tags { 98 | if (keyt != "_uploads") && (keyt != "_valid") { 99 | fields := GetAllPairsFromBucket([]string{key, "catalog", keyi, keyt}) 100 | if _, ok := fields["_totalsize"]; ok { 101 | totalsize := GetAllPairsFromBucket([]string{key, "catalog", keyi, keyt, "_totalsize"}) 102 | for keys, vals := range totalsize { 103 | lastchar := vals[len(vals)-1:len(vals)] 104 | if lastchar == "B"{ 105 | PutSimplePairToBucket([]string{key, "catalog", keyi, keyt, "_totalsizehuman"}, keys, vals) 106 | PutSimplePairToBucket([]string{key, "catalog", keyi, keyt, "_totalsizebytes"}, keys, 107 | strconv.Itoa(utils.FromHumanToByte(vals))) 108 | } else { 109 | PutSimplePairToBucket([]string{key, "catalog", keyi, keyt, "_totalsizebytes"}, keys, vals) 110 | num, _ := strconv.Atoi(vals) 111 | PutSimplePairToBucket([]string{key, "catalog", keyi, keyt, "_totalsizehuman"}, keys, 112 | utils.FromByteToHuman(num)) 113 | } 114 | } 115 | DeleteBucket([]string{key, "catalog", keyi, keyt, "_totalsize"}) 116 | } 117 | } 118 | } 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /project/src/dt/dt.go: -------------------------------------------------------------------------------- 1 | package dt 2 | 3 | import( 4 | "say" 5 | "conf" 6 | 7 | "time" 8 | ) 9 | 10 | 11 | func Watch(start time.Time, name string) { 12 | if conf.Env["timewatch"] == "yes" { 13 | elapsed := time.Since(start) 14 | say.L2("TimeWatch: [ " + name + " ] - " + elapsed.String()) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /project/src/handler/deleteimage.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import( 4 | "db" 5 | "say" 6 | "qurl" 7 | "checker" 8 | 9 | "net/url" 10 | "net/http" 11 | ) 12 | 13 | func DeleteImage(w http.ResponseWriter, r *http.Request){ 14 | if v, err := url.ParseQuery(r.URL.RawQuery); err != nil { 15 | say.L3(err.Error()) 16 | } else { 17 | if (v["reponame"] != nil) && (v["curname"] != nil) && (v["curtag"] != nil) { 18 | say.L1("Starting delete manifest [ " + v["reponame"][0] + "/" + v["curname"][0] + "/" + v["curtag"][0] + " ]") 19 | query := "/v2/" + v["curname"][0] + "/manifests/" + 20 | db.GetValueFromBucket([]string{v["reponame"][0], "catalog", v["curname"][0], v["curtag"][0]}, "digest") 21 | inhdr := map[string]string{"Accept": "application/vnd.docker.distribution.manifest.v2+json"} 22 | if _, _, ok := qurl.MakeQuery(query, "DELETE", db.GetRepoPretty(v["reponame"][0]), inhdr); ok { 23 | db.PutSimplePairToBucket([]string{ v["reponame"][0], "catalog", v["curname"][0], v["curtag"][0]}, "_valid", "0") 24 | go checker.RunCheckTags() 25 | http.Redirect(w, r, "/info?reponame=" + v["reponame"][0] + "&curname=" + v["curname"][0], 307) 26 | } 27 | } else { 28 | say.L3("Something wrong with args in deleteHandler") 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /project/src/handler/info.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import( 4 | "db" 5 | "dt" 6 | "say" 7 | "utils" 8 | 9 | "time" 10 | "sort" 11 | "strconv" 12 | "net/url" 13 | "net/http" 14 | "encoding/json" 15 | ) 16 | 17 | func Info(w http.ResponseWriter, r *http.Request){ 18 | defer dt.Watch(time.Now(), "Info Handler") 19 | 20 | irepos := make(map[string]interface{}) 21 | headerdata := make(map[string]string) 22 | repos := utils.Keys(db.GetRepos()) 23 | sort.Strings(repos) 24 | irepos["repos"] = repos 25 | 26 | if v, err := url.ParseQuery(r.URL.RawQuery); err != nil { 27 | say.L3(err.Error()) 28 | } else { 29 | headerdata["header"] = "" 30 | headerdata["currepo"] = "" 31 | irepos["curname"] = "" 32 | 33 | if v["reponame"] != nil { 34 | if v["reponame"][0] != "" { 35 | irepos["reponame"] = v["reponame"][0] 36 | 37 | headerdata["header"] = irepos["reponame"].(string) + " : " + 38 | db.GetRepoPretty(irepos["reponame"].(string))["host"] 39 | headerdata["currepo"] = irepos["reponame"].(string) 40 | irepos["curname"] = irepos["reponame"].(string) 41 | 42 | namesStructure := db.GetCatalogStructure(irepos["reponame"].(string)) 43 | nsarr := []string{} 44 | if (len(namesStructure) > 0) { 45 | sort.Slice(namesStructure, func(i, j int) bool { 46 | return namesStructure[i]["fullname"] < namesStructure[j]["fullname"] 47 | }) 48 | nslast := namesStructure[0]["namespace"] 49 | nsarr = append(nsarr, nslast) 50 | for _, e := range namesStructure { 51 | if nslast != e["namespace"] { 52 | nsarr = append(nsarr, e["namespace"]) 53 | nslast = e["namespace"] 54 | } 55 | } 56 | } 57 | irepos["namespaces"] = nsarr 58 | 59 | if v["curnamespace"] != nil { 60 | irepos["curnamespace"] = v["curnamespace"][0] 61 | 62 | nmarr := []string{} 63 | for _, e := range namesStructure { 64 | if irepos["curnamespace"] == e["namespace"] { 65 | nmarr = append(nmarr, e["nameshort"]) 66 | } 67 | } 68 | irepos["shortnames"] = nmarr 69 | 70 | if v["curshortname"] != nil { 71 | irepos["curshortname"] = v["curshortname"][0] 72 | if irepos["curnamespace"].(string) == "_none" { 73 | irepos["curname"] = irepos["curshortname"].(string) 74 | } else { 75 | irepos["curname"] = irepos["curnamespace"].(string) + "/" + irepos["curshortname"].(string) 76 | } 77 | 78 | tags := db.GetTags(irepos["reponame"].(string), irepos["curname"].(string)) 79 | sort.Strings(tags) 80 | uploads := make(map[string]map[string]string) 81 | totaluploads := make(map[string]int) 82 | for _, e := range tags { 83 | uploads[e] = make(map[string]string) 84 | uploads[e] = db.GetAllPairsFromBucket([]string{ 85 | irepos["reponame"].(string), 86 | "catalog", 87 | irepos["curname"].(string), 88 | e, 89 | "_uploads" }) 90 | count := 0 91 | for _, eu := range uploads[e] { 92 | if num, err := strconv.Atoi(eu); err != nil { 93 | say.L3(err.Error()) 94 | } else { 95 | count += num 96 | } 97 | } 98 | totaluploads[e] = count 99 | } 100 | irepos["tags"] = totaluploads 101 | headerdata["header"] = headerdata["header"] + "/" + irepos["curname"].(string) 102 | if v["curtag"] != nil { 103 | irepos["curtag"] = v["curtag"][0] 104 | irepos["uploads"] = uploads[irepos["curtag"].(string)] 105 | headerdata["header"] = headerdata["header"] + ":" + irepos["curtag"].(string) 106 | var dbpath = []string{ 107 | irepos["reponame"].(string), 108 | "catalog", 109 | irepos["curname"].(string), 110 | irepos["curtag"].(string), 111 | "history" } 112 | strhist := db.GetAllPairsFromBucket(dbpath) 113 | objhist := make(map[string]interface{}) 114 | lastkey := "" 115 | layersnum := 0 116 | for key, value := range strhist { 117 | var ch interface{} 118 | _ = json.Unmarshal([]byte(value), &ch) 119 | objhist[key] = ch 120 | if lastkey < key { 121 | lastkey = key 122 | } 123 | layersnum++ 124 | } 125 | irepos["history"] = objhist 126 | irepos["lastupdated"] = lastkey 127 | irepos["layersnum"] = layersnum 128 | dbpath[4] = "_totalsizehuman" 129 | strsizehuman := db.GetAllPairsFromBucket(dbpath) 130 | dbpath[4] = "_totalsizebytes" 131 | strsizebytes := db.GetAllPairsFromBucket(dbpath) 132 | lastkey = "" 133 | for key, _ := range strsizehuman { 134 | if lastkey < key { 135 | lastkey = key 136 | } 137 | } 138 | if strsizebytes != nil { 139 | irepos["imagesizebytes"] = strsizebytes 140 | } 141 | if strsizehuman != nil { 142 | irepos["imagesizehuman"] = strsizehuman 143 | } 144 | irepos["lastpushed"] = lastkey 145 | dbpath[4] = "_parent" 146 | 147 | parentDescr := db.GetAllPairsFromBucket(dbpath) 148 | dbpath[2] = parentDescr["name"] 149 | dbpath[3] = "_namepair" 150 | npair := db.GetAllPairsFromBucket(dbpath[0:4]) 151 | for e, k := range npair { 152 | parentDescr["namespace"] = e 153 | parentDescr["shortname"] = k 154 | } 155 | irepos["parent"] = parentDescr 156 | } 157 | } 158 | } 159 | } 160 | } 161 | } 162 | 163 | irepos["headerdata"] = headerdata 164 | irepos["action"] = "info" 165 | renderTemplate(w, "info", irepos) 166 | } 167 | -------------------------------------------------------------------------------- /project/src/handler/main.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import( 4 | "say" 5 | 6 | "net/http" 7 | ) 8 | 9 | func Main(w http.ResponseWriter, r *http.Request){ 10 | if r.URL.Path == "/" { 11 | Info(w, r) 12 | } else { 13 | if r.URL.Path != "/favicon.ico" { 14 | say.L3("Main Handler : Wrong query [" + r.URL.Path + "]") 15 | http.Redirect(w, r, "/", 307) 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /project/src/handler/managerepos.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import( 4 | "db" 5 | "say" 6 | "utils" 7 | 8 | "sort" 9 | "net/url" 10 | "net/http" 11 | ) 12 | 13 | func ManageRepos(w http.ResponseWriter, r *http.Request){ 14 | urlc := r.URL.Path[len("/managerepos/"):] 15 | repos := utils.Keys(db.GetRepos()) 16 | sort.Strings(repos) 17 | var repopretty map[string]string 18 | if urlc == "add" { 19 | if v, err := url.ParseQuery(r.URL.RawQuery); err != nil { 20 | say.L3(err.Error()) 21 | } else { 22 | if len(v) != 0 { 23 | db.CreateRepo(v) 24 | http.Redirect(w, r, "/managerepos/", 307) 25 | } 26 | } 27 | } 28 | if urlc == "edit" { 29 | if v, err := url.ParseQuery(r.URL.RawQuery); err != nil { 30 | say.L3(err.Error()) 31 | } else { 32 | if len(v) == 1 { 33 | repopretty = db.GetRepoPretty(v["reponame"][0]) 34 | repopretty["pass"] = "" 35 | } 36 | if len(v) > 1 { 37 | db.CreateRepo(v) 38 | http.Redirect(w, r, "/managerepos/", 307) 39 | } 40 | } 41 | } 42 | if urlc == "delete" { 43 | if v, err := url.ParseQuery(r.URL.RawQuery); err != nil { 44 | say.L3(err.Error()) 45 | } else { 46 | if len(v) == 1 { 47 | db.DeleteRepo(v["reponame"][0]) 48 | http.Redirect(w, r, "/managerepos/", 307) 49 | } 50 | } 51 | } 52 | irepos := make(map[string]interface{}, len(urlc)+len(repos)+len(repopretty)) 53 | 54 | irepos["path"] = urlc 55 | irepos["repos"] = repos 56 | irepos["chosen"] = repopretty 57 | irepos["action"] = "conf" 58 | 59 | renderTemplate(w, "managerepos", irepos) 60 | } 61 | -------------------------------------------------------------------------------- /project/src/handler/render.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import( 4 | "say" 5 | 6 | "net/http" 7 | "html/template" 8 | ) 9 | 10 | func renderTemplate(w http.ResponseWriter, tmpl string, c interface{}) { 11 | say.L1("Rendering template [ " + tmpl + " ]") 12 | templates := template.Must(template.ParseGlob("./templates/*")) 13 | err := templates.ExecuteTemplate(w, tmpl, c) 14 | if err != nil { 15 | http.Error(w, err.Error(), http.StatusInternalServerError) 16 | return 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /project/src/handler/repograph.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import( 4 | "dt" 5 | "db" 6 | "say" 7 | "utils" 8 | 9 | "time" 10 | "sort" 11 | "net/url" 12 | "net/http" 13 | ) 14 | 15 | func RepoGraph(w http.ResponseWriter, r *http.Request){ 16 | defer dt.Watch(time.Now(), "Graph Handler") 17 | 18 | if v, err := url.ParseQuery(r.URL.RawQuery); err != nil { 19 | say.L3(err.Error()) 20 | } else { 21 | irepos := make(map[string]interface{}) 22 | headerdata := make(map[string]string) 23 | repos := utils.Keys(db.GetRepos()) 24 | sort.Strings(repos) 25 | irepos["repos"] = repos 26 | irepos["action"] = "graph" 27 | 28 | headerdata["header"] = "" 29 | headerdata["currepo"] = "" 30 | irepos["curname"] = "" 31 | 32 | irepos["headerdata"] = headerdata 33 | 34 | filter := "" 35 | 36 | if v["reponame"] == nil { 37 | say.L3("Name of repository not set in repograpHandler") 38 | } else { 39 | if v["reponame"][0] != "" { 40 | irepos["reponame"] = v["reponame"][0] 41 | 42 | headerdata["header"] = irepos["reponame"].(string) + " : " + 43 | db.GetRepoPretty(irepos["reponame"].(string))["host"] 44 | headerdata["currepo"] = irepos["reponame"].(string) 45 | irepos["curname"] = irepos["reponame"].(string) 46 | 47 | nsarr := []string{} 48 | namesStructure := db.GetCatalogStructure(irepos["reponame"].(string)) 49 | if (len(namesStructure) > 0) { 50 | sort.Slice(namesStructure, func(i, j int) bool { 51 | return namesStructure[i]["fullname"] < namesStructure[j]["fullname"] 52 | }) 53 | nslast := namesStructure[0]["namespace"] 54 | nsarr = append(nsarr, nslast) 55 | for _, e := range namesStructure { 56 | if nslast != e["namespace"] { 57 | nsarr = append(nsarr, e["namespace"]) 58 | nslast = e["namespace"] 59 | } 60 | } 61 | } 62 | irepos["namespaces"] = nsarr 63 | if v["curnamespace"] != nil { 64 | irepos["curnamespace"] = v["curnamespace"][0] 65 | if irepos["curnamespace"].(string) != "_none" { 66 | filter = irepos["curnamespace"].(string) 67 | } 68 | 69 | nmarr := []string{} 70 | for _, e := range namesStructure { 71 | if irepos["curnamespace"] == e["namespace"] { 72 | nmarr = append(nmarr, e["nameshort"]) 73 | } 74 | } 75 | irepos["shortnames"] = nmarr 76 | 77 | if v["curshortname"] != nil { 78 | irepos["curshortname"] = v["curshortname"][0] 79 | 80 | if irepos["curnamespace"].(string) == "_none" { 81 | irepos["curname"] = irepos["curshortname"].(string) 82 | } else { 83 | irepos["curname"] = irepos["curnamespace"].(string) + "/" + irepos["curshortname"].(string) 84 | } 85 | 86 | headerdata["header"] = headerdata["header"] + "/" + irepos["curname"].(string) 87 | filter = irepos["curname"].(string) 88 | 89 | tags := db.GetTags(irepos["reponame"].(string), irepos["curname"].(string)) 90 | sort.Strings(tags) 91 | totaluploads := make(map[string]string) 92 | for _, e := range tags { 93 | totaluploads[e] = "" 94 | } 95 | irepos["tags"] = totaluploads 96 | headerdata["header"] = headerdata["header"] + "/" + irepos["curname"].(string) 97 | 98 | if v["curtag"] != nil { 99 | irepos["curtag"] = v["curtag"][0] 100 | headerdata["header"] = headerdata["header"] + ":" + irepos["curtag"].(string) 101 | 102 | filter = irepos["curname"].(string) + ":" + irepos["curtag"].(string) 103 | } 104 | } 105 | } 106 | 107 | irepos["graphdata"] = db.Schema2json(db.GetSchemaFromPoint([]string{irepos["reponame"].(string), "_namesgraph"}, filter)) 108 | 109 | headerdata := make(map[string]string) 110 | headerdata["header"] = irepos["reponame"].(string) + " : " + 111 | db.GetRepoPretty(irepos["reponame"].(string))["host"] 112 | headerdata["currepo"] = irepos["reponame"].(string) 113 | irepos["headerdata"] = headerdata 114 | 115 | irepos["repodata"] = make(map[string]interface{}) 116 | repos := utils.Keys(db.GetRepos()) 117 | sort.Strings(repos) 118 | irepos["repodata"].(map[string]interface{})["catalog"] = repos 119 | irepos["repodata"].(map[string]interface{})["curname"] = irepos["reponame"].(string) 120 | } else { 121 | irepos["graphdata"] = "" 122 | 123 | headerdata := make(map[string]string) 124 | headerdata["header"] = "" 125 | headerdata["currepo"] = "" 126 | irepos["headerdata"] = headerdata 127 | 128 | irepos["repodata"] = make(map[string]interface{}) 129 | irepos["repodata"].(map[string]interface{})["catalog"] = utils.Keys(db.GetRepos()) 130 | irepos["repodata"].(map[string]interface{})["curname"] = "" 131 | } 132 | } 133 | renderTemplate(w, "repograph", irepos) 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /project/src/handler/updateall.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import( 4 | "checker" 5 | 6 | "net/http" 7 | ) 8 | 9 | func UpdateAll(w http.ResponseWriter, r *http.Request){ 10 | checker.StartManual() 11 | http.Redirect(w, r, "/info", 307) 12 | } 13 | -------------------------------------------------------------------------------- /project/src/handler/upgradedb.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import( 4 | "db" 5 | "say" 6 | 7 | "net/http" 8 | ) 9 | 10 | func UpgradeDB(w http.ResponseWriter, r *http.Request){ 11 | funcname := r.URL.Path[len("/upgrade/"):] 12 | say.L1("Starting upgrade for [ " + funcname + " ]") 13 | if funcname == "totalsize" { 14 | db.UpgradeTotalSize() 15 | } 16 | if funcname == "falsenumnames" { 17 | db.UpgradeFalseNumericImage() 18 | } 19 | if funcname == "oldparentnames" { 20 | db.UpgradeOldParentNames() 21 | } 22 | http.Redirect(w, r, "/", 307) 23 | } 24 | -------------------------------------------------------------------------------- /project/src/qurl/qurl.go: -------------------------------------------------------------------------------- 1 | package qurl 2 | 3 | import( 4 | "say" 5 | 6 | "strings" 7 | "strconv" 8 | "net/http" 9 | "io/ioutil" 10 | "crypto/tls" 11 | "encoding/json" 12 | "encoding/base64" 13 | ) 14 | 15 | func makequery(rqst *http.Request, secure bool) (body interface{}, header map[string][]string, status int){ 16 | var client *http.Client 17 | if secure { 18 | client = &http.Client{} 19 | } else { 20 | tr := &http.Transport{ 21 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 22 | } 23 | client = &http.Client{Transport: tr} 24 | } 25 | if resp, err := client.Do(rqst); err != nil { 26 | status = -1 27 | say.L3(err.Error()) 28 | say.L3("Probably something wrong with network configuration or registry state") 29 | } else { 30 | defer resp.Body.Close() 31 | status = resp.StatusCode 32 | header = resp.Header 33 | if status == 200 || status == 401 { 34 | if bodytmp, err := ioutil.ReadAll(resp.Body); err != nil { 35 | status = -1 36 | say.L3(err.Error()) 37 | } else { 38 | var c interface{} 39 | if len(bodytmp) == 0 { 40 | body = map[string]string{} 41 | } else { 42 | if err := json.Unmarshal(bodytmp, &c); err != nil { 43 | status = -1 44 | say.L3(err.Error()) 45 | say.L3("makequery: Cannot convert body to interface") 46 | } else { 47 | body = c 48 | if c.(map[string]interface{})["errors"] != nil && status != 401 { 49 | say.L3(c.(map[string]interface{})["errors"].([]interface{})[0].(map[string]interface{})["message"].(string)) 50 | } 51 | } 52 | } 53 | } 54 | } 55 | } 56 | return 57 | } 58 | 59 | func getbearertoken(wwwauth string, user string, pass string, secure bool) (token string, ok bool){ 60 | ok = false 61 | query := "" 62 | splitted := strings.Split(wwwauth, ",") 63 | if len(splitted) < 3 { 64 | say.L3(wwwauth) 65 | } else { 66 | idaddrs := strings.Index(splitted[0], "\"") 67 | idservc := strings.Index(splitted[1], "\"") 68 | idscope := strings.Index(splitted[2], "\"") 69 | if (idaddrs == -1) || (idservc == -1) || (idscope == -1) { 70 | say.L3(splitted[0]) 71 | say.L3(splitted[1]) 72 | say.L3(splitted[2]) 73 | } else { 74 | if (splitted[0][:idaddrs-1]=="Bearer realm") && 75 | (splitted[1][:idservc-1]=="service") && 76 | (splitted[2][:idscope-1]=="scope") { 77 | 78 | addrs := splitted[0][idaddrs+1:len(splitted[0])-1] 79 | servc := splitted[1][idservc+1:len(splitted[1])-1] 80 | servc = strings.Replace(servc, " ", "+", -1) 81 | scope := splitted[2][idscope+1:len(splitted[2])-1] 82 | query = addrs + "?account=" + user + "&service=" + servc + "&scope=" + scope 83 | if reqst, err := http.NewRequest("GET", query, nil); err != nil { 84 | say.L3("Qurl: getbearertoken: cannot create query") 85 | say.L3(err.Error()) 86 | } else { 87 | // + user + ":" + pass + "@" + 88 | reqst.Header.Add("Authorization", "Basic " + 89 | base64.StdEncoding.EncodeToString([]byte(user + ":" + pass))) 90 | body, _, c := makequery(reqst, secure) 91 | if c == 200 { 92 | token = body.(map[string]interface{})["token"].(string) 93 | ok = true 94 | } 95 | } 96 | } else { 97 | say.L3("Qurl: GetBearerToken: Registry sent wrong Www-Authenticate header.") 98 | say.L3(wwwauth) 99 | } 100 | } 101 | } 102 | if !ok { 103 | say.L3("Qurl: GetBearerToken: Registry sent wrong Www-Authenticate header or token specification was changed.") 104 | } 105 | return 106 | } 107 | 108 | func MakeQuery(query, method string, info, inhdrs map[string]string) (body interface{}, outhdrs map[string][]string, ok bool){ 109 | ok = false 110 | var c int 111 | secure := true 112 | if info["secure"] == "false" { secure = false} 113 | tquery := info["scheme"] + "://" + info["host"] + query 114 | if reqst, err := http.NewRequest(method, tquery, nil); err != nil { 115 | say.L3("Qurl: MakeQuery: cannot create query") 116 | say.L3(err.Error()) 117 | } else { 118 | reqst.Header.Add("Authorization", "Basic " + 119 | base64.StdEncoding.EncodeToString([]byte(info["user"] + ":" + info["pass"]))) 120 | for kh, vh := range inhdrs{ 121 | reqst.Header.Set(kh, vh) 122 | } 123 | body, outhdrs, c = makequery(reqst, secure) 124 | if c == 401 { 125 | if outhdrs["Www-Authenticate"][0][0:5] == "Basic" { 126 | say.L3("MakeQuery: Code [401] : Unauthorized response is returned (credentials problem, check user/pass pair)") 127 | return 128 | } else if outhdrs["Www-Authenticate"][0][0:6] == "Bearer" { 129 | say.L1("MakeQuery: Code [401] : Bearer auth. Trying to get auth token.") 130 | if token, oktok := getbearertoken(outhdrs["Www-Authenticate"][0], info["user"], info["pass"], secure); !oktok { 131 | say.L3("MakeQuery: Bearer: Cannot obtain token for [" + outhdrs["Www-Authenticate"][0] + "]") 132 | return 133 | } else { 134 | say.L1("MakeQuery: Bearer: Token recieved. Retriying query.") 135 | tquery = info["scheme"] + "://" + info["host"] + query 136 | if reqst, err := http.NewRequest(method, tquery, nil); err != nil { 137 | say.L3(err.Error()) 138 | return 139 | } else { 140 | reqst.Header.Add("Authorization", "Bearer "+token) 141 | for kh, vh := range inhdrs{ 142 | reqst.Header.Set(kh, vh) 143 | } 144 | body, outhdrs, c = makequery(reqst, secure) 145 | if c == 401 { 146 | say.L3("MakeQuery: Token: Code [401] : Unauthorized response is returned (credentials problem, check user/pass pair or communication between registry and auth server)") 147 | say.L3(body.(map[string]interface{})["errors"].([]interface{})[0].(map[string]interface{})["message"].(string)) 148 | return 149 | } 150 | } 151 | } 152 | } 153 | } 154 | if c != 200 { body = c } 155 | switch c { 156 | case 200: 157 | if method=="GET" || method=="HEAD" { ok = true } else { say.L3("MakeQuery: Unexpected [200] status")} 158 | case 202: 159 | if method=="DELETE"{ ok = true } else { say.L3("MakeQuery: Unexpected [202] status")} 160 | case 404: 161 | say.L3("MakeQuery: [404] Page not found") 162 | case -1: 163 | say.L3("MakeQuery: Netwrok or internal problem") 164 | default: 165 | say.L3("MakeQuery: Cannot diagnose problem. Code \n[ " + strconv.Itoa(c) + " ] ") 166 | } 167 | } 168 | return 169 | } 170 | -------------------------------------------------------------------------------- /project/src/qurl/qurl_test.go: -------------------------------------------------------------------------------- 1 | package qurl 2 | 3 | import( 4 | "say" 5 | "time" 6 | "flag" 7 | "utils" 8 | "strings" 9 | "net/http" 10 | "strconv" 11 | "testing" 12 | "encoding/json" 13 | ) 14 | 15 | var TestAddress string 16 | var TestInfo map[string]string 17 | func init(){ 18 | flag.StringVar(&TestAddress, "repo", "", "Repository to be tested") 19 | flag.Parse() 20 | tmpaddress := TestAddress 21 | TestInfo = make(map[string]string) 22 | TestInfo["scheme"]=tmpaddress[:strings.Index(tmpaddress, "://")] 23 | tmpaddress = tmpaddress[strings.Index(tmpaddress, "://")+3:] 24 | TestInfo["user"]=tmpaddress[:strings.Index(tmpaddress, ":")] 25 | tmpaddress = tmpaddress[strings.Index(tmpaddress, ":")+1:] 26 | TestInfo["pass"]=tmpaddress[:strings.Index(tmpaddress, "@")] 27 | tmpaddress = tmpaddress[strings.Index(tmpaddress, "@")+1:] 28 | TestInfo["host"]=tmpaddress 29 | TestInfo["secure"]="false" 30 | } 31 | 32 | func TestGetAPI(t *testing.T){ 33 | // say.L1(">> GET /v2/") 34 | // if body_ping, _, ok := MakeQuery("/v2/", "GET", TestInfo, map[string]string{}); !ok { 35 | // if body_ping == 404 { 36 | // say.L3("API V2 is not supported by this registry") 37 | // } 38 | // t.Fail() 39 | // } else { 40 | say.L1(">> GET /v2/_catalog") 41 | if body_catalog, _, ok := MakeQuery("/v2/_catalog", "GET", TestInfo, map[string]string{}); !ok { 42 | t.Fail() 43 | } else { 44 | var catalog interface{} 45 | if body_catalog.(map[string]interface{})["repositories"] == nil { 46 | say.L3("There is no 'repositories' field, check API specification") 47 | t.Fail() 48 | } else { 49 | catalog = body_catalog.(map[string]interface{})["repositories"] 50 | if len(catalog.([]interface{})) == 0 { 51 | say.L3("The catalog is empty, cannot make further checks") 52 | t.Fail() 53 | } else { 54 | for _, ei := range catalog.([]interface{}) { 55 | say.L1(">> GET /v2/" + ei.(string) + "/tags/list") 56 | if body_tags, _, ok := MakeQuery("/v2/" + ei.(string) + "/tags/list", 57 | "GET", TestInfo, map[string]string{}); ok { 58 | if body_tags.(map[string]interface{})["name"] != nil && 59 | body_tags.(map[string]interface{})["tags"] != nil { 60 | for _, et := range body_tags.(map[string]interface{})["tags"].([]interface{}) { 61 | say.L1(">> GET /v2/" + ei.(string) + "/manifests/" + et.(string)) 62 | if body_manifest, _, ok := MakeQuery("/v2/" + ei.(string) + "/manifests/" + et.(string), 63 | "GET", TestInfo, map[string]string{}); ok { 64 | say.L1(">> CHECK MANIFEST FIELDS [" + ei.(string) + ":" + et.(string)+"]") 65 | testManifestFields(t, body_manifest) 66 | if !t.Failed() { 67 | say.L1(">> Ok") 68 | } 69 | say.L1(">> CHECK CONTENT DIGEST [" + ei.(string) + ":" + et.(string)+"]") 70 | testContentDigest(t, body_manifest) 71 | if !t.Failed() { 72 | say.L1(">> Ok") 73 | } 74 | say.L1(">> CHECK FSSHA & HISTORY [" + ei.(string) + ":" + et.(string)+"]") 75 | testFSSHAandHistory(t, body_manifest) 76 | if !t.Failed() { 77 | say.L1(">> Ok") 78 | } 79 | } 80 | } 81 | } 82 | } 83 | } 84 | } 85 | } 86 | } 87 | // } 88 | } 89 | 90 | func testManifestFields(t *testing.T, manifest interface{}){ 91 | if _, ok := manifest.(map[string]interface{})["name"].(string); !ok { 92 | say.L3("Something wrong with 'name' field.") 93 | say.L3("Probably API was changed.") 94 | say.L4(manifest.(map[string]interface{})["name"]) 95 | t.Fail() 96 | } 97 | 98 | if _, ok := manifest.(map[string]interface{})["tag"].(string); !ok { 99 | say.L3("Something wrong with 'tag' field.") 100 | say.L3("Probably API was changed.") 101 | say.L4(manifest.(map[string]interface{})["tag"]) 102 | t.Fail() 103 | } 104 | 105 | if _, ok := manifest.(map[string]interface{})["fsLayers"].([]interface{}); !ok { 106 | say.L3("Something wrong with 'fsLayers' field.") 107 | say.L3("Probably API was changed.") 108 | say.L4(manifest.(map[string]interface{})["fsLayers"]) 109 | t.Fail() 110 | } else { 111 | if _, ok := manifest.(map[string]interface{})["fsLayers"].([]interface{})[0].(map[string]interface{})["blobSum"].(string); !ok { 112 | say.L3("Something wrong with 'blobSum' field.") 113 | say.L3("Probably API was changed.") 114 | say.L4(manifest.(map[string]interface{})["fsLayers"].([]interface{})[0].(map[string]interface{})["blobSum"]) 115 | t.Fail() 116 | } 117 | } 118 | 119 | if e, ok := manifest.(map[string]interface{})["history"].([]interface{}); !ok { 120 | say.L3("Something wrong with 'history' field.") 121 | say.L3("Probably API was changed.") 122 | say.L4(manifest.(map[string]interface{})["history"]) 123 | t.Fail() 124 | } else { 125 | if _, ok := e[0].(map[string]interface{})["v1Compatibility"].(string); !ok { 126 | say.L3("Something wrong with 'v1Compatibility' field.") 127 | say.L3("Probably API was changed.") 128 | say.L4(e[0].(map[string]interface{})["v1Compatibility"]) 129 | t.Fail() 130 | } 131 | } 132 | } 133 | 134 | func testContentDigest(t *testing.T, Manifest interface{}){ 135 | client := &http.Client{} 136 | Query := "/v2/" + 137 | Manifest.(map[string]interface{})["name"].(string) + "/manifests/" + 138 | Manifest.(map[string]interface{})["tag"].(string) 139 | say.L1(">> GET DIGEST " + Query) 140 | Reqtv2Digest, _ := http.NewRequest("GET", TestAddress + Query, nil) 141 | Reqtv2Digest.Header.Set("Accept", "application/vnd.docker.distribution.manifest.v2+json") 142 | if Respv2Digest, err := client.Do(Reqtv2Digest); err != nil { 143 | say.L3("Cannot recieve response from registry.") 144 | t.Fail() 145 | } else { 146 | defer Respv2Digest.Body.Close() 147 | contentdigest := Respv2Digest.Header.Get("Docker-Content-Digest") 148 | if contentdigest[0:7] != "sha256:"{ 149 | say.L3("Digest was received in wrong format.") 150 | say.L3("Probably API was changed.") 151 | say.L4(contentdigest) 152 | say.L4(contentdigest[0:7]) 153 | t.Fail() 154 | } 155 | } 156 | } 157 | 158 | func testFSSHAandHistory(t *testing.T, Manifest interface{}){ 159 | fsshaarr := Manifest.(map[string]interface{})["fsLayers"].([]interface{}) 160 | historyarr := Manifest.(map[string]interface{})["history"].([]interface{}) 161 | for i, _ := range fsshaarr { 162 | fssha := fsshaarr[i].(map[string]interface{})["blobSum"].(string) 163 | if _, fsshdr, okcl := MakeQuery("/v2/" + Manifest.(map[string]interface{})["name"].(string) + "/blobs/" + fssha, 164 | "HEAD", TestInfo, map[string]string{}); !okcl { 165 | say.L3("Cannot recieve fssha header from registry") 166 | t.Fail() 167 | } else { 168 | fssize := fsshdr["Content-Length"][0] 169 | if fsshanum, err := strconv.Atoi(fssize); err != nil { 170 | say.L3(err.Error()) 171 | say.L3("Cannot convert fssha size to int.") 172 | say.L3("Probably API was changed.") 173 | t.Fail() 174 | } else { 175 | if strconv.Itoa(utils.FromHumanToByte(utils.FromByteToHuman(fsshanum)))[0:2] != fssize[0:2] { 176 | say.L3("Connot convert size from Human to Byte and Back") 177 | t.Fail() 178 | } 179 | } 180 | var ch interface{} 181 | history := historyarr[i].(map[string]interface{})["v1Compatibility"].(string) 182 | if err := json.Unmarshal([]byte(history), &ch); err != nil { 183 | say.L3(err.Error()) 184 | say.L3("Cannot convert v1Compatibility history to JSON.") 185 | say.L3("Probably API was changed.") 186 | t.Fail() 187 | } else { 188 | if created, ok := ch.(map[string]interface{})["created"].(string); !ok { 189 | say.L3("Something went wrong with 'history->v1Compatibility->created' field.") 190 | say.L3("Probably API was changed.") 191 | say.L4(ch.(map[string]interface{})["created"]) 192 | t.Fail() 193 | } else { 194 | var indx int 195 | if indx = strings.Index(created, "T"); indx > -1 { 196 | created = created[:indx] + " " + created[indx+1:] 197 | if indx = strings.Index(created, "."); indx > -1 { 198 | created = created[:indx] 199 | } 200 | } 201 | if indx < 0 { 202 | say.L3("Timedate format was not in supposed form") 203 | t.Fail() 204 | } 205 | if dt, err := time.Parse("2006-01-02 15:04:05", created); err != nil { 206 | say.L3(err.Error()) 207 | say.L3("Something went wrong with 'history->v1Compatibility->created' conversion.") 208 | say.L3("Probably API was changed.") 209 | say.L4(ch.(map[string]interface{})["created"]) 210 | t.Fail() 211 | } else { 212 | if created != dt.Format("2006-01-02 15:04:05") { 213 | say.L3("Reverse time converson went wrong.") 214 | t.Fail() 215 | } 216 | } 217 | } 218 | if c_conf, ok := ch.(map[string]interface{})["container_config"]; !ok { 219 | say.L3("Something went wrong with 'manifest->history->container_config' fiels.") 220 | say.L3("Probably API was changed.") 221 | say.L4(ch) 222 | t.Fail() 223 | } else { 224 | if _, ok := c_conf.(map[string]interface{})["Cmd"].([]interface{}); !ok { 225 | say.L3("Something went wrong with 'manifest->history->container_config->Cmd' field.") 226 | say.L3("Probably API was changed.") 227 | say.L4(c_conf) 228 | t.Fail() 229 | } 230 | } 231 | } 232 | } 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /project/src/say/say.go: -------------------------------------------------------------------------------- 1 | package say 2 | 3 | import( 4 | "conf" 5 | 6 | "github.com/fatih/color" 7 | 8 | "time" 9 | "fmt" 10 | ) 11 | var mode string 12 | 13 | func L1(str string){ 14 | cyan := color.New(color.FgCyan).SprintFunc() 15 | if conf.Env["log_silent"] != "yes" && conf.Env["log_silent"] != "super" { 16 | fmt.Printf("[ " + time.Now().Format(time.RFC1123) + " ]" + cyan("[ L1 ] ") + str + "\n") 17 | } 18 | } 19 | 20 | func L2(str string){ 21 | yellow := color.New(color.FgYellow).SprintFunc() 22 | if conf.Env["log_silent"] != "super" { 23 | fmt.Printf("[ " + time.Now().Format(time.RFC1123) + " ]" + yellow("[ L2 ] ") + str + "\n") 24 | } 25 | } 26 | 27 | func L3(str string){ 28 | if conf.Env["log_silent"] != "super" { 29 | finstr := "[ " + time.Now().Format(time.RFC1123) + " ][ L3 ] " + str 30 | color.Red(finstr) 31 | } 32 | } 33 | 34 | func L4(str interface{}){ 35 | fmt.Println(str) 36 | } 37 | -------------------------------------------------------------------------------- /project/src/utils/utils.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import( 4 | "say" 5 | 6 | "strings" 7 | "strconv" 8 | ) 9 | 10 | func IsSliceDifferent(a []string, b []string) (bool) { 11 | al := len(a) 12 | bl := len(b) 13 | if a == nil && b == nil { 14 | say.L1("Slices are equally nill. Same.") 15 | return false 16 | } 17 | if a == nil || b == nil { 18 | say.L1("One of the slices is empty. Different.") 19 | return true 20 | } 21 | if al != bl { 22 | say.L1("Length of slices are different. Different.") 23 | return true 24 | } 25 | numofequal := 0 26 | for _, bel := range b { 27 | for _, ael := range a { 28 | if bel == ael{ 29 | numofequal++ 30 | break 31 | } 32 | } 33 | } 34 | if len(a) == numofequal { 35 | say.L1("Length of slices are same with number of equal elements. Same.") 36 | return false 37 | } else { 38 | say.L1("Length of slices are differ with number of equal elements. Different.") 39 | return true 40 | } 41 | } 42 | 43 | func FromByteToHuman(bytes int) (human string){ 44 | var num float64 45 | num = float64(bytes) 46 | human = strconv.FormatFloat(num, 'f', 2, 64) + " B" 47 | human = strings.Replace(human, ".00 B", " B", 1) 48 | if num > 1024 { 49 | num = num / 1024 50 | human = strconv.FormatFloat(num, 'f', 2, 64) + " KB" 51 | human = strings.Replace(human, ".00 KB", " KB", 1) 52 | } 53 | if num > 1024 { 54 | num = num / 1024 55 | human = strconv.FormatFloat(num, 'f', 2, 64) + " MB" 56 | human = strings.Replace(human, ".00 MB", " MB", 1) 57 | } 58 | if num > 1024 { 59 | num = num / 1024 60 | human = strconv.FormatFloat(num, 'f', 2, 64) + " GB" 61 | human = strings.Replace(human, ".00 MB", " MB", 1) 62 | } 63 | return 64 | } 65 | func FromHumanToByte(human string) (bytes int){ 66 | space := strings.Index(human, " ") 67 | bytes = 0 68 | number := "" 69 | scale := "" 70 | if space != -1 { 71 | number = human[:space] 72 | scale = human[space+1:] 73 | } 74 | fscale := 0.0 75 | switch scale { 76 | case "B": 77 | bytes, _ = strconv.Atoi(number) 78 | return 79 | case "KB": 80 | fscale = 1024 81 | case "MB": 82 | fscale = 1024 * 1024 83 | case "GB": 84 | fscale = 1024 * 1024 * 1024 85 | } 86 | fnum, _ := strconv.ParseFloat(number, 64) 87 | bytes = int(fnum * fscale) 88 | return 89 | } 90 | 91 | func Keys(inmap map[string]string) (outkeys []string){ 92 | outkeys = make([]string, 0, len(inmap)) 93 | for k := range inmap { 94 | outkeys = append(outkeys, k) 95 | } 96 | return 97 | } 98 | -------------------------------------------------------------------------------- /project/templates/catalogbar.html: -------------------------------------------------------------------------------- 1 | {{ define "catalogbar" }} 2 | {{ $input := . }} 3 | {{ if $input.namespaces }} 4 | 25 | 48 | {{ end }} 49 | {{ end }} 50 | -------------------------------------------------------------------------------- /project/templates/info.html: -------------------------------------------------------------------------------- 1 | {{ define "info" }} 2 | 3 | {{ $input := . }} 4 | 5 | 6 | 7 | 8 | 9 | {{ template "topbar" $input }} 10 |
11 | {{ template "repobar" $input }} 12 | {{ template "catalogbar" $input }} 13 | {{ template "tagbar" $input }} 14 | {{ template "manifestbar" $input }} 15 |
16 | 17 | 22 | 23 | {{ end }} 24 | -------------------------------------------------------------------------------- /project/templates/managerepos.html: -------------------------------------------------------------------------------- 1 | {{ define "managerepos" }} 2 | {{ $input := . }} 3 | 4 | 5 | 6 | 7 | 8 | 9 | {{ template "topbar" $input }} 10 | 34 | {{ if eq $input.path "add" }} 35 |
36 |
37 | Repo name:   (Just how it will be shown in this app)
38 | Repo scheme: http 39 | https 40 |
41 | Secure repo:                 42 | (Leave unchecked if your repo and/or auth server is insecure/use self-signed certs)
43 | Repo addr:   (Hostname or ip:port of repo)
44 | Username:    (Username to connect to Repo, mandatory field)
45 | Password:    (Password to connect to Repo, mandatory field)
46 |
47 | Cancel 48 |
49 | {{ end }} 50 | {{ if eq $input.path "edit" }} 51 |
52 |
53 | Repo name:   (Just how it will be shown in this app)
54 | Repo scheme: {{ if $input.chosen.scheme }} 55 | {{ if eq $input.chosen.scheme "http"}} 56 | http 57 | https 58 | {{ end }} 59 | {{ if eq $input.chosen.scheme "https"}} 60 | http 61 | https 62 | {{ end }} 63 | {{ else }} 64 | http 65 | https 66 | {{ end }} 67 |
68 | {{ if $input.chosen.secure }} 69 | Secure repo: {{ if eq $input.chosen.secure "true"}} 70 | 71 | {{else}} 72 | 73 | {{end}} 74 |                 75 | (Leave unchecked if your repo and/or auth server is insecure/use self-signed certs)
76 | {{end}} 77 | Repo addr:   (Hostname or ip:port of repo)
78 | Username:    (Username to connect to Repo, mandatory field)
79 | Password:    (Password to connect to Repo, mandatory field)
80 | 81 |
82 | 83 | Delete 84 | Cancel 85 |
86 | {{ end }} 87 | 88 | 93 | 94 | {{ end }} 95 | -------------------------------------------------------------------------------- /project/templates/manifestbar.html: -------------------------------------------------------------------------------- 1 | {{ define "manifestbar" }} 2 | {{ $input := . }} 3 | {{ if $input.history }} 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 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | {{ if $input.parent.name }} 48 | 52 | {{ else }} 53 | 54 | {{ end }} 55 | 56 | 57 |
Name{{ $input.curname }}
Tag{{ $input.curtag }}
Last Updated{{ $input.lastupdated }}
Last Pushed{{ $input.lastpushed }}
Image Size{{ index $input.imagesizehuman $input.lastpushed }}
Number Of Pushes{{ index $input.tags $input.curtag }}
Number Of Layers{{ $input.layersnum }}
Parent Image 49 | 50 | {{ $input.parent.name }}:{{ $input.parent.tag }} 51 | Parent unknown
58 | [DELETE] 60 |
61 |
62 | 63 |
64 |
65 | 66 |
67 | 145 |
146 |
147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | {{ range $time, $histobj := $input.history }} 157 | 158 | 159 | 160 | 165 | 166 | {{ end }} 167 | 168 |
Created TimeCompressed SizeCreeating Commad
{{ $time }}{{ $histobj.blobSize }} 161 | {{ range $i, $e := $histobj.container_config.Cmd }} 162 | {{ $e }} 163 | {{ end }} 164 |
169 |
170 |
171 |
172 | {{ end }} 173 | {{ end }} 174 | -------------------------------------------------------------------------------- /project/templates/repobar.html: -------------------------------------------------------------------------------- 1 | {{ define "repobar" }} 2 | {{ $input := . }} 3 | 30 | {{ end }} 31 | -------------------------------------------------------------------------------- /project/templates/repograph.html: -------------------------------------------------------------------------------- 1 | {{ define "repograph" }} 2 | {{ $input := . }} 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | {{ template "topbar" $input }} 20 | {{ template "repobar" $input }} 21 | {{ template "catalogbar" $input }} 22 | {{ template "tagbar" $input }} 23 |
24 | 64 | 65 | 66 | {{ end }} 67 | -------------------------------------------------------------------------------- /project/templates/tagbar.html: -------------------------------------------------------------------------------- 1 | {{ define "tagbar" }} 2 | {{ $input := . }} 3 | {{ if $input.tags }} 4 | 29 | {{ end }} 30 | {{ end }} 31 | -------------------------------------------------------------------------------- /project/templates/topbar.html: -------------------------------------------------------------------------------- 1 | {{define "topbar"}} 2 | {{ $input := . }} 3 |
4 | {{ if $input.headerdata }} 5 |

{{ $input.headerdata.header }}

6 | {{ end }} 7 | 8 | {{ if eq $input.action "info" }} 9 | Repos 10 | {{ else }} 11 | Repos 12 | {{ end }} 13 | 14 | {{ if eq $input.action "graph" }} 15 | Graph 16 | {{ else }} 17 | Graph 18 | {{ end }} 19 | 20 | {{ if eq $input.action "conf" }} 21 | Confs 22 | {{ else }} 23 | Confs 24 | {{ end }} 25 | Update all 26 |
27 | {{end}} 28 | --------------------------------------------------------------------------------