Skip to content

Commit c864ea6

Browse files
michaelarnautsballoob
authored andcommitted
Improve development workflow in docker (home-assistant#5079)
* Allow bower install of frontend components as root. Needed for frontend development in docker since everything runs as root in the docker image. * Improve development workflow in docker * Use LANG=C.UTF-8 in tox. Fixes installation of libraries with UTF-8 in it's readme. * Install mysqlclient psycopg2 uvloop after requirements_all.txt again, but with a --no-cache-dir this time. Allows bootstrap_frontend to be executed in a different path like the other scripts.
1 parent b2371c6 commit c864ea6

21 files changed

+142
-71
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN script/build_python_openzwave && \
2323

2424
COPY requirements_all.txt requirements_all.txt
2525
RUN pip3 install --no-cache-dir -r requirements_all.txt && \
26-
pip3 install mysqlclient psycopg2 uvloop
26+
pip3 install --no-cache-dir mysqlclient psycopg2 uvloop
2727

2828
# Copy source
2929
COPY . .

script/bootstrap

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/sh
2+
# Resolve all dependencies that the application requires to run.
23

3-
# script/bootstrap: Resolve all dependencies that the application requires to
4-
# run.
4+
# Stop on errors
5+
set -e
56

67
cd "$(dirname "$0")/.."
7-
88
script/bootstrap_server
99
script/bootstrap_frontend

script/bootstrap_frontend

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1+
#!/bin/sh
2+
# Resolve all frontend dependencies that the application requires to run.
3+
4+
# Stop on errors
5+
set -e
6+
7+
cd "$(dirname "$0")/.."
8+
19
echo "Bootstrapping frontend..."
10+
211
git submodule update
312
cd homeassistant/components/frontend/www_static/home-assistant-polymer
13+
14+
# Install node modules
415
npm install
5-
./node_modules/.bin/bower install
16+
17+
# Install bower web components. Allow to download the components as root since the user in docker is root.
18+
./node_modules/.bin/bower install --allow-root
19+
620
npm run setup_js_dev
721
cd ../../../../..

script/bootstrap_server

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#!/bin/sh
2+
# Resolve all server dependencies that the application requires to run.
3+
4+
# Stop on errors
5+
set -e
6+
17
cd "$(dirname "$0")/.."
28

39
echo "Installing dependencies..."

script/build_frontend

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1+
#!/bin/sh
12
# Builds the frontend for production
23

4+
# Stop on errors
5+
set -e
6+
37
cd "$(dirname "$0")/.."
48

5-
cd homeassistant/components/frontend/www_static
6-
rm -rf core.js* frontend.html* webcomponents-lite.min.js* panels
7-
cd home-assistant-polymer
9+
# Clean up
10+
rm -rf homeassistant/components/frontend/www_static/core.js* \
11+
homeassistant/components/frontend/www_static/frontend.html* \
12+
homeassistant/components/frontend/www_static/webcomponents-lite.min.js* \
13+
homeassistant/components/frontend/www_static/panels
14+
cd homeassistant/components/frontend/www_static/home-assistant-polymer
815
npm run clean
9-
npm run frontend_prod
1016

17+
# Build frontend
18+
npm run frontend_prod
1119
cp bower_components/webcomponentsjs/webcomponents-lite.min.js ..
1220
cp -r build/* ..
1321
BUILD_DEV=0 node script/gen-service-worker.js
1422
cp build/service_worker.js ..
15-
1623
cd ..
1724

25+
# Pack frontend
1826
gzip -f -k -9 *.html *.js ./panels/*.html
27+
cd ../../../..
1928

2029
# Generate the MD5 hash of the new frontend
21-
cd ../../../..
2230
script/fingerprint_frontend.py

script/build_python_openzwave

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# Sets up and builds python open zwave to be used with Home Assistant
1+
#!/bin/sh
2+
# Sets up and builds python open zwave to be used with Home Assistant.
23
# Dependencies that need to be installed:
34
# apt-get install cython3 libudev-dev python3-sphinx python3-setuptools
45

6+
# Stop on errors
7+
set -e
8+
59
cd "$(dirname "$0")/.."
610

711
if [ ! -d build ]; then
@@ -15,7 +19,7 @@ if [ -d python-openzwave ]; then
1519
git pull --recurse-submodules=yes
1620
git submodule update --init --recursive
1721
else
18-
git clone --recursive --depth 1 https://github.com/OpenZWave/python-openzwave.git
22+
git clone --branch python3 --recursive --depth 1 https://github.com/OpenZWave/python-openzwave.git
1923
cd python-openzwave
2024
fi
2125

script/dev_docker

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
# Build and run Home Assinstant in Docker
1+
#!/bin/sh
2+
# Build and run Home Assinstant in Docker.
23

34
# Optional: pass in a timezone as first argument
45
# If not given will attempt to mount /etc/localtime
56

7+
# Stop on errors
8+
set -e
9+
610
cd "$(dirname "$0")/.."
711

8-
docker build -t home-assistant-dev .
12+
docker build -t home-assistant-dev -f virtualization/Docker/Dockerfile.dev .
913

1014
if [ $# -gt 0 ]
1115
then

script/dev_openzwave_docker

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Open a docker that can be used to debug/dev python-openzwave
2-
# Pass in a command line argument to build
1+
#!/bin/sh
2+
# Open a docker that can be used to debug/dev python-openzwave. Pass in a command line argument to build
33

44
cd "$(dirname "$0")/.."
55

script/fingerprint_frontend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
2-
32
"""Generate a file with all md5 hashes of the assets."""
3+
44
from collections import OrderedDict
55
import glob
66
import hashlib

script/lint

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/sh
2-
#
3-
# NOTE: all testing is now driven through tox. The tox command below
4-
# performs roughly what this test did in the past.
2+
# Execute lint to spot code mistakes.
53

64
if [ "$1" = "--changed" ]; then
75
export files="`git diff upstream/dev --name-only | grep -e '\.py$'`"

script/lint_docker

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#!/bin/bash
1+
#!/bin/sh
2+
# Execute lint in a docker container to spot code mistakes.
3+
4+
# Stop on errors
25
set -e
36

4-
docker build -t home-assistant-test -f virtualization/Docker/Dockerfile.test .
7+
docker build -t home-assistant-test -f virtualization/Docker/Dockerfile.dev .
58
docker run --rm -it home-assistant-test tox -e lint

script/release

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Pushes a new version to PyPi
1+
#!/bin/sh
2+
# Pushes a new version to PyPi.
3+
4+
# Stop on errors
5+
set -e
26

37
cd "$(dirname "$0")/.."
48

script/server

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/sh
2+
# Launch the application and any extra required processes locally.
23

3-
# script/server: Launch the application and any extra required processes
4-
# locally.
4+
# Stop on errors
5+
set -e
56

67
cd "$(dirname "$0")/.."
7-
88
python3 -m homeassistant -c config

script/setup

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
#!/usr/bin/env sh
2-
cd "$(dirname "$0")/.."
1+
#!/bin/sh
2+
# Setups the repository.
3+
4+
# Stop on errors
5+
set -e
36

7+
cd "$(dirname "$0")/.."
48
git submodule init
59
script/bootstrap
610
python3 setup.py develop

script/test

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/bin/sh
2-
#
3-
# NOTE: all testing is now driven through tox. The tox command below
4-
# performs roughly what this test did in the past.
2+
# Excutes the tests with tox.
53

64
tox -e py34

script/test_docker

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#!/bin/bash
1+
#!/bin/sh
2+
# Excutes the tests with tox in a docker container.
3+
4+
# Stop on errors
25
set -e
36

4-
docker build -t home-assistant-test -f virtualization/Docker/Dockerfile.test .
5-
docker run --rm -it home-assistant-test tox -e py34
7+
docker build -t home-assistant-test -f virtualization/Docker/Dockerfile.dev .
8+
docker run --rm -it home-assistant-test tox -e py35

script/update

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/sh
2+
# Update application to run for its current checkout.
23

3-
# script/update: Update application to run for its current checkout.
4+
# Stop on errors
5+
set -e
46

57
cd "$(dirname "$0")/.."
6-
78
git pull
89
git submodule update

script/update_mdi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
2-
32
"""Download the latest Polymer v1 iconset for materialdesignicons.com."""
3+
44
import gzip
55
import os
66
import re

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ setenv =
88
; which get read in from setup.py. If we don't force our locale to a
99
; utf8 one, tox's env is reset. And the install of these 2 packages
1010
; fail.
11-
LANG=en_US.UTF-8
11+
LANG=C.UTF-8
1212
PYTHONPATH = {toxinidir}:{toxinidir}/homeassistant
1313
commands =
1414
py.test --timeout=30 --duration=10 --cov --cov-report= {posargs}

virtualization/Docker/Dockerfile.dev

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Dockerfile for development
2+
# Based on the production Dockerfile, but with development additions.
3+
# Keep this file as close as possible to the production Dockerfile, so the environments match.
4+
5+
FROM python:3.5
6+
MAINTAINER Paulus Schoutsen <Paulus@PaulusSchoutsen.nl>
7+
8+
VOLUME /config
9+
10+
RUN mkdir -p /usr/src/app
11+
WORKDIR /usr/src/app
12+
13+
RUN pip3 install --no-cache-dir colorlog cython
14+
15+
# For the nmap tracker, bluetooth tracker, Z-Wave, tellstick
16+
RUN echo "deb http://download.telldus.com/debian/ stable main" >> /etc/apt/sources.list.d/telldus.list && \
17+
wget -qO - http://download.telldus.se/debian/telldus-public.key | apt-key add - && \
18+
apt-get update && \
19+
apt-get install -y --no-install-recommends nmap net-tools cython3 libudev-dev sudo libglib2.0-dev bluetooth libbluetooth-dev \
20+
libtelldus-core2 && \
21+
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
22+
23+
COPY script/build_python_openzwave script/build_python_openzwave
24+
RUN script/build_python_openzwave && \
25+
mkdir -p /usr/local/share/python-openzwave && \
26+
ln -sf /usr/src/app/build/python-openzwave/openzwave/config /usr/local/share/python-openzwave/config
27+
28+
COPY requirements_all.txt requirements_all.txt
29+
RUN pip3 install --no-cache-dir -r requirements_all.txt && \
30+
pip3 install --no-cache-dir mysqlclient psycopg2 uvloop
31+
32+
# BEGIN: Development additions
33+
34+
# Install nodejs
35+
RUN curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - && \
36+
apt-get install -y nodejs
37+
38+
# Install tox
39+
RUN pip3 install --no-cache-dir tox
40+
41+
# Copy over everything required to run tox
42+
COPY requirements_test.txt .
43+
COPY setup.cfg .
44+
COPY setup.py .
45+
COPY tox.ini .
46+
COPY homeassistant/const.py homeassistant/const.py
47+
48+
# Get all dependencies
49+
RUN tox -e py35 --notest
50+
51+
# END: Development additions
52+
53+
# Copy source
54+
COPY . .
55+
56+
CMD [ "python", "-m", "homeassistant", "--config", "/config" ]

virtualization/Docker/Dockerfile.test

-32
This file was deleted.

0 commit comments

Comments
 (0)