├── .gitignore ├── LICENSE ├── README.md ├── django-admin ├── README.md ├── ansible │ ├── container.yml │ ├── files │ │ └── nginx.conf │ ├── inventory │ ├── main.yml │ └── requirements.txt ├── example │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── gulpfile.js ├── manage.py ├── package.json ├── requirements.txt └── src │ ├── html │ └── index.html │ ├── js │ └── main.js │ └── sass │ ├── _base.scss │ ├── _mixins.scss │ ├── _reset.scss │ ├── _vars.scss │ ├── _z-index.scss │ └── style.scss ├── django-cms ├── ansible │ ├── container.yml │ ├── main.yml │ └── requirements.txt └── requirements.txt ├── elk-stack ├── README.md ├── ansible │ ├── container.yml │ ├── devel.yml │ ├── main.yml │ └── requirements.txt ├── default.conf ├── filebeat.yml ├── html │ ├── favicon.ico │ └── index.html ├── logstash-beats.crt └── start.sh ├── flask-helloworld ├── README.md └── ansible │ ├── container.yml │ ├── flask-helloworld │ ├── hello_world.py │ ├── static │ │ └── style.css │ └── templates │ │ ├── index.html │ │ └── master.html │ ├── main.yml │ └── requirements.txt ├── helloworld-nginx ├── README.md ├── container.yml ├── files │ └── index.html ├── main.yml └── requirements.txt ├── images ├── django-admin.png └── image_streams.png ├── sshd ├── README.md └── ansible │ ├── container.yml │ ├── main.yml │ └── requirements.txt └── wordpress ├── README.md └── ansible ├── container.yml ├── main.yml └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Swap file 86 | *.swp 87 | 88 | # Spyder project settings 89 | .spyderproject 90 | 91 | # Rope project settings 92 | .ropeproject 93 | 94 | # shipit output and testing 95 | roles/ 96 | ansible/roles/ 97 | shipit_*/ 98 | shipit*.yml 99 | tmp.yml 100 | *.log 101 | *.retry 102 | *.out 103 | 104 | .ansible/ 105 | .bash_history 106 | .v8flags.4.6.85.31.undefined.json 107 | .idea/* 108 | 109 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ansible-container-examples 2 | 3 | This repo is deprecated. Examples are now found in [Ansible Galaxy](https://galaxy.ansible.com/). Look for *[container app](https://galaxy.ansible.com/list#/roles?page=1&page_size=10&role_type=APP)* and *[container enabled](https://galaxy.ansible.com/list#/roles?page=1&page_size=10&role_type=CON)* roles. 4 | -------------------------------------------------------------------------------- /django-admin/README.md: -------------------------------------------------------------------------------- 1 | # django-admin 2 | 3 | This is the same example project found in the [ansible-container repo](https://github.com/ansible/ansible-container/tree/master/example) with a twist. The images have 4 | been modified as needed to enable deployment on OpenShift. 5 | 6 | ## Why? 7 | 8 | The original project can be deployed to Kubernetes as is. OpenShift is built on Kubernetes, but it has its own security requirements. First, container processes cannot 9 | run as the *root* user. Even the entrypoint script cannot run as a privileged user. Second, the container must be able to run as an arbitrary user. 10 | 11 | Per the OpenShift [image creation guidelines](https://docs.openshift.org/latest/creating_images/guidelines.html): 12 | 13 | > By default, OpenShift Origin runs containers using an arbitrarily assigned user ID. This provides additional security against processes escaping the container due 14 | > to a container engine vulnerability and thereby achieves escalated permissions on the host node. 15 | > 16 | > For an image to support running as an arbitray user, directories and files that may be written to by processes in the image should be owned by the root group and be 17 | > read/writable by that group. Files to be executed should also have group execute permissions. 18 | 19 | ## Changes 20 | 21 | To make the example work within these constraints the following changes were made: 22 | 23 | - For the postgresql service, switch the base image to [openshift/postgresql-92-centos7](https://hub.docker.com/r/openshift/postgresql-92-centos7/) 24 | - For the django service, change file permissions on any directories and files the django process will access. 25 | - For the static service, also change file permissions on any directories and files the nginx process will access. 26 | 27 | Setting file permissions entails changing the group to *root* and granting read, write access to the group. This works because the arbitrary user employed by OpenShift is a member 28 | of *root*. The file permission changes are applied in the [ansible/main.yml](https://github.com/ansible/ansible-container-examples/blob/master/django-admin/ansible/main.yml) playbook. 29 | If you compare to the original [example/ansible/main.yml](https://github.com/ansible/ansible-container/blob/develop/example/ansible/main.yml) playbook, you'll see the specific changes. 30 | 31 | ## Requirements 32 | 33 | To complete the deployment to OpenShift you will need the following: 34 | 35 | - An [OpenShift Online Next Geneneration](https://www.openshift.com/devpreview/) developer preview account. 36 | - The OpenShift CLI installed. Log into your OpenShift Next Generation account and view [command line tools page](https://console.dev-preview-stg.openshift.com/console/command-line) 37 | - Ansible Container installed. See the [Ansible Container install guide](http://docs.ansible.com/ansible-container/installation.html) for assistance. 38 | - A local copy of the ansible-container-examples repo: 39 | 40 | ``` 41 | git clone https://github.com/ansible/ansible-container-examples.git 42 | ``` 43 | 44 | ### Build 45 | 46 | Start by building the example. Run the *build* command from within the *django-admin* directory found in your local copy of the project: 47 | 48 | ``` 49 | $ cd ansible-container-examples/django-admin 50 | $ ansible-container build 51 | ``` 52 | 53 | The *build* command creates the images for the sample application. There are 4 services defined in [ansible/container.yml](https://github.com/ansible/ansible-container-examples/blob/master/django-admin/ansible/container.yml) 54 | To build the images a container is created and started for each service, along with an Ansible Build container for running Ansible. A total of 5 containers will be started. 55 | 56 | The [ansible/main.yml playbook](https://github.com/ansible/ansible-container-examples/blob/master/django-admin/ansible/main.yml) is executed on the Ansible Build container with an inventory 57 | consisting of the 4 service names defined in *container.yml*. If you examine *main.yml*, you will notice that each play has a *hosts* directive listing one or more of the service names where 58 | tasks will be executed. If you're an experienced Ansible user, this should look and feel very familiar. Ansible playbook execution is exactly the same here as it is in any other environment 59 | with one exception. Instead of using SSH to communicate to the remote nodes, we're using the Docker connection plugin. 60 | 61 | As the build command proceeds, output from the playbook execution will appear, marking the completion of each task and play. Once completed, containers are committed and stopped. A Docker 62 | *commit* is essentially a snap-shot of the container at that moment, and it becomes an image. When the build process is fully complete, there will be 4 new images available in the local 63 | image cache. 64 | 65 | Example output from running the *build* command follows: 66 | 67 | ``` 68 | (Re)building the Ansible Container image. 69 | Building Docker Engine context... 70 | Starting Docker build of Ansible Container image (please be patient)... 71 | 72 | ... (A whole bunch of build and playbook execution output) ... 73 | 74 | ansible-container_1 | PLAY RECAP ********************************************************************* 75 | ansible-container_1 | django : ok=15 changed=11 unreachable=0 failed=0 76 | ansible-container_1 | gulp : ok=13 changed=9 unreachable=0 failed=0 77 | ansible-container_1 | static : ok=10 changed=8 unreachable=0 failed=0 78 | ansible-container_1 | 79 | ansible_ansible-container_1 exited with code 0 80 | Aborting on container exit... 81 | Stopping ansible_static_1 ... done 82 | Stopping ansible_gulp_1 ... done 83 | Stopping ansible_django_1 ... done 84 | Stopping ansible_postgresql_1 ... done 85 | Exporting built containers as images... 86 | Committing image... 87 | Exported django-admin-gulp with image ID sha256:3c1f9b5518a1a6f4aeccb1a576562d61ac8cef836c70f7f9078147ca8303de22 88 | Cleaning up gulp build container... 89 | Committing image... 90 | Exported django-admin-static with image ID sha256:15b944afc72e42c5f75a85dbb832c7966ba4ae1c071e36293a9b109f41ef55a6 91 | Cleaning up static build container... 92 | Committing image... 93 | Exported django-admin-django with image ID sha256:d362d1b749c9235aab144d764168036702dff03455b06887aa6a401b1288c905 94 | Cleaning up django build container... 95 | Cleaning up Ansible Container builder... 96 | ``` 97 | 98 | Checking the local image cache shows the new images: 99 | 100 | ``` 101 | $ docker images 102 | 103 | REPOSITORY TAG IMAGE ID CREATED SIZE 104 | django-admin-django 20160705211710 d362d1b749c9 10 minutes ago 886 MB 105 | django-admin-django latest d362d1b749c9 10 minutes ago 886 MB 106 | django-admin-static 20160705211710 15b944afc72e 10 minutes ago 890.6 MB 107 | django-admin-static latest 15b944afc72e 10 minutes ago 890.6 MB 108 | django-admin-gulp 20160705211710 3c1f9b5518a1 10 minutes ago 354.2 MB 109 | django-admin-gulp latest 3c1f9b5518a1 10 minutes ago 354.2 MB 110 | ansible-container-builder latest 00617d3fed58 20 minutes ago 884 MB 111 | ``` 112 | 113 | ## Run 114 | 115 | After building the application, run it locally to make sure everything works. The `ansible-container run` command will start each of the containers in 116 | an attached state, streaming stdout of each container terminal window. The containers will remain active until the terminal session is 117 | killed or the kill signal is sent by pressing *Ctrl-c*. 118 | 119 | With the containers running, you should be able to open a browser window and access the application on port 8100 of the Docker daemon host. The root of the application 120 | is */admin*. So to get to the application in your browser, you'll enter: `http://:8100/admin` 121 | 122 | If you're running Docker Machine, the Docker daemon host is the IP of the Vagrant box. You can get the IP with the command `docker-machine ip `, where 123 | host name is the actual name of the host registered with VirtualBox Manager. 124 | 125 | When everything is working, you will see th following in your browser: 126 | 127 | ![django-admin-img](https://github.com/ansible/ansible-container-examples/blob/master/images/django-admin.png) 128 | 129 | ## Login 130 | 131 | If you have not already done so, log into your OpenShift web console and create a project called *django-admin*. The application will be deployed into this project. 132 | 133 | You'll also need to authenticate with the OpenShift CLI. The instructions with the correct URL and access token can be found in your web console. Look for the support 134 | menu in the top right corner of the screen. Open it, and choose Command Line Tools. You will see a sample `oc login` command. Click the *click to show token* link and 135 | copy the full command. 136 | 137 | Here's an example of logging in and setting the default project: 138 | 139 | ``` 140 | $ oc login https://api.dev-preview-stg.openshift.com --token= 141 | $ oc project django-admin 142 | 143 | Now using project "django-admin" on server "https://api.dev-preview-stg.openshift.com:443" 144 | ``` 145 | 146 | ## Push 147 | 148 | Before the application can be deployed, the OpenShift cluster needs access to the image files. The easiest way to make the images accessible is to push them to the 149 | internal OpenShift registry, which you can do using Ansible Container. Note in the example below, we pass a --push-to value equal to the OpenShift registry followed 150 | by '/' and the name of the project: 151 | 152 | ``` 153 | $ ansible-container push --push-to https://registry.dev-preview-stg.openshift.com/django-admin --username --password 154 | ``` 155 | 156 | After successfully pushing the images, take a look at the images on OpenShift. Images on Openshift are referred to as *image streams*. Within your OpenShift web console 157 | go to [image streams](https://console.dev-preview-stg.openshift.com/console/project/django-admin/browse/images?main-tab=openshiftConsole%2Fbrowse&sub-tab=openshiftConsole%2Fbrowse-images). 158 | You should see a similar list of image streams: 159 | 160 | ![image streams](https://github.com/ansible/ansible-container-examples/blob/master/images/image_streams.png) 161 | 162 | ## ShipIt 163 | 164 | Next, run *shipit* to generate a deployment playbook and role. Specify the *openshift* engine, and use the --pull-from option to specify the URL the cluster will use to pull 165 | the images. 166 | 167 | **NOTE** the URL for the *--pull-from* option is not the same URL used to push the images. The --pull-from URL will point to the internal registry using an IP address. 168 | View the [image streams page](https://console.dev-preview-stg.openshift.com/console/project/django-admin/browse/images?main-tab=openshiftConsole%2Fbrowse&sub-tab=openshiftConsole%2Fbrowse-images) in your OpenShift web console to get the correct IP address. 169 | 170 | Follow the IP address with '/' + the name of the project. Your *shipit* command will be similar to the following: 171 | 172 | ``` 173 | $ ansible-container shipit openshift --pull-from 172.30.46.234:5000/django-admin 174 | 175 | Images will be pulled from 172.30.46.234:5000/django-admin 176 | Attaching to ansible_ansible-container_1 177 | Cleaning up Ansible Container builder... 178 | Role django-admin created. 179 | ``` 180 | 181 | Running *shipit* results in a playbook and a role being created in the *ansible* directory. You will see a *roles* directory and shipit-openshift.yml playbook: 182 | 183 | ``` 184 | $ ls -l ansible 185 | 186 | total 88 187 | -rw-r--r-- 1 chouseknecht staff 14760 Jul 8 12:25 ansible-container.log 188 | -rw-r--r-- 1 chouseknecht staff 1403 Jul 8 12:17 container.yml 189 | drwxr-xr-x 3 chouseknecht staff 102 Jul 7 18:21 files 190 | -rw-r--r-- 1 chouseknecht staff 10 Jun 26 13:14 inventory 191 | -rw-r--r-- 1 chouseknecht staff 7 Jul 8 11:54 main.retry 192 | -rw-r--r-- 1 chouseknecht staff 4005 Jul 8 11:57 main.yml 193 | -rw-r--r-- 1 chouseknecht staff 148 Jun 26 13:14 requirements.txt 194 | drwxr-xr-x 3 chouseknecht staff 102 Jul 6 02:09 roles <---- 195 | -rw-r--r-- 1 chouseknecht staff 179 Jul 6 02:09 shipit-openshift.yml <---- 196 | ``` 197 | 198 | ## Deploy 199 | 200 | From within the *ansible* directory run he playbook to deploy the app. 201 | 202 | ``` 203 | $ cd ansible 204 | $ ansible-playbook shipit-openshift.yml 205 | ``` 206 | 207 | After the playbook completes, take a look at the services, pods and routes created by the role: 208 | 209 | ``` 210 | $ oc get service 211 | 212 | NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE 213 | django 172.30.9.83 8080/TCP 2d 214 | postgresql 172.30.53.172 5432/TCP 2d 215 | static 172.30.6.139 80/TCP 2d 216 | 217 | 218 | $ oc get pod 219 | 220 | NAME READY STATUS RESTARTS AGE 221 | django-1-aw6s3 1/1 Running 0 2h 222 | postgresql-1-19z6q 1/1 Running 0 2h 223 | static-1-rwn1d 1/1 Running 0 2h 224 | 225 | $ oc get route 226 | 227 | NAME HOST/PORT PATH SERVICE TERMINATION LABELS 228 | static-80 static-80-django-admin.b795.dev-preview-stg.openshiftapps.com static:port-80 app=django-admin,service=static 229 | 230 | ``` 231 | 232 | The pods are created using deployments: 233 | 234 | ``` 235 | $ oc get dc 236 | 237 | NAME REVISION REPLICAS TRIGGERED BY 238 | django 1 1 config 239 | postgresql 1 1 config 240 | static 1 1 config 241 | 242 | ``` 243 | 244 | The route contains the URL for accessing the application via web browser. It's the full *openshfitapps.com* domain listed under *HOST/PORT* in the output from `oc get route`. 245 | Add '/admin' to view the same log-in page viewed when the app ran locally. 246 | 247 | **NOTE** The domain name is randomly generated by OpenShift. Use the domain generated by OpenShift in your environment, not the one listed in the above `oc get route` 248 | output example. 249 | 250 | Using the above output from `oc get route`, the log-in page to our app is accessed with the following: 251 | 252 | ``` 253 | http://static-80-django-admin.b795.dev-preview-stg.openshiftapps.com/admin 254 | ``` 255 | 256 | With not too much effort we were able to launch the app on OpenShift and demonstrate how Ansible Container manages the container lifecycle. If you're interested in 257 | learning more, or have questions, please let us know how we can help. The best ways to reach us are: 258 | 259 | * [Join the mailing list](https://groups.google.com/forum/#!forum/ansible-container) 260 | * [Open an issue](https://github.com/ansible/ansible-container/issues) 261 | * Join the #ansible-container channel on irc.freenode.net. 262 | -------------------------------------------------------------------------------- /django-admin/ansible/container.yml: -------------------------------------------------------------------------------- 1 | version: "1" 2 | services: 3 | django: 4 | image: centos:7 5 | expose: 6 | - "8080" 7 | working_dir: '/django' 8 | links: 9 | - postgresql 10 | user: 'django' 11 | command: ['/usr/bin/dumb-init', '/venv/bin/gunicorn', '-w', '2', '-b', '0.0.0.0:8080', 'example.wsgi:application'] 12 | dev_overrides: 13 | command: ['/usr/bin/dumb-init', '/venv/bin/python', 'manage.py', 'runserver', '0.0.0.0:8080'] 14 | volumes: 15 | - "$PWD:/django" 16 | options: 17 | kube: 18 | runAsUser: 1000 19 | static: 20 | image: centos:7 21 | ports: 22 | - "80:8080" 23 | user: 'nginx' 24 | links: 25 | - django 26 | command: ['/usr/bin/dumb-init', 'nginx', '-c', '/etc/nginx/nginx.conf'] 27 | dev_overrides: 28 | ports: [] 29 | # command: /bin/false 30 | options: 31 | kube: 32 | runAsUser: 997 33 | postgresql: 34 | image: openshift/postgresql-92-centos7 35 | expose: 36 | - 5432 37 | volumes: 38 | - '/var/lib/pgsql/data' 39 | environment: 40 | POSTGRESQL_USER: 'example' 41 | POSTGRESQL_PASSWORD: 'sesame' 42 | POSTGRESQL_DATABASE: 'example' 43 | gulp: 44 | image: centos:7 45 | user: 'node' 46 | links: 47 | - django 48 | command: /bin/false 49 | dev_overrides: 50 | working_dir: '/node' 51 | command: ['/usr/bin/dumb-init', '/node_modules/.bin/gulp'] 52 | ports: 53 | - "8080:8080" 54 | volumes: 55 | - "$PWD:/node" 56 | options: 57 | kube: 58 | state: absent 59 | openshift: 60 | state: absent 61 | 62 | registries: {} 63 | 64 | -------------------------------------------------------------------------------- /django-admin/ansible/files/nginx.conf: -------------------------------------------------------------------------------- 1 | # user nginx; 2 | daemon off; 3 | worker_processes auto; 4 | 5 | events { 6 | worker_connections 1024; 7 | } 8 | 9 | http { 10 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 11 | '$status $body_bytes_sent "$http_referer" ' 12 | '"$http_user_agent" "$http_x_forwarded_for"'; 13 | 14 | sendfile on; 15 | tcp_nopush on; 16 | tcp_nodelay on; 17 | keepalive_timeout 65; 18 | types_hash_max_size 2048; 19 | 20 | include /etc/nginx/mime.types; 21 | default_type application/octet-stream; 22 | 23 | # Load modular configuration files from the /etc/nginx/conf.d directory. 24 | # See http://nginx.org/en/docs/ngx_core_module.html#include 25 | # for more information. 26 | include /etc/nginx/conf.d/*.conf; 27 | 28 | server { 29 | listen 8080 default_server; 30 | listen [::]:8080 default_server; 31 | server_name _; 32 | root /static; 33 | 34 | # Load configuration files for the default server block. 35 | include /etc/nginx/default.d/*.conf; 36 | 37 | location /static/ { 38 | root /; 39 | } 40 | 41 | location / { 42 | proxy_pass_header Server; 43 | proxy_set_header Host $http_host; 44 | proxy_redirect off; 45 | proxy_set_header X-Real-IP $remote_addr; 46 | proxy_set_header X-Scheme $scheme; 47 | proxy_connect_timeout 10; 48 | proxy_read_timeout 10; 49 | proxy_pass http://django:8080/; 50 | } 51 | 52 | 53 | error_page 404 /404.html; 54 | location = /static/40x.html { 55 | } 56 | 57 | error_page 500 502 503 504 /50x.html; 58 | location = /static/50x.html { 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /django-admin/ansible/inventory: -------------------------------------------------------------------------------- 1 | localhost 2 | -------------------------------------------------------------------------------- /django-admin/ansible/main.yml: -------------------------------------------------------------------------------- 1 | - hosts: django,gulp,static 2 | tasks: 3 | - name: Install dumb init 4 | get_url: 5 | dest: /usr/bin/dumb-init 6 | url: https://github.com/Yelp/dumb-init/releases/download/v1.0.2/dumb-init_1.0.2_amd64 7 | mode: 0775 8 | validate_certs: no 9 | 10 | - hosts: django 11 | tasks: 12 | - name: Install python deps 13 | yum: 14 | name: '{{ item }}' 15 | state: latest 16 | update_cache: yes 17 | with_items: 18 | - postgresql-devel 19 | - python-devel 20 | - gcc 21 | - python-virtualenv 22 | 23 | - name: Make Django user 24 | user: 25 | name: django 26 | state: present 27 | createhome: yes 28 | home: /django 29 | group: root 30 | 31 | - name: Create /django with correct permissions 32 | file: 33 | name: /django 34 | state: directory 35 | owner: django 36 | group: root 37 | mode: 0777 38 | 39 | - name: Make virtualenv dir 40 | file: 41 | name: /venv 42 | state: directory 43 | owner: django 44 | group: root 45 | mode: g+rw 46 | 47 | - name: Make staticfiles dir 48 | file: 49 | name: /static 50 | state: directory 51 | owner: django 52 | group: root 53 | mode: g+rw 54 | 55 | - name: Setup virtualenv 56 | command: virtualenv . 57 | chdir: /venv 58 | creates: /venv/bin/python 59 | remote_user: django 60 | 61 | - name: Copy source 62 | copy: 63 | src: "{{ lookup('pipe','dirname `pwd`') }}/" 64 | dest: /django 65 | remote_user: django 66 | 67 | - name: Install requirements 68 | pip: 69 | executable: /venv/bin/pip 70 | requirements: /django/requirements.txt 71 | remote_user: django 72 | 73 | - name: Collect staticfiles 74 | command: /venv/bin/python manage.py collectstatic --noinput 75 | chdir: /django 76 | remote_user: django 77 | 78 | - name: Itemize Django static assets 79 | find: 80 | paths: /static 81 | recurse: yes 82 | register: django_assets 83 | 84 | - name: Fetch Django static assets 85 | fetch: 86 | src:"{{ item.path }}" 87 | dest: /tmp 88 | with_items: "{{ django_assets.files }}" 89 | 90 | - name: Wait for the database to come up... 91 | wait_for: 92 | host: postgresql 93 | port: 5432 94 | delay: 10 95 | 96 | - name: Apply database migrations 97 | command: /venv/bin/python manage.py migrate --noinput 98 | chdir: /django 99 | remote_user: django 100 | 101 | - hosts: gulp 102 | tasks: 103 | - name: Make node user 104 | user: 105 | name: node 106 | state: present 107 | createhome: yes 108 | home: /node 109 | 110 | - name: Make sure node owns its working dir 111 | file: 112 | name: /node 113 | state: directory 114 | owner: node 115 | recurse: true 116 | 117 | - name: Make node_modules directory 118 | file: 119 | name: /node_modules 120 | state: directory 121 | owner: node 122 | 123 | - name: Install nodejs 124 | yum: 125 | name: https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodejs-5.9.1-1nodesource.el7.centos.x86_64.rpm 126 | 127 | - name: Copy source 128 | copy: 129 | src: "{{ lookup('pipe','dirname `pwd`') }}/" 130 | dest: /node 131 | owner: node 132 | remote_user: node 133 | 134 | - name: Symlink package.json 135 | file: 136 | name: /package.json 137 | src: /node/package.json 138 | owner: node 139 | state: link 140 | 141 | - name: Install node deps 142 | command: npm install 143 | chdir: / 144 | remote_user: node 145 | 146 | - name: Build static assets 147 | command: /node_modules/.bin/gulp build 148 | chdir: /node 149 | environment: 150 | NODE_PATH: / 151 | remote_user: node 152 | 153 | - name: Itemize built assets 154 | find: 155 | paths: /node/dist 156 | recurse: yes 157 | register: gulp_assets 158 | 159 | - name: Fetch built assets 160 | fetch: src="{{ item.path }}" 161 | dest: /tmp 162 | with_items: "{{ gulp_assets.files }}" 163 | 164 | - hosts: static 165 | tasks: 166 | - name: Install EPEL 167 | yum: name: epel-release 168 | state: latest 169 | update_cache: yes 170 | 171 | - name: Install nginx 172 | yum: 173 | name: nginx 174 | state: latest 175 | 176 | - name: Put nginx config 177 | copy: 178 | src: nginx.conf 179 | dest: /etc/nginx/nginx.conf 180 | 181 | - name: Make static dir 182 | file: 183 | name: /static 184 | state: directory 185 | owner: nginx 186 | group: root 187 | mode: g+rw 188 | 189 | - name: Put Django assets 190 | copy: 191 | src: /tmp/django/static/ 192 | dest: /static/ 193 | owner: nginx 194 | 195 | - name: Put built assets 196 | copy: 197 | src: /tmp/gulp/node/dist 198 | dest: /static/ 199 | owner: nginx 200 | 201 | - name: Make pidfile dir accessible 202 | file: 203 | name: /run 204 | state: directory 205 | owner: nginx 206 | group: root 207 | mode: g+rw 208 | recurse: yes 209 | 210 | - name: Set permission on /var/lib/nginx 211 | file: 212 | name: /var/lib/nginx 213 | owner: nginx 214 | group: root 215 | mode: g+rw 216 | recurse: yes 217 | 218 | - name: Set permissions on /var/log/nginx 219 | file: 220 | name: /var/log/nginx 221 | state: directory 222 | owner: nginx 223 | group: root 224 | mode: g+rwx 225 | -------------------------------------------------------------------------------- /django-admin/ansible/requirements.txt: -------------------------------------------------------------------------------- 1 | # These are the python requirements for your Ansible Container builder. 2 | # You do not need to include Ansible itself in this file. 3 | docker-py==1.8.0 4 | 5 | -------------------------------------------------------------------------------- /django-admin/example/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-container-examples/7847c2cf7bfd3e12bac3aeb0446ddbac3744be8c/django-admin/example/__init__.py -------------------------------------------------------------------------------- /django-admin/example/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for example project. 3 | 4 | Generated by 'django-admin startproject' using Django 1.8.13. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.8/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/1.8/ref/settings/ 11 | """ 12 | 13 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 14 | import os 15 | 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'wj9rt420!n0(np*gi6#rpb7)y*b2qzp#@3l8p66na#q(4svs!e' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = ( 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'gunicorn', 41 | ) 42 | 43 | MIDDLEWARE_CLASSES = ( 44 | 'django.contrib.sessions.middleware.SessionMiddleware', 45 | 'django.middleware.common.CommonMiddleware', 46 | 'django.middleware.csrf.CsrfViewMiddleware', 47 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 48 | 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | 'django.middleware.security.SecurityMiddleware', 52 | ) 53 | 54 | ROOT_URLCONF = 'example.urls' 55 | 56 | TEMPLATES = [ 57 | { 58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 59 | 'DIRS': [], 60 | 'APP_DIRS': True, 61 | 'OPTIONS': { 62 | 'context_processors': [ 63 | 'django.template.context_processors.debug', 64 | 'django.template.context_processors.request', 65 | 'django.contrib.auth.context_processors.auth', 66 | 'django.contrib.messages.context_processors.messages', 67 | ], 68 | }, 69 | }, 70 | ] 71 | 72 | WSGI_APPLICATION = 'example.wsgi.application' 73 | 74 | 75 | # Database 76 | # https://docs.djangoproject.com/en/1.8/ref/settings/#databases 77 | 78 | DATABASES = { 79 | 'default': { 80 | 'ENGINE': 'django.db.backends.postgresql_psycopg2', 81 | 'NAME': 'example', 82 | 'HOST': 'postgresql', 83 | 'PORT': 5432, 84 | 'USER': 'example', 85 | 'PASSWORD': 'sesame' 86 | } 87 | } 88 | 89 | 90 | # Internationalization 91 | # https://docs.djangoproject.com/en/1.8/topics/i18n/ 92 | 93 | LANGUAGE_CODE = 'en-us' 94 | 95 | TIME_ZONE = 'UTC' 96 | 97 | USE_I18N = True 98 | 99 | USE_L10N = True 100 | 101 | USE_TZ = True 102 | 103 | 104 | # Static files (CSS, JavaScript, Images) 105 | # https://docs.djangoproject.com/en/1.8/howto/static-files/ 106 | 107 | STATIC_URL = '/static/' 108 | STATIC_ROOT = '/static/' 109 | -------------------------------------------------------------------------------- /django-admin/example/urls.py: -------------------------------------------------------------------------------- 1 | """example URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.8/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 14 | """ 15 | from django.conf.urls import include, url 16 | from django.contrib import admin 17 | 18 | urlpatterns = [ 19 | url(r'^admin/', include(admin.site.urls)), 20 | ] 21 | 22 | from django.conf import settings 23 | from django.conf.urls.static import static 24 | if settings.DEBUG: 25 | urlpatterns += static('/static/dist', document_root='/django/dist') 26 | 27 | -------------------------------------------------------------------------------- /django-admin/example/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for example project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | import socket 13 | import time 14 | 15 | postgres_is_alive = False 16 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 17 | 18 | while not postgres_is_alive: 19 | try: 20 | s.connect(('postgresql', 5432)) 21 | except socket.error: 22 | time.sleep(1) 23 | else: 24 | postgres_is_alive = True 25 | 26 | 27 | from django.core.wsgi import get_wsgi_application 28 | 29 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") 30 | 31 | application = get_wsgi_application() 32 | -------------------------------------------------------------------------------- /django-admin/gulpfile.js: -------------------------------------------------------------------------------- 1 | const prefixer = require('autoprefixer') 2 | const sync = require('browser-sync') 3 | const cssnano = require('cssnano') 4 | const del = require('del') 5 | const fs = require('fs') 6 | const gulp = require('gulp') 7 | const changed = require('gulp-changed') 8 | const include = require('gulp-file-include') 9 | const htmlmin = require('gulp-htmlmin') 10 | const imagemin = require('gulp-imagemin') 11 | const plumber = require('gulp-plumber') 12 | const postcss = require('gulp-postcss') 13 | const sass = require('gulp-sass') 14 | const maps = require('gulp-sourcemaps') 15 | const notifier = require('node-notifier') 16 | const rollup = require('rollup') 17 | const babel = require('rollup-plugin-babel') 18 | const commonjs = require('rollup-plugin-commonjs') 19 | const resolve = require('rollup-plugin-node-resolve') 20 | const uglify = require('rollup-plugin-uglify') 21 | 22 | // error handler 23 | 24 | const onError = function(error) { 25 | notifier.notify({ 26 | 'title': 'Error', 27 | 'message': 'Compilation failure.' 28 | }) 29 | 30 | console.log(error) 31 | this.emit('end') 32 | } 33 | 34 | // clean 35 | 36 | gulp.task('clean', function() {del('dist')}) 37 | 38 | // html 39 | 40 | gulp.task('html', ['images'], function() { 41 | return gulp.src('src/html/**/*.html') 42 | .pipe(plumber({ errorHandler: onError })) 43 | .pipe(include({ prefix: '@', basepath: 'dist/images/' })) 44 | .pipe(htmlmin({ collapseWhitespace: true, removeComments: true })) 45 | .pipe(gulp.dest('dist')) 46 | }) 47 | 48 | // sass 49 | 50 | const processors = [ 51 | prefixer({ browsers: 'last 2 versions' }), 52 | cssnano({ safe: true }) 53 | ] 54 | 55 | gulp.task('sass', function() { 56 | return gulp.src('src/sass/style.scss') 57 | .pipe(plumber({ errorHandler: onError })) 58 | .pipe(maps.init()) 59 | .pipe(sass()) 60 | .pipe(postcss(processors)) 61 | .pipe(maps.write('./maps', { addComment: false })) 62 | .pipe(gulp.dest('dist')) 63 | }) 64 | 65 | // js 66 | 67 | const read = { 68 | entry: 'src/js/main.js', 69 | sourceMap: true, 70 | plugins: [ 71 | resolve({ jsnext: true, main: true }), 72 | commonjs(), 73 | babel({ exclude: 'node_modules/**' }), 74 | uglify() 75 | ] 76 | } 77 | 78 | const write = { 79 | format: 'iife', 80 | sourceMap: true 81 | } 82 | 83 | gulp.task('js', function() { 84 | return rollup 85 | .rollup(read) 86 | .then(function(bundle) { 87 | // generate the bundle 88 | const files = bundle.generate(write) 89 | 90 | // write the files to dist 91 | fs.writeFileSync('dist/bundle.js', files.code) 92 | fs.writeFileSync('dist/maps/bundle.js.map', files.map.toString()) 93 | }) 94 | }) 95 | 96 | // images 97 | 98 | gulp.task('images', function() { 99 | return gulp.src('src/images/**/*.{gif,jpg,png,svg}') 100 | .pipe(plumber({ errorHandler: onError })) 101 | .pipe(changed('dist/images')) 102 | .pipe(imagemin({ progressive: true, interlaced: true })) 103 | .pipe(gulp.dest('dist/images')) 104 | }) 105 | 106 | // fonts, videos, favicon 107 | 108 | const others = [ 109 | { 110 | name: 'fonts', 111 | src: '/fonts/**/*.{woff,woff2}', 112 | dest: '/fonts' 113 | }, { 114 | name: 'videos', 115 | src: '/videos/**/*', 116 | dest: '/videos' 117 | }, { 118 | name: 'favicon', 119 | src: '/favicon.ico', 120 | dest: '' 121 | } 122 | ] 123 | 124 | others.forEach(function(object) { 125 | gulp.task(object.name, function() { 126 | return gulp.src('src' + object.src) 127 | .pipe(plumber({ errorHandler: onError })) 128 | .pipe(gulp.dest('dist' + object.dest)) 129 | }) 130 | }) 131 | 132 | // server 133 | 134 | const server = sync.create() 135 | const reload = sync.reload 136 | 137 | const sendMaps = function(req, res, next) { 138 | const filename = req.url.split('/').pop() 139 | const extension = filename.split('.').pop() 140 | 141 | if(extension === 'css' || extension === 'js') { 142 | res.setHeader('X-SourceMap', '/maps/' + filename + '.map') 143 | } 144 | 145 | return next() 146 | } 147 | 148 | const options = { 149 | notify: false, 150 | proxy: 'django:8080', 151 | watchOptions: { 152 | ignored: '*.map' 153 | }, 154 | port: 8080 155 | } 156 | 157 | gulp.task('server', function() {sync(options)}) 158 | 159 | // watch 160 | 161 | gulp.task('watch', function() { 162 | gulp.watch('src/html/**/*.html', ['html', reload]) 163 | gulp.watch('src/sass/**/*.scss', ['sass', reload]) 164 | gulp.watch('src/js/**/*.js', ['js', reload]) 165 | gulp.watch('src/images/**/*.{gif,jpg,png,svg}', ['images', reload]) 166 | }) 167 | 168 | // build and default tasks 169 | 170 | gulp.task('build', ['clean'], function() { 171 | try { 172 | // create dist directories 173 | fs.mkdirSync('dist') 174 | } catch (err) { 175 | // whatever. 176 | } 177 | 178 | try { 179 | fs.mkdirSync('dist/maps') 180 | } catch (err) { 181 | // whatever. 182 | } 183 | 184 | 185 | // run the tasks 186 | gulp.start('html', 'sass', 'js', 'images', 'fonts', 'videos', 'favicon') 187 | }) 188 | 189 | gulp.task('default', ['build', 'server', 'watch']) 190 | -------------------------------------------------------------------------------- /django-admin/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | import socket 5 | import time 6 | 7 | if __name__ == "__main__": 8 | 9 | postgres_is_alive = False 10 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 11 | 12 | while not postgres_is_alive: 13 | try: 14 | s.connect(('postgresql', 5432)) 15 | except socket.error: 16 | time.sleep(1) 17 | else: 18 | postgres_is_alive = True 19 | 20 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") 21 | 22 | from django.core.management import execute_from_command_line 23 | 24 | execute_from_command_line(sys.argv) 25 | -------------------------------------------------------------------------------- /django-admin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "1.0.0", 4 | "description": "", 5 | "author": "", 6 | "license": "", 7 | "files": [], 8 | "dependencies": { 9 | "autoprefixer": "*", 10 | "babel-preset-es2015-rollup": "*", 11 | "browser-sync": "*", 12 | "cssnano": "*", 13 | "del": "*", 14 | "gulp": "*", 15 | "gulp-changed": "*", 16 | "gulp-file-include": "*", 17 | "gulp-htmlmin": "*", 18 | "gulp-imagemin": "*", 19 | "gulp-plumber": "*", 20 | "gulp-postcss": "*", 21 | "gulp-sass": "*", 22 | "gulp-sourcemaps": "*", 23 | "node-notifier": "*", 24 | "rollup": "*", 25 | "rollup-plugin-babel": "*", 26 | "rollup-plugin-commonjs": "*", 27 | "rollup-plugin-node-resolve": "*", 28 | "rollup-plugin-uglify": "*" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /django-admin/requirements.txt: -------------------------------------------------------------------------------- 1 | Django>=1.8,<1.9 2 | psycopg2==2.6.1 3 | gunicorn==19.4.5 4 | -------------------------------------------------------------------------------- /django-admin/src/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /django-admin/src/js/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const main = (function() { }); 3 | 4 | document.addEventListener('DOMContentLoaded', main) 5 | -------------------------------------------------------------------------------- /django-admin/src/sass/_base.scss: -------------------------------------------------------------------------------- 1 | // FONT 2 | 3 | html { 4 | // 1rem = 10px 5 | font-size: 10px; 6 | } 7 | 8 | body { 9 | // font-family: ; 10 | // font-weight: ; 11 | // font-size: ; 12 | line-height: 1.3; 13 | } 14 | 15 | // LAYOUT 16 | 17 | .container { 18 | width: 100% - 2 * $site-gutter; 19 | max-width: $site-width; 20 | margin-right: auto; 21 | margin-left: auto; 22 | } 23 | -------------------------------------------------------------------------------- /django-admin/src/sass/_mixins.scss: -------------------------------------------------------------------------------- 1 | @mixin clearfix { 2 | &::before, 3 | &::after { 4 | content: ""; 5 | display: table; 6 | clear: both; 7 | } 8 | } 9 | 10 | @mixin flex($grow: 0, $shrink: 1, $basis: auto) { 11 | flex-grow: $grow; 12 | flex-shrink: $shrink; 13 | flex-basis: $basis; 14 | } 15 | 16 | @mixin font-face($font-name, $file-name) { 17 | @font-face { 18 | font-family: $font-name; 19 | src: url("fonts/#{$file-name}.woff2") format("woff2"), 20 | url("fonts/#{$file-name}.woff") format("woff"); 21 | } 22 | } 23 | 24 | @mixin hide-text { 25 | overflow: hidden; 26 | text-indent: 101%; 27 | white-space: nowrap; 28 | } 29 | 30 | @mixin min($width) { 31 | @media screen and (min-width: $width) { 32 | @content; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /django-admin/src/sass/_reset.scss: -------------------------------------------------------------------------------- 1 | html, body, div, 2 | header, footer, main, section, nav, 3 | h1, h2, h3, h4, h5, h6, img, svg, 4 | p, a, hr, span, ol, ul, li, 5 | form, input, label { 6 | margin: 0; 7 | padding: 0; 8 | border: none; 9 | font-size: 100%; 10 | font: inherit; 11 | vertical-align: baseline; 12 | } 13 | 14 | *, 15 | *::before, 16 | *::after { 17 | box-sizing: border-box; 18 | } 19 | 20 | img { 21 | max-width: 100%; 22 | } 23 | 24 | svg:not(:root) { 25 | overflow: hidden; 26 | } 27 | 28 | input { 29 | border-radius: 0; 30 | } 31 | 32 | ::placeholder { 33 | opacity: 1; 34 | } 35 | 36 | a { 37 | background-color: transparent; 38 | 39 | text-decoration: none; 40 | color: inherit; 41 | 42 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 43 | outline: none; 44 | } 45 | -------------------------------------------------------------------------------- /django-admin/src/sass/_vars.scss: -------------------------------------------------------------------------------- 1 | // SITE 2 | 3 | $site-width: 960px; 4 | $site-gutter: 7.5%; 5 | 6 | // BREAKPOINTS 7 | 8 | $tablet: 768px; 9 | $desktop: 1024px; 10 | 11 | // FONTS 12 | 13 | // $sans: ; 14 | // $serif: ; 15 | 16 | // COLORS 17 | -------------------------------------------------------------------------------- /django-admin/src/sass/_z-index.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-container-examples/7847c2cf7bfd3e12bac3aeb0446ddbac3744be8c/django-admin/src/sass/_z-index.scss -------------------------------------------------------------------------------- /django-admin/src/sass/style.scss: -------------------------------------------------------------------------------- 1 | @import "mixins"; 2 | @import "reset"; 3 | 4 | // PARTIALS 5 | 6 | @import "vars"; 7 | @import "base"; 8 | @import "z-index"; 9 | 10 | // COMPONENTS 11 | 12 | // SECTIONS 13 | -------------------------------------------------------------------------------- /django-cms/ansible/container.yml: -------------------------------------------------------------------------------- 1 | version: "1" 2 | services: 3 | django: 4 | image: python:2.7 5 | postgres: 6 | image: openshift/postgresql-92-centos7 7 | expose: 8 | - 5432 9 | volumes: 10 | - '/var/lib/pgsql/data' 11 | environment: 12 | POSTGRESQL_USER: 'example' 13 | POSTGRESQL_PASSWORD: 'sesame' 14 | POSTGRESQL_DATABASE: 'example' 15 | 16 | registries: {} 17 | -------------------------------------------------------------------------------- /django-cms/ansible/main.yml: -------------------------------------------------------------------------------- 1 | # This should be your Ansible playbooks to provision your containers. 2 | # An inventory will be automatically created using the names of the services 3 | # from your container.yml file. 4 | # Add any roles or other modules you'll need to this directory too. 5 | # For many examples of roles, check out Ansible Galaxy: https://galaxy.ansible.com/ 6 | # 7 | # - hosts: all 8 | # gather_facts: false 9 | # tasks: 10 | # - raw: which python || apt-get update 11 | # - raw: (which python && which aptitude) || apt-get install -y python python-apt aptitude 12 | # - hosts: web 13 | # tasks: 14 | # - name: Upgrade APT 15 | # apt: upgrade=yes 16 | # - name: Install ca-certificates 17 | # apt: name=ca-certificates state=latest 18 | # - name: Install dumb-init 19 | # apt: deb=https://github.com/Yelp/dumb-init/releases/download/v1.0.2/dumb-init_1.0.2_amd64.deb 20 | # - name: Install Apache 21 | # apt: name=apache2 state=latest 22 | -------------------------------------------------------------------------------- /django-cms/ansible/requirements.txt: -------------------------------------------------------------------------------- 1 | # These are the python requirements for your Ansible Container builder. 2 | # You do not need to include Ansible itself in this file. 3 | docker-py==1.8.0 -------------------------------------------------------------------------------- /django-cms/requirements.txt: -------------------------------------------------------------------------------- 1 | # Bare minimum 2 | django-cms>=3.0 3 | 4 | # These dependencies are brought in by django CMS, but if you want to 5 | # lock-in their version, specify them 6 | Django>=1.8 7 | 8 | django-treebeard==3.0 9 | django-sekizai==0.8.2 10 | django-classy-tags==0.6.2 11 | djangocms-admin-style==0.2.2 12 | html5lib==0.999 13 | six==1.3.0 14 | 15 | # Optional, recommended packages 16 | Pillow>=2 17 | django-filer==0.9.9 18 | cmsplugin-filer==0.10.1 19 | django-reversion==1.8.5 20 | 21 | # db driver 22 | psycopg2 23 | -------------------------------------------------------------------------------- /elk-stack/README.md: -------------------------------------------------------------------------------- 1 | # elk-stack 2 | 3 | This example was taken from the [Elasticsearch, Logstash, Kibana (ELK) Docker image documentation](https://elk-docker.readthedocs.io/). 4 | 5 | The intention is to present a how-to for using [Jinja](http://jinja.pocoo.org) templating within *container.yml*. Take a look at the 6 | [Quck Tour](http://docs.ansible.com/ansible-container/tour.html), if you're unfamiliar with *container.yml* and its role in an 7 | Ansible Container project. 8 | 9 | Here is the *container.yml* included in this project: 10 | 11 | ``` 12 | version: "1" 13 | defaults: 14 | beats_access_port: 9200 15 | forwarder_access_port: 5000 16 | kibana_access_port: 5601 17 | logstash_access_port: 5044 18 | nginx_access_port: 8080 19 | services: 20 | elk: 21 | image: sebp/elk 22 | ports: 23 | - "{{ kibana_access_port }}:5601" 24 | - "{{ beats_access_port }}:9200" 25 | - "{{ logstash_access_port }}:5044" 26 | - "{{ forwarder_access_port }}:5000" 27 | {% if logstash_data %} 28 | volumes: 29 | - {{ logstash_data }}:/var/lib/elasticsearch 30 | {% endif %} 31 | nginx: 32 | image: nginx 33 | links: 34 | - elk:elk 35 | ports: 36 | - "{{ nginx_access_port }}:8000" 37 | command: /usr/local/bin/start.sh 38 | user: nginx 39 | {% if nginx_log_data %} 40 | volumes: 41 | - {{ nginx_log_data }}:/var/log/nginx 42 | {% endif %} 43 | registries: {} 44 | ``` 45 | 46 | When Ansible Container reads *container.yml* it passes it through Jinja template rendering, and then uses the result. For template rendering to work Jinja needs to know the values of the variables 47 | referenced in each expression. If you are unfamiliar with Jinja and template expressions, please review [the Jinja docs](http://jinja.pocoo.org/docs/dev/). 48 | 49 | Variable definitions can be passed to Ansible Container using the following methods: 50 | 51 | - Use the *--var-file* option, passing the path of a YAML or JSON file 52 | - Provide a *defaults* top-level section in the *container.yml* file 53 | - Define *AC_* environment variables that correspond to the Jinja variables 54 | 55 | Let's take a look at the *container.yml* starting with the *elk* services. It uses an ELK stack image, *sebp/elk*, pulled from Docker Hub as its base image, and it exposes the standard ELK ports. 56 | Notice in each of the defined port mappings the host portion is replaced with a Jinja expression, giving us the following expressions: `{{ kibana_access_port }}`, 57 | `{{ beats_access_port }}`, `{{ logstash_access_port }}`, and `{{ forwarder_access_port }}`. These expressions represent variable substitutions in Jinja. For example, if *kibana_access_port* 58 | is defined as 3000, then 3000 will be substituted for `{{ kibana_access_port }}` during template rendering. 59 | 60 | Also, notice the *volumes* directive for the *elk* service. It's wrapped in a Jinja `{% if %} ... {% endif %}` control block. As you might guess just from reading it, if the 61 | *logstash_data* variable is defined, then a volume gets defined, and it binds the value of *logstash_data* to */var/lib/elasticsearch*. Conversly, if *logstash_data* is not defined, the volume 62 | directive is excluded altogether form the final *container.yml*. 63 | 64 | The same thing has been done in the *nginx* service where variable substitution is used in the port mapping, and there is a conditionally defined volume for */var/log/nginx*. 65 | 66 | Notice toward the top of the file there is a *defaults* section. It provides default vaules for all of the variables used in the port definitions. This insures the port mappings will always work. 67 | If no other definitions are provided using either *AC_* environment variables or a variable file passed in using the *--var-file* option, then the *default* values will be used. 68 | 69 | Variable precedence is given in the following order: 70 | 71 | - defaults 72 | - variable file 73 | - environment variables 74 | 75 | The default definition gets the lowest precedence, and environment variables receive the highest. This means that if a default value of *8080* is defined for *nginx_access_port*, as it is in the above 76 | example, and *AC_NGINX_ACCESS_PORT=9000* is also defined in the environment, the environment variable wins, and the value *9000* is used. 77 | 78 | Since the above file provides a *default* section with port definitions, and the volume definitions are conditional, the standard *build* command with no options and no additional variable 79 | definitions works: 80 | 81 | ``` 82 | $ ansible-container build 83 | ``` 84 | 85 | At runtime different values can be substituted using environment variables or a variable file. For demo purposes, there is a *devel.yml* file included in the *ansible* directory providing some possible override 86 | values. The application can be started with these settings using the following command: 87 | 88 | ``` 89 | $ ansible-container --var-file devel.yml run 90 | ``` 91 | 92 | Using Jinja templating in *container.yml* provides some nice flexibility by allowing us to separate the configuration directives from the data. This makes it possible to substitute different configuration data 93 | depending on the environment. It also gives us access to control structures like the *{% if %}* and *{% for %}* expressions, as demonstrated above, and it even makes it possible 94 | to share variable definitions with Ansible Playbook during the *build* process. For example, we could pass the variable file into the playbook run by doing the following: 95 | 96 | ``` 97 | $ ansible-container --var-file devel.yml build -- -e"@/ansible-container/ansible/devel.yml" 98 | ``` 99 | 100 | Try it out. And please, let us know what you think. We would love to hear how you put this feature to use in your environment. For more information on Jinja templating in *container.yml* see 101 | [the templating guide on our doc site](http://docs.ansible.com/ansible-container/container_yml/template.html). 102 | 103 | For help getting started or questions, you can find us in the following places: 104 | 105 | * [Join the mailing list](https://groups.google.com/forum/#!forum/ansible-container) 106 | * [Open an issue](https://github.com/ansible/ansible-container/issues) 107 | * Join the #ansible-container channel on irc.freenode.net. 108 | 109 | -------------------------------------------------------------------------------- /elk-stack/ansible/container.yml: -------------------------------------------------------------------------------- 1 | version: "1" 2 | defaults: 3 | beats_access_port: 9200 4 | forwarder_access_port: 5000 5 | kibana_access_port: 5601 6 | logstash_access_port: 5044 7 | nginx_access_port: 8080 8 | services: 9 | elk: 10 | image: sebp/elk 11 | ports: 12 | - "{{ kibana_access_port }}:5601" 13 | - "{{ beats_access_port }}:9200" 14 | - "{{ logstash_access_port }}:5044" 15 | - "{{ forwarder_access_port }}:5000" 16 | {% if logstash_data %} 17 | volumes: 18 | - {{ logstash_data }}:/var/lib/elasticsearch 19 | {% endif %} 20 | nginx: 21 | image: nginx 22 | links: 23 | - elk:elk 24 | ports: 25 | - "{{ nginx_access_port }}:8000" 26 | command: /usr/local/bin/start.sh 27 | user: nginx 28 | {% if nginx_log_data %} 29 | volumes: 30 | - {{ nginx_log_data }}:/var/log/nginx 31 | {% endif %} 32 | registries: {} 33 | -------------------------------------------------------------------------------- /elk-stack/ansible/devel.yml: -------------------------------------------------------------------------------- 1 | 2 | --- 3 | nginx_log_data: ~/data/nginx 4 | kibana_access_port: 8888 5 | nginx_access_port: 9000 6 | -------------------------------------------------------------------------------- /elk-stack/ansible/main.yml: -------------------------------------------------------------------------------- 1 | - hosts: nginx 2 | gather_facts: no 3 | tasks: 4 | - name: Update all packages 5 | raw: apt-get update 6 | 7 | - name: Install python and curl 8 | raw: apt-get install -y python curl 9 | 10 | - name: Download filebeat 11 | get_url: url=https://download.elastic.co/beats/filebeat/filebeat_1.0.1_amd64.deb dest=/filebeat_1.0.1_amd64.deb mode=0664 12 | 13 | - name: Install filebeat 14 | apt: deb=/filebeat_1.0.1_amd64.deb 15 | 16 | - name: Remove package file 17 | file: path=/filebeat_1.0.1_amd64.deb state=absent 18 | 19 | - name: Remove nginx access.log 20 | file: path=/var/log/nginx/access.log state=absent 21 | 22 | - name: Remove nginx error.log 23 | file: path=/var/log/nginx/error.log state=absent 24 | 25 | - name: Add root group and set uid for nginx 26 | user: name=nginx groups=nginx,root uid=1000 27 | 28 | - name: Set permissions on /var/log/nginx 29 | file: path=/var/log/nginx owner=root group=root mode=0775 30 | 31 | - name: Set permissions on /var/cache/nginx 32 | file: path=/var/cache/nginx owner=root group=root mode=0775 33 | 34 | - name: Set permission on /run 35 | file: path=/run owner=root group=root mode=0775 36 | 37 | - name: Copy default.conf 38 | copy: src=../default.conf dest=/etc/nginx/conf.d/default.conf owner=root group=root mode=0664 39 | 40 | - name: Copy filebeat config file 41 | copy: src=../filebeat.yml dest=/etc/filebeat/filebeat.yml owner=root group=root mode=0660 42 | 43 | - name: Create certs dir 44 | file: path=/etc/pki/tls/certs state=directory recurse=yes owner=root group=root mode=0775 45 | 46 | - name: Copy logstash cert file 47 | copy: src=../logstash-beats.crt dest=/etc/pki/tls/certs/logstash-beats.crt owner=root group=root mode=0660 48 | 49 | - name: Copy html dir 50 | copy: src=../html dest=/usr/share/nginx/html owner=nginx group=nginx mode=0664 51 | 52 | - name: Copy start.sh script 53 | copy: src=../start.sh dest=/usr/local/bin/start.sh owner=root group=root mode=0775 54 | 55 | 56 | -------------------------------------------------------------------------------- /elk-stack/ansible/requirements.txt: -------------------------------------------------------------------------------- 1 | # These are the python requirements for your Ansible Container builder. 2 | # You do not need to include Ansible itself in this file. 3 | docker-py==1.8.0 -------------------------------------------------------------------------------- /elk-stack/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 8000; 3 | server_name localhost; 4 | 5 | access_log /var/log/nginx/access.log main; 6 | 7 | location / { 8 | root /usr/share/nginx/html; 9 | index index.html index.htm; 10 | } 11 | 12 | error_page 500 502 503 504 /50x.html; 13 | location = /50x.html { 14 | root /usr/share/nginx/html; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /elk-stack/filebeat.yml: -------------------------------------------------------------------------------- 1 | output: 2 | logstash: 3 | enabled: true 4 | hosts: 5 | - elk:5044 6 | timeout: 15 7 | tls: 8 | certificate_authorities: 9 | - /etc/pki/tls/certs/logstash-beats.crt 10 | 11 | filebeat: 12 | prospectors: 13 | - 14 | paths: 15 | - /var/log/syslog 16 | - /var/log/auth.log 17 | document_type: syslog 18 | - 19 | paths: 20 | - "/var/log/nginx/*.log" 21 | document_type: nginx-access -------------------------------------------------------------------------------- /elk-stack/html/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-container-examples/7847c2cf7bfd3e12bac3aeb0446ddbac3744be8c/elk-stack/html/favicon.ico -------------------------------------------------------------------------------- /elk-stack/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Filebeats + nginx example 7 | 8 | 9 |

Hello world!

10 | 11 | -------------------------------------------------------------------------------- /elk-stack/logstash-beats.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC6zCCAdOgAwIBAgIJANPZwuf+5wTLMA0GCSqGSIb3DQEBCwUAMAwxCjAIBgNV 3 | BAMMASowHhcNMTUxMjI4MTA0NTMyWhcNMjUxMjI1MTA0NTMyWjAMMQowCAYDVQQD 4 | DAEqMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp+jHFvhyYKiPXc7k 5 | 0c33f2QV+1hHNyW/uwcJbp5jG82cuQ41v70Z1+b2veBW4sUlDY3yAIEOPSUD8ASt 6 | 9m72CAo4xlwYKDvm/Sa3KJtDk0NrQiz6PPyBUFsY+Bj3xn6Nz1RW5YaP+Q1Hjnks 7 | PEyQu4vLgfTSGYBHLD4gvs8wDWY7aaKf8DfuP7Ov74Qlj2GOxnmiDEF4tirlko0r 8 | qQcvBgujCqA7rNoG+QDmkn3VrxtX8mKF72bxQ7USCyoxD4cWV2mU2HD2Maed3KHj 9 | KAvDAzSyBMjI+qi9IlPN5MR7rVqUV0VlSKXBVPct6NG7x4WRwnoKjTXnr3CRADD0 10 | 4uvbQQIDAQABo1AwTjAdBgNVHQ4EFgQUVFurgDwdcgnCYxszc0dWMWhB3DswHwYD 11 | VR0jBBgwFoAUVFurgDwdcgnCYxszc0dWMWhB3DswDAYDVR0TBAUwAwEB/zANBgkq 12 | hkiG9w0BAQsFAAOCAQEAaLSytepMb5LXzOPr9OiuZjTk21a2C84k96f4uqGqKV/s 13 | okTTKD0NdeY/IUIINMq4/ERiqn6YDgPgHIYvQheWqnJ8ir69ODcYCpsMXIPau1ow 14 | T8c108BEHqBMEjkOQ5LrEjyvLa/29qJ5JsSSiULHvS917nVgY6xhcnRZ0AhuJkiI 15 | ARKXwpO5tqJi6BtgzX/3VDSOgVZbvX1uX51Fe9gWwPDgipnYaE/t9TGzJEhKwSah 16 | kNr+7RM+Glsv9rx1KcWcx4xxY3basG3/KwvsGAFPvk5tXbZ780VuNFTTZw7q3p8O 17 | Gk1zQUBOie0naS0afype5qFMPp586SF/2xAeb68gLg== 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /elk-stack/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curl -XPUT 'http://elk:9200/_template/filebeat?pretty' -d@/etc/filebeat/filebeat.template.json 4 | /etc/init.d/filebeat start 5 | nginx 6 | tail -f /var/log/nginx/access.log -f /var/log/nginx/error.log 7 | -------------------------------------------------------------------------------- /flask-helloworld/README.md: -------------------------------------------------------------------------------- 1 | # Flask HelloWorld 2 | 3 | Here is Flask HelloWorld example with [Ansible Container](https://github.com/ansible/ansible-container). 4 | 5 | The config creates a CentOS 7 Container. 6 | 7 | This GIST assumes you have read the [Ansible Container docs](https://docs.ansible.com/ansible-container), and have a sucessful install of Ansible Container. 8 | 9 | ## Install 10 | 1. Clone the Repo `git clone https://github.com/ansible/ansible-container-examples`. 11 | 2. Change Directory `cd ansible-container-examples/flask-helloworld/`. 12 | 3. Run `ansible-container build`. 13 | 4. Run `ansible-container run`. 14 | 15 | You will find the content of `flask-helloworld/templates/index.html` on `http://localhost:5000`. 16 | -------------------------------------------------------------------------------- /flask-helloworld/ansible/container.yml: -------------------------------------------------------------------------------- 1 | version: "1" 2 | services: 3 | web: 4 | image: centos:7 5 | ports: 6 | - "5000:5000" 7 | 8 | command: ['/usr/bin/dumb-init', 'python', '/flaskapp/hello_world.py'] 9 | registries: {} 10 | -------------------------------------------------------------------------------- /flask-helloworld/ansible/flask-helloworld/hello_world.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template 2 | 3 | APP = Flask(__name__) 4 | 5 | @APP.route('/') 6 | def index(): 7 | return render_template('index.html') 8 | 9 | 10 | if __name__ == '__main__': 11 | APP.run(debug=True, host='0.0.0.0') 12 | -------------------------------------------------------------------------------- /flask-helloworld/ansible/flask-helloworld/static/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #F8A434; 3 | font-family: 'Lato', sans-serif; 4 | color: #FDFCFB; 5 | text-align: center; 6 | position: relative; 7 | bottom: 35px; 8 | top: 65px; 9 | } 10 | .description { 11 | position: relative; 12 | top: 55px; 13 | font-size: 50px; 14 | letter-spacing: 1.5px; 15 | line-height: 1.3em; 16 | margin: -2px 0 45px; 17 | } 18 | -------------------------------------------------------------------------------- /flask-helloworld/ansible/flask-helloworld/templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends "master.html" %} 2 | 3 | {% block title %}Welcome to Flask App{% endblock %} 4 | 5 | {% block content %} 6 | 7 |
8 |

Hello World

9 |
10 | 11 | {% endblock %} 12 | -------------------------------------------------------------------------------- /flask-helloworld/ansible/flask-helloworld/templates/master.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {% block head %} 5 | {% block title %}{% endblock %} 6 | {% endblock %} 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | {% block content %} 17 | {% endblock %} 18 |
19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /flask-helloworld/ansible/main.yml: -------------------------------------------------------------------------------- 1 | - hosts: web 2 | tasks: 3 | - name: Install dumb init 4 | get_url: 5 | dest: /usr/bin/dumb-init 6 | url: https://github.com/Yelp/dumb-init/releases/download/v1.0.2/dumb-init_1.0.2_amd64 7 | mode: 0775 8 | validate_certs: no 9 | 10 | - name: Install EPEL 11 | yum: name=epel-release state=latest 12 | - name: Install Flask 13 | yum: name=python-flask state=latest 14 | - name: Install Jinja2 15 | yum: name=python-jinja2 state=latest 16 | - name: Create Flask User 17 | user: name=flaskapp state=present createhome=yes home=/flaskapp group=root 18 | - name: Create /flaskapp with correct permissions 19 | file: name=/flaskapp state=directory owner=flaskapp group=root mode=0777 20 | remote_user: flaskapp 21 | - name: Copy The Application 22 | copy: 23 | src: flask-helloworld/ 24 | dest: /flaskapp/ 25 | owner: flaskapp 26 | mode: 0777 27 | -------------------------------------------------------------------------------- /flask-helloworld/ansible/requirements.txt: -------------------------------------------------------------------------------- 1 | # These are the python requirements for your Ansible Container builder. 2 | # You do not need to include Ansible itself in this file. 3 | docker-py==1.8.0 -------------------------------------------------------------------------------- /helloworld-nginx/README.md: -------------------------------------------------------------------------------- 1 | # Ansible-container HelloWorld 2 | 3 | Here is a quick [Ansible Container](https://github.com/ansible/ansible-container) HelloWorld deployment running Nginx. 4 | 5 | The config creates a single Centos 7 container running nginx exposed on port 8080. 6 | 7 | This GIST assumes you have read the [Ansible Container docs](https://docs.ansible.com/ansible-container), and have a sucessful install of Ansible Container. 8 | 9 | ## Install 10 | 1. Run `ansible-container init` 11 | 2. In the `ansible` directory populate `container.yml` and `main.yml` with the content below 12 | 3. In the `ansible` directory create a directory called `files` 13 | 4. In the `files` directory create a file called `index.html` and copy the content below, or use your own custom HTML 14 | 5. Run `ansible-container build` 15 | 6. Run `ansible-container run` 16 | 17 | Open `http://localhost:8080` in your browser, and see the content of `files/index.html`. 18 | 19 | If you're running Docker Machine, in your terminal session run `open http://$(docker-machine ip default):8080`, replacing `default` with your machine name. 20 | -------------------------------------------------------------------------------- /helloworld-nginx/container.yml: -------------------------------------------------------------------------------- 1 | version: "1" 2 | services: 3 | web: 4 | image: centos:7 5 | ports: 6 | - "8080:80" 7 | 8 | command: ['/usr/bin/dumb-init', 'nginx', '-c', '/etc/nginx/nginx.conf', "-g", "daemon off;"] 9 | 10 | 11 | registries: {} 12 | -------------------------------------------------------------------------------- /helloworld-nginx/files/index.html: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /helloworld-nginx/main.yml: -------------------------------------------------------------------------------- 1 | - hosts: web 2 | tasks: 3 | - name: Install dumb init 4 | get_url: 5 | dest: /usr/bin/dumb-init 6 | url: https://github.com/Yelp/dumb-init/releases/download/v1.0.2/dumb-init_1.0.2_amd64 7 | mode: 0775 8 | validate_certs: no 9 | 10 | - name: Install EPEL 11 | yum: 12 | name: epel-release 13 | state: latest 14 | 15 | - name: Install Nginx 16 | yum: 17 | name: nginx 18 | state: latest 19 | 20 | - name: Copy index update 21 | copy: 22 | src: files/index.html 23 | dest: /usr/share/nginx/html/index.html 24 | owner: root 25 | group: root 26 | mode: 0777 27 | -------------------------------------------------------------------------------- /helloworld-nginx/requirements.txt: -------------------------------------------------------------------------------- 1 | # These are the python requirements for your Ansible Container builder. 2 | # You do not need to include Ansible itself in this file. 3 | docker-py==1.8.0 -------------------------------------------------------------------------------- /images/django-admin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-container-examples/7847c2cf7bfd3e12bac3aeb0446ddbac3744be8c/images/django-admin.png -------------------------------------------------------------------------------- /images/image_streams.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansible/ansible-container-examples/7847c2cf7bfd3e12bac3aeb0446ddbac3744be8c/images/image_streams.png -------------------------------------------------------------------------------- /sshd/README.md: -------------------------------------------------------------------------------- 1 | # sshd 2 | 3 | Should you do this? Not really. Containers are meant to be immutable, so there should be no reason to SSH into a container. If you need to 4 | poke around in a container for debugging purposes, the *right* way is to `docker exec -i -t /bin/bash`. 5 | 6 | But nevertheless, this question comes up all the time, "How can I run sshd in my container?" In fact, a developer recently opened an 7 | issue at [Ansible Container](https://github.com/ansible/ansible-container) because he was having trouble figuring out the playbook to make this work. 8 | So, here's the answer. 9 | 10 | Keep in mind that [Ansible Container](https://github.com/ansible/ansible-container) does NOT use SSH when performing `ansible-container build`. It 11 | uses `docker exec`. Once playbook execution completes it performs a `docker commit` to create an image from the changed container. 12 | 13 | Enjoy! And stop changing things inside immutable containers! 14 | 15 | ## Running the example 16 | 17 | First, clone the Ansible Container Examples repo: 18 | 19 | ``` 20 | $ cd projects 21 | $ git clone https://github.com/ansible/ansible-container-examples.git 22 | ``` 23 | 24 | Next we'll run the *build* command to create a container image that's capable of running *sshd*. The *build* command reads the *container.yml* and 25 | determine which services to start and which base images to use. In this case there is only one service defined, which we named *ssh*, and the base image 26 | is *ubuntu:14.04*. The *build* process will create and start a container using the *ubuntu14:04* image, which it pulls from Docker Hub. The name of 27 | this container will be *ansible_sshd_1*. It also starts an Ansible Build container where it will run the playbook, *main.yml*. Playbook tasks will be 28 | executed on *ansible_sshd_1*, and communication between the two containers takes place using Ansible's Docker connection plugin. 29 | 30 | Run the following commands to start the *build* process: 31 | 32 | ``` 33 | $ cd ansible-container-examples/sshd 34 | $ ansible-container build 35 | ``` 36 | 37 | As the *build* process runs, output from the playbook's execution will display, marking the completion of each task and play. Once the playbook completes 38 | the process performs a commit, taking a snapshot of the container, and creating a new image. 39 | 40 | Next, we'll run a container using the new image. The following will create and start a container in detached mode with the sshd process running inside: 41 | 42 | ``` 43 | $ ansible-container run -d 44 | ``` 45 | 46 | The sshd process inside the container is listening on port 22. Use `docker ps` to discover which host port is mappped to the container's port 22: 47 | 48 | ``` 49 | $ docker ps 50 | 51 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 52 | d3a8cd2cd5e6 sshd-ssh:latest "/usr/sbin/sshd -D" 6 seconds ago Up 5 seconds 0.0.0.0:32786->22/tcp ansible_ssh_1 53 | ``` 54 | 55 | In the above example host port 32786 was mapped to container port 22. This is configurable in *container.yml*. If you want to map 56 | container port 22 to a specific host port, modify the *ports* option. 57 | 58 | We're ready to SSH into the container. If you're using Docker Machine, you will first need the IP address of the host VM. The following command 59 | will provide the IP. Replace *default* with the name of your VM: 60 | 61 | ``` 62 | $ docker-machine ip default 63 | ``` 64 | 65 | Either with the IP of the Docker Machine or localhost, if you're not running Docker Machine, SSH to the container with the following: 66 | 67 | ``` 68 | $ ssh root@192.168.99.100 -p 32786 69 | The authenticity of host '[192.168.99.100]:32786 ([192.168.99.100]:32786)' can't be established. 70 | ECDSA key fingerprint is SHA256:NgVOKNssA0OeTUFiFJA1OONpLQN7ezfv5FJmkKiR4eA. 71 | Are you sure you want to continue connecting (yes/no)? yes 72 | Warning: Permanently added '[192.168.99.100]:32786' (ECDSA) to the list of known hosts. 73 | root@192.168.99.100's password: 74 | ``` 75 | 76 | The password is *password*. This gets set on line 4 in main.yml. 77 | 78 | **NOTE** Obviously keeping clear text passwords in an unencrypted playbook is not safe. For ways to encrypt files and pass them into your playbook 79 | or encrypt the entire playbook see the [ansible-vault docs](http://docs.ansible.com/ansible/playbooks_vault.html). 80 | 81 | For more information on [Ansible Container](https://github.com/ansible/ansible-container), please visit our [docs site](https://docs.ansible.com/ansible-container). If you 82 | have question or need help getting started, please reach out to us using one of the following: 83 | 84 | * [Join the mailing list](https://groups.google.com/forum/#!forum/ansible-container) 85 | * [Open an issue](https://github.com/ansible/ansible-container/issues) 86 | * Join the #ansible-container channel on irc.freenode.net. 87 | 88 | 89 | -------------------------------------------------------------------------------- /sshd/ansible/container.yml: -------------------------------------------------------------------------------- 1 | version: "1" 2 | services: 3 | ssh: 4 | image: ubuntu:14.04 5 | ports: 6 | - 22 7 | environment: 8 | - NOTVISIBLE="in users profile" 9 | command: ["/usr/sbin/sshd", "-D"] 10 | 11 | registries: {} 12 | -------------------------------------------------------------------------------- /sshd/ansible/main.yml: -------------------------------------------------------------------------------- 1 | - hosts: ssh 2 | gather_facts: no 3 | vars: 4 | mypassword: password 5 | tasks: 6 | - name: Update all packages 7 | raw: apt-get update 8 | - name: Install python 9 | raw: apt-get install -y python python-apt 10 | - name: Install openssh-server 11 | apt: name=openssh-server state=present 12 | - name: Create /var/run/sshd 13 | file: path=/var/run/sshd state=directory owner=root group=root mode=0755 14 | - name: Update sshd_config 15 | replace: dest=/etc/ssh/sshd_config regexp='^PermitRootLogin without-password' replace='PermitRootLogin yes' 16 | - name: Update pam settings 17 | replace: dest=/etc/pam.d/sshd regexp='session\s*required\s*pam_loginuid.so' replace='session optional pam_loginuid.so' 18 | - name: Update /etc/profile 19 | lineinfile: dest=/etc/profile line='VISIBLE=now' 20 | - name: Get encrypted password 21 | shell: python -c 'import crypt; print crypt.crypt("{{ mypassword }}", "$1$SomeSalt$")' 22 | register: output 23 | - name: Set root password 24 | user: name=root password="{{ output.stdout }}" update_password=always 25 | -------------------------------------------------------------------------------- /sshd/ansible/requirements.txt: -------------------------------------------------------------------------------- 1 | # These are the python requirements for your Ansible Container builder. 2 | # You do not need to include Ansible itself in this file. 3 | docker-py==1.8.0 -------------------------------------------------------------------------------- /wordpress/README.md: -------------------------------------------------------------------------------- 1 | # Wordpress 2 | 3 | - A Wordpress-Mariadb example built from scratch on Centos 7. 4 | - Creates a Mariadb container and a Wordpress container. 5 | - Demonstrates deployment to Kubernetes and OpenShift. 6 | 7 | main.yml: 8 | 9 | ``` 10 | - hosts: db 11 | vars: 12 | - wp_mysql_db: wordpress 13 | - wp_mysql_user: wordpress 14 | - wp_mysql_password: password 15 | ``` 16 | ``` 17 | - hosts: wordpress 18 | vars: 19 | - wp_mysql_db: wordpress 20 | - wp_mysql_user: wordpress 21 | - wp_mysql_password: password 22 | 23 | ``` 24 | We can change the user and database by editing the main.yml file. 25 | 26 | main.yml 27 | ``` 28 | - hosts: db 29 | vars: 30 | - wp_mysql_db: < database name > 31 | - wp_mysql_user: < user name > 32 | - wp_mysql_password: < password > 33 | ``` 34 | 35 | ``` 36 | - hosts: wordpress 37 | vars: 38 | - wp_mysql_db: < database name > 39 | - wp_mysql_user: < user name > 40 | - wp_mysql_password: < password > 41 | ``` 42 | 43 | Build Images. 44 | ----------------- 45 | ``` 46 | $ cd example/wordpress-example 47 | $ ansible-container build 48 | ``` 49 | 50 | ## Run the Container. 51 | 52 | ``` 53 | $ ansible-container run 54 | 55 | ``` 56 | 57 | ## Push images to cloud. 58 | 59 | ``` 60 | $ docker login 61 | $ ansible-container push 62 | 63 | ``` 64 | 65 | ## Deploy to OpenShift. 66 | 67 | ``` 68 | $ ansible-container shipit openshift --save-config 69 | 70 | Images will be pulled from procrypto 71 | Attaching to ansible_ansible-container_1 72 | Cleaning up Ansible Container builder... 73 | Role wordpress created. 74 | 75 | ``` 76 | It will create the OpenShift artifacts to deploy it on OpenShift. 77 | 78 | 79 | ## Run the OpenShift artifacts. 80 | 81 | ``` 82 | $ oc create -f wordpress/ansible/shipit_config/openshift/ 83 | 84 | route "db-3306" created 85 | deploymentconfig "db" created 86 | service "db" created 87 | route "wordpress-80" created 88 | deploymentconfig "wordpress" created 89 | service "wordpress" created 90 | 91 | ``` 92 | 93 | ### View the Services and Deployments on OpenShift. 94 | 95 | ``` 96 | $ oc get service 97 | NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE 98 | db 172.30.32.159 3306/TCP 3h 99 | wordpress 172.30.47.102 80/TCP 3h 100 | 101 | ``` 102 | 103 | ### Next, take a look at the pods created by the deployments. 104 | 105 | ``` 106 | $ oc get pods 107 | NAME READY STATUS RESTARTS AGE 108 | db-1-0xob4 1/1 Running 0 3h 109 | wordpress-1-9wp23 1/1 Running 0 3h 110 | 111 | ``` 112 | 113 | ### Details of one of the pods. 114 | 115 | ``` 116 | $ oc describe pod wordpress-1-9wp23 117 | Name: wordpress-1-9wp23 118 | Namespace: sample-project 119 | Node: adb.vm/192.168.121.210 120 | Start Time: Thu, 25 Aug 2016 01:58:28 -0400 121 | Labels: app=wordpress,deployment=wordpress-1,deploymentconfig=wordpress,service=wordpress 122 | Status: Running 123 | IP: 172.17.0.6 124 | Controllers: ReplicationController/wordpress-1 125 | Containers: 126 | wordpress: 127 | Container ID: docker://49192ac035b01e56632a2090ee05695ffba54dc93ddfd45312486c4568775d56 128 | Image: procrypto/wordpress-wordpress:20160822144236 129 | Image ID: docker://8012c285060d102987cfbcc4b6a6220bc1037ab4d5b74b0de1568f43d6495f32 130 | Port: 80/TCP 131 | Args: 132 | bash 133 | -c 134 | bash /tmp/a.sh ; usr/sbin/apachectl -D FOREGROUND 135 | QoS Tier: 136 | memory: BestEffort 137 | cpu: BestEffort 138 | State: Running 139 | Started: Thu, 25 Aug 2016 02:01:57 -0400 140 | Ready: True 141 | Restart Count: 0 142 | Environment Variables: 143 | Conditions: 144 | Type Status 145 | Ready True 146 | Volumes: 147 | default-token-4s5b8: 148 | Type: Secret (a volume populated by a Secret) 149 | SecretName: default-token-4s5b8 150 | ``` 151 | 152 | 153 | 154 | 155 | ## Deploy to Kubernetes. 156 | 157 | ``` 158 | $ ansible-container shipit kube --save-config 159 | 160 | Images will be pulled from procrypto 161 | Attaching to ansible_ansible-container_1 162 | Cleaning up Ansible Container builder... 163 | Role wordpress created. 164 | 165 | ``` 166 | It will create the Kubernetes artifacts to deploy it on Kubernetes. 167 | 168 | 169 | ### Run the Kubernetes Artifacts. 170 | ``` 171 | $ kubectl create -f wordpress/ansible/shipit_config/kubernetes/ 172 | 173 | deployment "db" created 174 | service "db" created 175 | deployment "wordpress" created 176 | service "wordpress" created 177 | 178 | ``` 179 | 180 | ### View the Services on Kubernetes. 181 | 182 | ``` 183 | $ kubectl get service 184 | 185 | NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE 186 | db 10.254.176.204 3306/TCP 1m 187 | kubernetes 10.254.0.1 443/TCP 2d 188 | wordpress 10.254.177.169 80/TCP 1m 189 | 190 | ``` 191 | 192 | ### View the Deployments. 193 | 194 | ``` 195 | $ kubectl get deployment 196 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE 197 | db 1 1 1 1 4m 198 | wordpress 1 1 1 1 4m 199 | ``` 200 | 201 | ### Next, take a look at the pods created by the deployments. 202 | 203 | ``` 204 | $ kubectl get pods 205 | NAME READY STATUS RESTARTS AGE 206 | db-1420940741-bluto 1/1 Running 0 1m 207 | wordpress-1256450439-vqksz 1/1 Running 0 1m 208 | 209 | ``` 210 | 211 | ### Details of one of the pods. 212 | 213 | ``` 214 | $ kubectl describe pod wordpress-1256450439-vqksz 215 | Name: wordpress-1256450439-vqksz 216 | Namespace: default 217 | Node: 127.0.0.1/127.0.0.1 218 | Start Time: Thu, 25 Aug 2016 05:58:12 -0400 219 | Labels: app=wordpress,pod-template-hash=1256450439,service=wordpress 220 | Status: Running 221 | IP: 172.17.0.3 222 | Controllers: ReplicaSet/wordpress-1256450439 223 | Containers: 224 | wordpress: 225 | Container ID: docker://03136dc3b4aa204bc8f0e3c1811ed061ccb7b7f9bb8d3a6e1d7cd12c40f14767 226 | Image: procrypto/wordpress-wordpress:20160822144236 227 | Image ID: docker://8012c285060d102987cfbcc4b6a6220bc1037ab4d5b74b0de1568f43d6495f32 228 | Port: 80/TCP 229 | Args: 230 | bash 231 | -c 232 | bash /tmp/a.sh ; usr/sbin/apachectl -D FOREGROUND 233 | QoS Tier: 234 | cpu: BestEffort 235 | memory: BestEffort 236 | State: Running 237 | Started: Thu, 25 Aug 2016 05:58:19 -0400 238 | Ready: True 239 | Restart Count: 0 240 | Environment Variables: 241 | Conditions: 242 | Type Status 243 | Ready True 244 | Volumes: 245 | default-token-61sic: 246 | Type: Secret (a volume populated by a Secret) 247 | SecretName: default-token-61sic 248 | ``` 249 | -------------------------------------------------------------------------------- /wordpress/ansible/container.yml: -------------------------------------------------------------------------------- 1 | version: "1" 2 | services: 3 | db: 4 | image: centos:7 5 | ports: 6 | - "3306:3306" 7 | command: ['/usr/bin/mysqld_safe'] 8 | 9 | wordpress: 10 | image: centos:7 11 | ports: 12 | - "80:80" 13 | links: 14 | - db 15 | command: bash -c "bash /tmp/a.sh ; usr/sbin/apachectl -D FOREGROUND" 16 | 17 | -------------------------------------------------------------------------------- /wordpress/ansible/main.yml: -------------------------------------------------------------------------------- 1 | - hosts: db 2 | vars: 3 | - wp_mysql_db: wordpress 4 | - wp_mysql_user: wordpress 5 | - wp_mysql_password: password 6 | tasks: 7 | - name: Install mariadb mariadb-server 8 | yum: 9 | name: "{{ item }}" 10 | state: latest 11 | with_items: 12 | - epel-release 13 | - mariadb-server 14 | - bind-utils 15 | - psmisc 16 | - hostname 17 | - MySQL-python 18 | 19 | - name: Update the repository 20 | shell: yum -y erase vim-minimal && \ 21 | yum -y update && \ 22 | yum clean all 23 | 24 | - name: mysql_install_db 25 | shell: mysql_install_db --user=mysql --basedir=/usr/ --ldata=/var/lib/mysql/ 26 | 27 | - name: run mysqld_safe 28 | shell: mysqld_safe > /dev/null 2>&1 & 29 | sleep 5 30 | 31 | - name: Create mysql database 32 | mysql_db: 33 | name: "{{ wp_mysql_db }}" 34 | state: present 35 | 36 | - name: Create mysql user 37 | mysql_user: 38 | name: "{{ wp_mysql_user }}" 39 | password: "{{ wp_mysql_password }}" 40 | state: present 41 | priv: "*.*:ALL,GRANT" 42 | host: "%" 43 | 44 | 45 | - hosts: wordpress 46 | vars: 47 | - wp_mysql_db: wordpress 48 | - wp_mysql_user: wordpress 49 | - wp_mysql_password: password 50 | tasks: 51 | - name: Update the system with required packages 52 | shell: yum -y update && \ 53 | yum clean all && \ 54 | yum -y install epel-release && \ 55 | yum clean all 56 | 57 | - name: Install packages 58 | yum: 59 | name: "{{ item }}" 60 | state: latest 61 | with_items: 62 | - httpd 63 | - php 64 | - php-mysql 65 | - php-gd 66 | - psmisc 67 | - tar 68 | 69 | - name: Download wordpress 70 | shell: cd /tmp; curl -LO http://wordpress.org/latest.tar.gz 71 | 72 | - name: untar 73 | shell: tar -zxvf /tmp/latest.tar.gz -C /var/www/html 74 | 75 | - name: change permission 76 | shell: chmod +x /tmp/* 77 | 78 | - name: Change permission of files 79 | shell: chown -R apache:apache /var/www/* 80 | 81 | 82 | - name: Copy the sample file 83 | command: mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php 84 | 85 | - name: Change DocumentRoot 86 | lineinfile: 87 | dest: /etc/httpd/conf/httpd.conf 88 | regexp: "(.)+DocumentRoot /var/www/html" 89 | line: "DocumentRoot /var/www/html/wordpress" 90 | 91 | - name: Update the database path 92 | copy: 93 | content: sed /var/www/html/wordpress/wp-config.php -i -e "s/^\(define('DB_HOST', '\).*\(');.*\)/\1${DB_PORT#tcp://}\2/" 94 | dest: /tmp/a.sh 95 | 96 | - name: change perm 97 | shell: chmod +x /tmp/a.sh 98 | 99 | - name: Update WordPress config file 100 | lineinfile: 101 | dest: /var/www/html/wordpress/wp-config.php 102 | regexp: "{{ item.regexp }}" 103 | line: "{{ item.line }}" 104 | with_items: 105 | - {'regexp': "define\\('DB_NAME', '(.)+'\\);", 'line': "define('DB_NAME', '{{wp_mysql_db}}');"} 106 | - {'regexp': "define\\('DB_USER', '(.)+'\\);", 'line': "define('DB_USER', '{{wp_mysql_user}}');"} 107 | - {'regexp': "define\\('DB_PASSWORD', '(.)+'\\);", 'line': "define('DB_PASSWORD', '{{wp_mysql_password}}');"} 108 | -------------------------------------------------------------------------------- /wordpress/ansible/requirements.txt: -------------------------------------------------------------------------------- 1 | # These are the python requirements for your Ansible Container builder. 2 | # You do not need to include Ansible itself in this file. 3 | docker-py==1.8.0 --------------------------------------------------------------------------------