├── .github └── workflows │ └── main.yml ├── .gitignore ├── Dockerfile ├── HelloContainer.py ├── Makefile ├── README.md ├── app.py └── requirements.txt /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Python application test with Github Actions 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Set up Python 3.8 13 | uses: actions/setup-python@v1 14 | with: 15 | python-version: 3.8 16 | - name: Install dependencies 17 | run: | 18 | make install 19 | - name: Lint Dockerfile 20 | run: | 21 | make lint 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /.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 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.7.3-stretch 2 | 3 | # Working Directory 4 | WORKDIR /app 5 | 6 | # Copy source code to working directory 7 | COPY . app.py /app/ 8 | 9 | # Install packages from requirements.txt 10 | # hadolint ignore=DL3013 11 | RUN pip install --no-cache-dir --upgrade pip &&\ 12 | pip install --no-cache-dir --trusted-host pypi.python.org -r requirements.txt -------------------------------------------------------------------------------- /HelloContainer.py: -------------------------------------------------------------------------------- 1 | # Databricks notebook source 2 | print("hello world") 3 | 4 | # COMMAND ---------- 5 | 6 | 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | install: 2 | pip install --upgrade pip &&\ 3 | pip install -r requirements.txt 4 | 5 | lint: 6 | docker run --rm -i hadolint/hadolint < Dockerfile -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # container-from-scratch-python 2 | This is building a container from scratch 3 | 4 | ## Build the Container Yourself and Push to Docker Hub 5 | 6 | ### Build image 7 | *(If you want to develop yourself)* 8 | docker build --tag=hello-duke-cli-210 . 9 | 10 | ### List docker images 11 | docker image ls 12 | 13 | ### Run my newly built container 14 | 15 | docker run -it hello-duke-cli-210 python app.py --name "Big John" 16 | 17 | ### Push to Docker Hub 18 | 19 | *Note: You will need to change for your Docker Hub Repo* 20 | docker push noahgift/duke102:tagname 21 | 22 | ## Run it yourself 23 | 24 | ```bash 25 | docker pull noahgift/cloudapp:latest 26 | docker run -it noahgift/cloudapp bash 27 | 28 | #then run python app.py --help 29 | ``` 30 | 31 | ## Pass in a command 32 | 33 | ```bash 34 | docker run -it noahgift/cloudapp python app.py --name "Big John" 35 | #the output 36 | Hello Big John! 37 | ``` 38 | 39 | ## Push to Amazon ECR 40 | 41 | 1. Create ECR repository 42 | 43 | 44 | ### More things Do 45 | 46 | * Lint the code with Github Actions (see the Makefile) 47 | * Automatically build the container after lint, and push to DockerHub or some other Container Registery 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import click 3 | 4 | @click.command() 5 | @click.option("--name") 6 | def hello(name): 7 | click.echo(f'Hello {name}!') 8 | 9 | if __name__ == '__main__': 10 | #pylint: disable=no-value-for-parameter 11 | hello() -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pylint 2 | click 3 | --------------------------------------------------------------------------------