Skip to content

Commit 2b73e27

Browse files
committed
initial commit
0 parents  commit 2b73e27

File tree

9 files changed

+207
-0
lines changed

9 files changed

+207
-0
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
keys/*.json

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM jupyter/base-notebook:latest
2+
3+
WORKDIR /work
4+
5+
USER root
6+
RUN apt-get update && \
7+
apt-get upgrade -y && \
8+
apt-get install -y git
9+
10+
RUN git clone https://github.com/stackql/pystackql
11+
12+
ADD ./bin/stackql /work/
13+
14+
RUN mv stackql /bin && \
15+
chmod +x /bin/stackql
16+
17+
COPY ./keys /keys
18+
COPY ./example.ipynb /work
19+
20+
RUN chmod 644 example.ipynb && \
21+
chown jovyan:users example.ipynb
22+
23+
ENV PYTHON_PACKAGES="\
24+
matplotlib \
25+
pandas \
26+
mplfinance \
27+
"
28+
29+
RUN pip install --upgrade pip \
30+
&& pip install --no-cache-dir $PYTHON_PACKAGES

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 InfraQL
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# StackQL Jupyter Demo
2+
3+
Query cloud inventory and perform analysis and visualisations using Jupyter and Python.
4+
5+
## Prerequisites
6+
7+
- Docker
8+
9+
## Instructions
10+
11+
1. Clone this repo `git clone https://github.com/stackql/stackql-jupyter-demo`
12+
2. Add the appropriate service account key for your environment to the `keys/` directory
13+
3. Build the image:
14+
```shell
15+
docker build --no-cache -t stackql-jupyter-demo .
16+
```
17+
4. Run the image:
18+
```shell
19+
docker run -dp 8888:8888 stackql-jupyter-demo start-notebook.sh --NotebookApp.token=''
20+
```
21+
> Add authentication if running this on a server which is accessible to others, see https://jupyter-notebook.readthedocs.io/en/stable/security.html
22+
5. Run your StackQL commands!
23+
6. Stop your running container when finished:
24+
```shell
25+
docker stop $(docker ps -l -q --filter status=running --filter ancestor=stackql-jupyter-demo)
26+
```
27+
28+
## Example
29+
30+
![Example Notebook](images/example-notebook.png)

bin/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore

example.ipynb

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "18459691",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%env OKTA_SECRET_KEY=yourapikey"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "5f4d2d85",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"auth = { \n",
21+
" \"google\": { \n",
22+
" \"keyfilepath\": \"/keys/infraql-demo.json\", \n",
23+
" \"keyfiletype\": \"serviceaccount\" \n",
24+
" }, \n",
25+
" \"okta\": { \n",
26+
" \"keyenvvar\": \"OKTA_SECRET_KEY\", \n",
27+
" \"keyfiletype\": \"api_key\" \n",
28+
" } \n",
29+
" }"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"id": "c3c2fed4",
36+
"metadata": {},
37+
"outputs": [],
38+
"source": [
39+
"import json, pandas as pd\n",
40+
"from pystackql import StackQL\n",
41+
"iql = StackQL(auth=json.dumps(auth))"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"id": "c891981d",
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"iql_query = \"\"\"\n",
52+
"SELECT id, name \n",
53+
"FROM google.compute.instances \n",
54+
"WHERE project = 'infraql-demo' \n",
55+
"AND zone = 'australia-southeast1-a'\n",
56+
"\"\"\""
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"id": "50fb43ea",
63+
"metadata": {},
64+
"outputs": [],
65+
"source": [
66+
"pd.read_json(iql.execute(iql_query))"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": null,
72+
"id": "0f864f31",
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"iql_query = \"\"\"\n",
77+
"SELECT id, \n",
78+
"JSON_EXTRACT(credentials, '$.emails[0].status') as status \n",
79+
"FROM okta.user.users \n",
80+
"WHERE subdomain = 'dev-72290228'\n",
81+
"\"\"\""
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"id": "f0533dcb",
88+
"metadata": {},
89+
"outputs": [],
90+
"source": [
91+
"pd.read_json(iql.execute(iql_query))"
92+
]
93+
}
94+
],
95+
"metadata": {
96+
"kernelspec": {
97+
"display_name": "Python 3",
98+
"language": "python",
99+
"name": "python3"
100+
},
101+
"language_info": {
102+
"codemirror_mode": {
103+
"name": "ipython",
104+
"version": 3
105+
},
106+
"file_extension": ".py",
107+
"mimetype": "text/x-python",
108+
"name": "python",
109+
"nbconvert_exporter": "python",
110+
"pygments_lexer": "ipython3",
111+
"version": "3.9.2"
112+
}
113+
},
114+
"nbformat": 4,
115+
"nbformat_minor": 5
116+
}

images/example-notebook.png

105 KB
Loading

keys/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore

0 commit comments

Comments
 (0)