Skip to content

Commit

Permalink
Added app files
Browse files Browse the repository at this point in the history
  • Loading branch information
labeveryday committed May 28, 2021
1 parent 240e5d9 commit a40787e
Show file tree
Hide file tree
Showing 12 changed files with 571 additions and 1 deletion.
132 changes: 132 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# VScode
.VScode
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2021, Cisco Systems, Inc. and/or its affiliates
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python main.py
128 changes: 127 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,127 @@
# startnow-Intro-to-Python-buildpacks
# startnow-Intro-to-Python-buildpacks

This is a repo focuses on walking through the basics of using a python build pack to build your docker containers.

This app leverages `https://registry.buildpacks.io/searches/python` and the Cisco DevNet [ACI Always On Sandbox](https://devnetsandbox.cisco.com/RM/Topology) to gather FabricOverallHealth and also verify Tenants in ACI.

To sign up for DevNet: [Start Now](http://cs.co/startnowduan)

>Special thanks to [DaShaun](https://twitter.com/dashaun) from Redis Labs for introducing me to this awesome tool!
___

## Why use buildpacks

Building and maintaining a `Dockerfile` can be a pain. Most network engineers just want to get their app up and running without worrying about the things they don't need to.

This is where buildpacks come in because they remove the pain of building a container like:

- Finding the right images
- Security risks do to patching
- Time it takes to build a `Dockerfile`

They give you the ability to containerize your entire app in as little as 1 command. The buildpack will handle the version of python that will be used along with installing all of the dependencies from the requirements.txt file.

NOW THATS SWEET!
___

## How To Get Started

1. Build your app:

```bash
➜ intro-to-python-buildpacks git:(main) ✗ tree -L 2
.
├── LICENSE
├── Procfile
├── README.md
├── __init__.py
├── app
│ ├── __init__.py
│ └── aci_conn.py
├── main.py
├── requirements.txt
├── tenant_log.txt
```

>NOTE: In this repo we have all the files needed to containerize our python app.

2. [Install docker](https://hub.docker.com/search?type=edition&offering=community): This is needed to run your app once its containerized.

3. Once docker is installed we have to then install the `pack CLI` tool to build our containers from buildpack

>NOTE: Pack is maintained by the Cloud Native Buildpacks project to support the use of buildpack

https://buildpacks.io/docs/tools/pack/

4. After installation verify the installed `pack CLI` version

```bash
pack --version
```

5. Now create the default builder that will be used for packeto. A builder includes the buildpacks and everything we need like our environment for building our python app.

```bash
pack config default-builder paketobuildpacks/builder:full
```

>You can use `pack builder suggest` to view a list of suggested builders

6. Before we containerize our app we need to create a file in our root directory called `Procfile`. Here is where we add our "process type" i.e. `web, worker, urgentworker, clock` and so on and then we enter our command argument that should be executed on startup.

```bash
web: python main.py
```

For more information on the [Procfile](https://devcenter.heroku.com/articles/procfile)

7. Now lets build the app using the latest python build pack

```bash
pack build myaciapp --buildpack paketo-community/[email protected]
```

To find build packs: [https://registry.buildpacks.io/searches/python](https://registry.buildpacks.io/searches/python)

8. We can now verify that our app image has been built by executing:

```bash
docker images myaciapp
```

![image](./images/image.png "Docker image")

9. Last thing to do is run our app:

```bash
docker run myaciapp
```

![Results](./images/results.png "Myapp Results")

___

## Notes

Buildpacks were introduced by Heroku, in 2011, and adopted by Cloud Foundry, Gitlab, Knative and others.

Cloud Native Buildpacks began with Heroku and Pivotal in early 2018.

Cloud Native Buildpacks joined the CNCF in October 2018.

By using the Python Buildpack you don't have to worry about building the dockerfile configuration
The build pack will automatically grab the `Procfile`, `buildpack.yml`, `requirements.txt`
___
### About me
Introverted Network Automation Engineer that is changing lives as a Developer Advocate for Cisco DevNet. Pythons scripts are delicious. Especially at 2am on a Saturday night.
Contact Me:
- [LinkedIn](https://www.linkedin.com/in/duanlightfoot/)
- [Twitter](https://twitter.com/labeveryday)
Empty file added __init__.py
Empty file.
Empty file added app/__init__.py
Empty file.
Loading

0 comments on commit a40787e

Please sign in to comment.