Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions google-iotsdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM debian:10.3-slim
ARG DEBIAN_FRONTEND=noninteractive

# [UBUNTU]
RUN apt-get update && \
apt-get install -y python3 git ca-certificates curl \
cmake build-essential libssl-dev python3-dev python3-pip zlib1g-dev openssl uuid-runtime libffi-dev

# install python3 dependencies in advance -- we can copy them later
RUN python3 -m pip install --no-cache --upgrade pip && \
python3 -m pip install --no-cache --upgrade setuptools wheel psutil

RUN python3 -m pip install --no-cache --upgrade cryptography>=2.9.2
RUN python3 -m pip install --no-cache --upgrade google-api-python-client>=1.9.3
RUN python3 -m pip install --no-cache --upgrade google-auth-httplib2>=0.0.3
RUN python3 -m pip install --no-cache --upgrade google-auth>=1.18.0
RUN python3 -m pip install --no-cache --upgrade google-cloud-pubsub>=1.6.0
RUN python3 -m pip install --no-cache --upgrade google-cloud-iot>=1.0.0
RUN python3 -m pip install --no-cache --upgrade grpc-google-iam-v1>=0.12.3
RUN python3 -m pip install --no-cache --upgrade pyjwt>=1.7.1
RUN python3 -m pip install --no-cache --upgrade paho-mqtt>=1.5.0


RUN mkdir -p /config
RUN mkdir -p /google-iotsdk
RUN mkdir -p /prov

WORKDIR /
COPY google-iotsdk/* /google-iotsdk/

ENTRYPOINT ["/google-iotsdk/start.sh"]
3 changes: 3 additions & 0 deletions google-iotsdk/config/google.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PROJECT_ID=homeassistant-281519
REGISTRY_ID=homeassistant-registry
DEVICE_ID=google-device
12 changes: 12 additions & 0 deletions google-iotsdk/config/google.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "XXXXXX-281519",
"private_key_id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"private_key": "-----BEGIN PRIVATE KEY-----\iXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n-----END PRIVATE KEY-----\n",
"client_email": "raspberry@homeassistant-281519.iam.gserviceaccount.com",
"client_id": "XXXXXXXXXXXXX",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/raspberry%40homeassistant-281519.iam.gserviceaccount.com"
}
17 changes: 17 additions & 0 deletions google-iotsdk/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# google-iotsdk/docker-compose.yml
version: "3"
services:
google-iotsdk:
image: hub.foundries.io/<YOUR_FACTORY_NAME>/google-iotsdk:latest
tmpfs:
- /run
- /var/lock
- /var/log
volumes:
- /var/run/secrets:/config
environment:
- GOOGLE_APPLICATION_CREDENTIALS=/config/google.json
tty: true
network_mode: "host"
privileged: true
restart: always
34 changes: 34 additions & 0 deletions google-iotsdk/google-iotsdk/provision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

# create the device certificate
#
# On the first connection attempt, it will trigger the google thing creation,
# registration and so forth

PROV_DIR=${1:-/prov}
DEVICE_ID_FILE=${2:-/prov/thing_name}

GOOGLE_CONFIG_CREDENTIAL="/config/google.json"

if [ -f "$DEVICE_ID_FILE" ]; then
echo "$DEVICE_ID_FILE exists."
else
while [ ! -f $GOOGLE_CONFIG_CREDENTIAL ]
do
sleep 5 # or less like 0.2
echo "Waiting $GOOGLE_CONFIG_CREDENTIAL"
done
ls -l $GOOGLE_CONFIG_CREDENTIAL
DEVICE_UUID=$(uuidgen)
DEVICE_ID="fio-google-${DEVICE_UUID}"
echo "[provision] Device name: ${DEVICE_ID}"
echo "${DEVICE_ID}" > "${PROV_DIR}/thing_name"
openssl req -x509 -newkey rsa:2048 -keyout ${PROV_DIR}/rsa_private.pem -nodes -out ${PROV_DIR}/rsa_cert.pem -subj "/CN=unused"
fi

DEVICE_ID="$(cat ${PROV_DIR}/thing_name)"
echo "[provision] Device name: ${DEVICE_ID}"
export GOOGLE_APPLICATION_CREDENTIALS="$GOOGLE_CONFIG_CREDENTIAL"
echo "9"


1,222 changes: 1,222 additions & 0 deletions google-iotsdk/google-iotsdk/roots.pem

Large diffs are not rendered by default.

Loading