Skip to content

Commit

Permalink
Containers Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJanowicz committed Nov 30, 2022
1 parent 77b46b9 commit bd61ecd
Show file tree
Hide file tree
Showing 29 changed files with 319 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ ingestion/example_files/bigquery/*.json
# ignore all .csv files located in enrichment/example_data
enrichment/example_data/**/*.csv

**/__pycache__/
3 changes: 3 additions & 0 deletions containers/cleanupCommands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# To remove all images, containers, networks:
- command: `docker system prune -a -f`
- documentation: https://docs.docker.com/engine/reference/commandline/system_prune/
7 changes: 7 additions & 0 deletions containers/docker_ex1_python_env/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.10.0-slim

# Python commands run inside the virtual environment
RUN python -m pip install \
pandas \
numpy \

18 changes: 18 additions & 0 deletions containers/docker_ex1_python_env/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Simple example

## Install docker
- https://docs.docker.com/get-docker/

## Post-installation
- Make sure it works by running following command:
- `docker run hello-world`

## To run this docker file:
- First run build command: `docker build -t example1 .`

## Check that the image was built
- `docker images` - can also see the file sizes

- Then can run it: `docker run -it --rm example1`
- (-it) keeps the container running
- (--rm) automatically removes the container when exiting the program
9 changes: 9 additions & 0 deletions containers/docker_ex1b_ubuntu_env/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ubuntu:18.04

## add some labels
LABEL maintainer="[email protected]"
LABEL version="0.1"
LABEL description="This is a Dockerfile for a simple Ubuntu container."

## update the container
RUN apt-get update && apt-get upgrade -y
9 changes: 9 additions & 0 deletions containers/docker_ex1b_ubuntu_env/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Build (make sure you are in the right directory)
- `docker build -t ubuntu .`

# Run
- `docker run -i -d --rm ubuntu`
- note, the -d stands for 'detached' - meaning that this will run in the background
- if we want to see what is running in the background, we can do: `docker ps` to see list of containers running
- if we want to jummp into the terminal of the running container:
- `docker exec -it 408f95b22bcf /bin/bash` - will run/execute a command, bringing up the /bash terminal for us
6 changes: 6 additions & 0 deletions containers/docker_ex1c_mysql_env/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Create MySQL Image for JSP Tutorial Application
FROM mysql:latest

ENV MYSQL_ROOT_PASSWORD ahi2020

EXPOSE 3306
5 changes: 5 additions & 0 deletions containers/docker_ex1c_mysql_env/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Build
- `docker build -t hants-sql .`

# Run
- `docker run -d -p 3305:3306 hants-sql`
24 changes: 24 additions & 0 deletions containers/docker_ex2_streamlit_env/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## https://docs.streamlit.io/knowledge-base/tutorials/deploy/docker

FROM python:3.9-slim

EXPOSE 8501

# Set working directory in the container
WORKDIR /app

# copy /app directory from local machine to /app directory in container
COPY /app /app

# install dependencies and updates
RUN apt-get update && apt-get install -y \
build-essential \
software-properties-common \
git \
&& rm -rf /var/lib/apt/lists/*

# install python dependencies for python
RUN pip3 install -r requirements.txt

# run the app
ENTRYPOINT ["streamlit", "run", "streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
3 changes: 3 additions & 0 deletions containers/docker_ex2_streamlit_env/app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
altair
pandas
streamlit
37 changes: 37 additions & 0 deletions containers/docker_ex2_streamlit_env/app/streamlit_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from collections import namedtuple
import altair as alt
import math
import pandas as pd
import streamlit as st

"""
# Welcome to Streamlit (by hants)!
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
forums](https://discuss.streamlit.io).
In the meantime, below is an example of what you can do with just a few lines of code:
"""

with st.echo(code_location='below'):
total_points = st.slider("Number of points in spiral", 1, 5000, 2000)
num_turns = st.slider("Number of turns in spiral", 1, 100, 9)

Point = namedtuple('Point', 'x y')
data = []

points_per_turn = total_points / num_turns

for curr_point_num in range(total_points):
curr_turn, i = divmod(curr_point_num, points_per_turn)
angle = (curr_turn + 1) * 2 * math.pi * i / points_per_turn
radius = curr_point_num / total_points
x = radius * math.cos(angle)
y = radius * math.sin(angle)
data.append(Point(x, y))

st.altair_chart(alt.Chart(pd.DataFrame(data), height=500, width=500)
.mark_circle(color='#0068c9', opacity=0.5)
.encode(x='x:Q', y='y:Q'))
6 changes: 6 additions & 0 deletions containers/docker_ex2_streamlit_env/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Build
- `docker build -t streamlit .`

# Run:
- `docker run -p 8501:8501 streamlit`
- note - the -p is for opening up the containers port 8501 and pushing it to our machines/OS port 8501
20 changes: 20 additions & 0 deletions containers/docker_w_compose_ex1_flask_1app/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.7-alpine
## add bash so can use bash commands/go into container
RUN apk update && apk add bash

# set working directory with env varialbes
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_DEBUG=1
ENV FLASK_RUN_PORT=5001

# copy files into working directory
COPY . .

# install dependencies
RUN pip install -r requirements.txt

# run the app and expose the default port for flask
EXPOSE 5001
CMD ["flask", "run"]
7 changes: 7 additions & 0 deletions containers/docker_w_compose_ex1_flask_1app/app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
return 'Hello World! This is from a basic flask app - with mods (part3)'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask
8 changes: 8 additions & 0 deletions containers/docker_w_compose_ex1_flask_1app/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.9"
services:
flaskapp1:
build: ./app
ports:
- "8001:5001"
volumes:
- ./app:/code
7 changes: 7 additions & 0 deletions containers/docker_w_compose_ex1_flask_1app/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# To run:
- `docker-compose up --build`
- this will build the container and everything in it for the first time

## To run again with no changes:
- `docker-compose up`
- while if you need to update it because of code changes to the docker file, likely should add `--build` argument to end
20 changes: 20 additions & 0 deletions containers/docker_w_compose_ex1_flask_3app/app1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.7-alpine
## add bash so can use bash commands/go into container
RUN apk update && apk add bash

# set working directory with env varialbes
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_DEBUG=1
ENV FLASK_RUN_PORT=5001

# copy files into working directory
COPY . .

# install dependencies
RUN pip install -r requirements.txt

# run the app and expose the default port for flask
EXPOSE 5001
CMD ["flask", "run"]
7 changes: 7 additions & 0 deletions containers/docker_w_compose_ex1_flask_3app/app1/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
return 'Hello from Flask App 1'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask
20 changes: 20 additions & 0 deletions containers/docker_w_compose_ex1_flask_3app/app2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.7-alpine
## add bash so can use bash commands/go into container
RUN apk update && apk add bash

# set working directory with env varialbes
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_DEBUG=1
ENV FLASK_RUN_PORT=5002

# copy files into working directory
COPY . .

# install dependencies
RUN pip install -r requirements.txt

# run the app and expose the default port for flask
EXPOSE 5002
CMD ["flask", "run"]
7 changes: 7 additions & 0 deletions containers/docker_w_compose_ex1_flask_3app/app2/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
return 'Hell from Flask App 2'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask
24 changes: 24 additions & 0 deletions containers/docker_w_compose_ex1_flask_3app/app3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## https://docs.streamlit.io/knowledge-base/tutorials/deploy/docker

FROM python:3.9-slim

EXPOSE 8501

# Set working directory in the container
WORKDIR /app

# copy /app directory from local machine to /app directory in container
COPY /app /app

# install dependencies and updates
RUN apt-get update && apt-get install -y \
build-essential \
software-properties-common \
git \
&& rm -rf /var/lib/apt/lists/*

# install python dependencies for python
RUN pip3 install -r requirements.txt

# run the app
ENTRYPOINT ["streamlit", "run", "streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
altair
pandas
streamlit
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from collections import namedtuple
import altair as alt
import math
import pandas as pd
import streamlit as st

"""
# Welcome to Streamlit (by hants)!
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
forums](https://discuss.streamlit.io).
In the meantime, below is an example of what you can do with just a few lines of code:
"""

with st.echo(code_location='below'):
total_points = st.slider("Number of points in spiral", 1, 5000, 2000)
num_turns = st.slider("Number of turns in spiral", 1, 100, 9)

Point = namedtuple('Point', 'x y')
data = []

points_per_turn = total_points / num_turns

for curr_point_num in range(total_points):
curr_turn, i = divmod(curr_point_num, points_per_turn)
angle = (curr_turn + 1) * 2 * math.pi * i / points_per_turn
radius = curr_point_num / total_points
x = radius * math.cos(angle)
y = radius * math.sin(angle)
data.append(Point(x, y))

st.altair_chart(alt.Chart(pd.DataFrame(data), height=500, width=500)
.mark_circle(color='#0068c9', opacity=0.5)
.encode(x='x:Q', y='y:Q'))
21 changes: 21 additions & 0 deletions containers/docker_w_compose_ex1_flask_3app/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3.9"
services:
app1_flask:
build: ./app1
ports:
- "8001:5001"
volumes:
- ./app1:/code
app2_flask:
build: ./app2
ports:
- "8002:5002"
volumes:
- ./app2:/code
app3_streamlit:
build: ./app3
ports:
- "8003:8501"
volumes:
- ./app3/app:/app

7 changes: 7 additions & 0 deletions containers/docker_w_compose_ex1_flask_3app/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# To run:
- `docker-compose up --build`
- this will build the container and everything in it for the first time

## To run again with no changes:
- `docker-compose up`
- while if you need to update it because of code changes to the docker file, likely should add `--build` argument to end
Empty file.

0 comments on commit bd61ecd

Please sign in to comment.