Fix docker build

This commit is contained in:
Otto Winter
2018-08-26 11:26:14 +02:00
parent 1576e1847e
commit 74c70509c2
19 changed files with 1086 additions and 28 deletions
+1
View File
@@ -107,3 +107,4 @@ config/
examples/ examples/
Dockerfile Dockerfile
.git/ .git/
tests/build/
+1
View File
@@ -104,3 +104,4 @@ venv.bak/
.mypy_cache/ .mypy_cache/
config/ config/
tests/build/
+54 -8
View File
@@ -5,6 +5,7 @@ variables:
stages: stages:
- lint - lint
- test
- build - build
- deploy - deploy
@@ -14,7 +15,20 @@ stages:
- python2.7 - python2.7
- esphomeyaml-lint - esphomeyaml-lint
.hassio-builder: &hassio-builder .test: &test
stage: test
before_script:
- pip install -e .
tags:
- python2.7
- esphomeyaml-test
variables:
TZ: UTC
cache:
paths:
- tests/build
.docker-builder: &docker-builder
before_script: before_script:
- docker info - docker info
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
@@ -33,8 +47,13 @@ pylint:
script: script:
- pylint esphomeyaml - pylint esphomeyaml
.build: &build test:
<<: *hassio-builder <<: *test
script:
- esphomeyaml tests/test1.yaml compile
.build-hassio: &build-hassio
<<: *docker-builder
stage: build stage: build
script: script:
- | - |
@@ -49,10 +68,11 @@ pylint:
"${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}" "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}"
- docker push "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}" - docker push "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:${CI_COMMIT_SHA}"
- docker push "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:dev" - docker push "${CI_REGISTRY}/ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:dev"
retry: 1
# Generic deploy template # Generic deploy template
.deploy: &deploy .deploy: &deploy
<<: *hassio-builder <<: *docker-builder
stage: deploy stage: deploy
script: script:
- version=${CI_COMMIT_TAG:1} - version=${CI_COMMIT_TAG:1}
@@ -71,8 +91,20 @@ pylint:
- docker push "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:latest" - docker push "ottowinter/esphomeyaml-hassio-${ADDON_ARCH}:latest"
# Build jobs # Build jobs
build:normal:
<<: *docker-builder
stage: build
script:
- docker build -t "${CI_REGISTRY}/ottowinter/esphomeyaml:dev" .
- |
docker tag \
"${CI_REGISTRY}/ottowinter/esphomeyaml:dev" \
"${CI_REGISTRY}/ottowinter/esphomeyaml:${CI_COMMIT_SHA}"
- docker push "${CI_REGISTRY}/ottowinter/esphomeyaml:${CI_COMMIT_SHA}"
- docker push "${CI_REGISTRY}/ottowinter/esphomeyaml:dev"
build:armhf: build:armhf:
<<: *build <<: *build-hassio
variables: variables:
ADDON_ARCH: armhf ADDON_ARCH: armhf
@@ -82,12 +114,12 @@ build:armhf:
# ADDON_ARCH: aarch64 # ADDON_ARCH: aarch64
build:i386: build:i386:
<<: *build <<: *build-hassio
variables: variables:
ADDON_ARCH: i386 ADDON_ARCH: i386
build:amd64: build:amd64:
<<: *build <<: *build-hassio
variables: variables:
ADDON_ARCH: amd64 ADDON_ARCH: amd64
@@ -119,7 +151,6 @@ deploy:i386:
except: except:
- /^(?!master).+@/ - /^(?!master).+@/
deploy:amd64: deploy:amd64:
<<: *deploy <<: *deploy
variables: variables:
@@ -129,3 +160,18 @@ deploy:amd64:
except: except:
- /^(?!master).+@/ - /^(?!master).+@/
deploy:pypi:
stage: deploy
before_script:
- pip install -e .
- pip install twine
script:
- python setup.py sdist
- twine upload dist/*
tags:
- python2.7
- esphomeyaml-test
only:
- /^v\d+\.\d+\.\d+(?:(?:(?:\+|\.)?[a-zA-Z0-9]+)*)?$/
except:
- /^(?!master).+@/
+5 -1
View File
@@ -1,6 +1,10 @@
FROM python:2.7 FROM python:2.7
MAINTAINER Otto Winter <contact@otto-winter.com> MAINTAINER Otto Winter <contact@otto-winter.com>
RUN apt-get update && apt-get install -y \
python-pil \
&& rm -rf /var/lib/apt/lists/*
ENV ESPHOMEYAML_OTA_HOST_PORT=6123 ENV ESPHOMEYAML_OTA_HOST_PORT=6123
EXPOSE 6123 EXPOSE 6123
VOLUME /config VOLUME /config
@@ -16,7 +20,7 @@ RUN platformio settings set enable_telemetry No && \
COPY . . COPY . .
RUN pip install -e . && \ RUN pip install -e . && \
pip install pillow tzlocal pip install tzlocal
WORKDIR /config WORKDIR /config
ENTRYPOINT ["esphomeyaml"] ENTRYPOINT ["esphomeyaml"]
+2 -1
View File
@@ -5,6 +5,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
python \ python \
python-pip \ python-pip \
python-setuptools \ python-setuptools \
python-pil \
git \ git \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/*rm -rf /var/lib/apt/lists/* /tmp/* && \ && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/*rm -rf /var/lib/apt/lists/* /tmp/* && \
pip install --no-cache-dir --no-binary :all: platformio && \ pip install --no-cache-dir --no-binary :all: platformio && \
@@ -15,6 +16,6 @@ RUN platformio run -d /pio; rm -rf /pio
COPY . . COPY . .
RUN pip install --no-cache-dir --no-binary :all: -e . && \ RUN pip install --no-cache-dir --no-binary :all: -e . && \
pip install --no-cache-dir --no-binary :all: pillow tzlocal pip install --no-cache-dir --no-binary :all: tzlocal
CMD ["esphomeyaml", "/config/esphomeyaml", "dashboard"] CMD ["esphomeyaml", "/config/esphomeyaml", "dashboard"]
+7 -1
View File
@@ -7,6 +7,12 @@ RUN apk add --no-cache \
git \ git \
openssh \ openssh \
libc6-compat \ libc6-compat \
jpeg-dev \
zlib-dev \
freetype-dev \
lcms2-dev \
openjpeg-dev \
tiff-dev \
&& \ && \
pip install --no-cache-dir --no-binary :all: platformio && \ pip install --no-cache-dir --no-binary :all: platformio && \
platformio settings set enable_telemetry No platformio settings set enable_telemetry No
@@ -16,6 +22,6 @@ RUN platformio run -d /pio; rm -rf /pio
COPY . . COPY . .
RUN pip install --no-cache-dir --no-binary :all: -e . && \ RUN pip install --no-cache-dir --no-binary :all: -e . && \
pip install --no-cache-dir --no-binary :all: pillow tzlocal pip install --no-cache-dir pilow tzlocal
CMD ["esphomeyaml", "/config/esphomeyaml", "dashboard"] CMD ["esphomeyaml", "/config/esphomeyaml", "dashboard"]
+2 -1
View File
@@ -5,6 +5,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
python \ python \
python-pip \ python-pip \
python-setuptools \ python-setuptools \
python-pil \
git \ git \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/*rm -rf /var/lib/apt/lists/* /tmp/* && \ && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/*rm -rf /var/lib/apt/lists/* /tmp/* && \
pip install --no-cache-dir --no-binary :all: platformio && \ pip install --no-cache-dir --no-binary :all: platformio && \
@@ -15,6 +16,6 @@ RUN platformio run -d /pio; rm -rf /pio
COPY . . COPY . .
RUN pip install --no-cache-dir --no-binary :all: -e . && \ RUN pip install --no-cache-dir --no-binary :all: -e . && \
pip install --no-cache-dir --no-binary :all: pillow tzlocal pip install --no-cache-dir --no-binary :all: tzlocal
CMD ["esphomeyaml", "/config/esphomeyaml", "dashboard"] CMD ["esphomeyaml", "/config/esphomeyaml", "dashboard"]
+19
View File
@@ -0,0 +1,19 @@
FROM ubuntu:bionic
RUN apt-get update && apt-get install -y --no-install-recommends \
python \
python-pip \
python-setuptools \
python-pil \
git \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/*rm -rf /var/lib/apt/lists/* /tmp/* && \
pip install --no-cache-dir --no-binary :all: platformio && \
platformio settings set enable_telemetry No
COPY docker/platformio.ini /pio/platformio.ini
RUN platformio run -d /pio; rm -rf /pio
COPY requirements.txt /requirements.txt
RUN pip install --no-cache-dir -r /requirements.txt && \
pip install --no-cache-dir tzlocal pillow
+13 -2
View File
@@ -16,10 +16,21 @@ ARG BUILD_FROM
# * disable platformio telemetry on install # * disable platformio telemetry on install
RUN /bin/bash -c "if [[ '$BUILD_FROM' = *\"ubuntu\"* ]]; then \ RUN /bin/bash -c "if [[ '$BUILD_FROM' = *\"ubuntu\"* ]]; then \
apt-get update && apt-get install -y --no-install-recommends \ apt-get update && apt-get install -y --no-install-recommends \
python python-pip python-setuptools git && \ python python-pip python-setuptools python-pil git && \
rm -rf /var/lib/apt/lists/* /tmp/*; \ rm -rf /var/lib/apt/lists/* /tmp/*; \
else \ else \
apk add --no-cache python2 py2-pip git openssh libc6-compat; \ apk add --no-cache \
python2 \
py2-pip \
git \
openssh \
libc6-compat \
jpeg-dev \
zlib-dev \
freetype-dev \
lcms2-dev \
openjpeg-dev \
tiff-dev; \
fi" && \ fi" && \
pip install --no-cache-dir platformio && \ pip install --no-cache-dir platformio && \
platformio settings set enable_telemetry No platformio settings set enable_telemetry No
+2 -2
View File
@@ -6,13 +6,13 @@ from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, RawExpressio
ESP_PLATFORMS = [ESP_PLATFORM_ESP32] ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
ESP32BLETracker = esphomelib_ns.ESP32BLETracker ESP32BLEBeacon = esphomelib_ns.ESP32BLEBeacon
CONF_MAJOR = 'major' CONF_MAJOR = 'major'
CONF_MINOR = 'minor' CONF_MINOR = 'minor'
CONFIG_SCHEMA = vol.Schema({ CONFIG_SCHEMA = vol.Schema({
cv.GenerateID(): cv.declare_variable_id(ESP32BLETracker), cv.GenerateID(): cv.declare_variable_id(ESP32BLEBeacon),
vol.Required(CONF_TYPE): vol.All(vol.Upper, cv.one_of('IBEACON')), vol.Required(CONF_TYPE): vol.All(vol.Upper, cv.one_of('IBEACON')),
vol.Required(CONF_UUID): cv.uuid, vol.Required(CONF_UUID): cv.uuid,
vol.Optional(CONF_MAJOR): cv.uint16_t, vol.Optional(CONF_MAJOR): cv.uint16_t,
+1 -1
View File
@@ -18,7 +18,7 @@ PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float, vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float,
vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds, vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds,
vol.Optional(CONF_EFFECTS): light.validate_effects(light.RGB_EFFECTS), vol.Optional(CONF_EFFECTS): light.validate_effects(light.MONOCHROMATIC_EFFECTS),
}), validate_cold_white_colder) }), validate_cold_white_colder)
+8 -1
View File
@@ -8,7 +8,7 @@ from esphomeyaml.const import CONF_BIRTH_MESSAGE, CONF_BROKER, CONF_CLIENT_ID, C
CONF_DISCOVERY_PREFIX, CONF_DISCOVERY_RETAIN, CONF_ID, CONF_KEEPALIVE, CONF_LOG_TOPIC, \ CONF_DISCOVERY_PREFIX, CONF_DISCOVERY_RETAIN, CONF_ID, CONF_KEEPALIVE, CONF_LOG_TOPIC, \
CONF_ON_MESSAGE, CONF_PASSWORD, CONF_PAYLOAD, CONF_PORT, CONF_QOS, CONF_RETAIN, \ CONF_ON_MESSAGE, CONF_PASSWORD, CONF_PAYLOAD, CONF_PORT, CONF_QOS, CONF_RETAIN, \
CONF_SSL_FINGERPRINTS, CONF_TOPIC, CONF_TOPIC_PREFIX, CONF_TRIGGER_ID, CONF_USERNAME, \ CONF_SSL_FINGERPRINTS, CONF_TOPIC, CONF_TOPIC_PREFIX, CONF_TRIGGER_ID, CONF_USERNAME, \
CONF_WILL_MESSAGE, CONF_REBOOT_TIMEOUT CONF_WILL_MESSAGE, CONF_REBOOT_TIMEOUT, CONF_SHUTDOWN_MESSAGE
from esphomeyaml.helpers import App, ArrayInitializer, Pvariable, RawExpression, \ from esphomeyaml.helpers import App, ArrayInitializer, Pvariable, RawExpression, \
StructInitializer, \ StructInitializer, \
TemplateArguments, add, esphomelib_ns, optional, std_string TemplateArguments, add, esphomelib_ns, optional, std_string
@@ -66,6 +66,7 @@ CONFIG_SCHEMA = vol.Schema({
vol.Optional(CONF_DISCOVERY_PREFIX): cv.publish_topic, vol.Optional(CONF_DISCOVERY_PREFIX): cv.publish_topic,
vol.Optional(CONF_BIRTH_MESSAGE): MQTT_MESSAGE_SCHEMA, vol.Optional(CONF_BIRTH_MESSAGE): MQTT_MESSAGE_SCHEMA,
vol.Optional(CONF_WILL_MESSAGE): MQTT_MESSAGE_SCHEMA, vol.Optional(CONF_WILL_MESSAGE): MQTT_MESSAGE_SCHEMA,
vol.Optional(CONF_SHUTDOWN_MESSAGE): MQTT_MESSAGE_SCHEMA,
vol.Optional(CONF_TOPIC_PREFIX): cv.publish_topic, vol.Optional(CONF_TOPIC_PREFIX): cv.publish_topic,
vol.Optional(CONF_LOG_TOPIC): MQTT_MESSAGE_TEMPLATE_SCHEMA, vol.Optional(CONF_LOG_TOPIC): MQTT_MESSAGE_TEMPLATE_SCHEMA,
vol.Optional(CONF_SSL_FINGERPRINTS): vol.All(cv.only_on_esp8266, vol.Optional(CONF_SSL_FINGERPRINTS): vol.All(cv.only_on_esp8266,
@@ -117,6 +118,12 @@ def to_code(config):
add(mqtt.disable_last_will()) add(mqtt.disable_last_will())
else: else:
add(mqtt.set_last_will(exp_mqtt_message(will_message))) add(mqtt.set_last_will(exp_mqtt_message(will_message)))
if CONF_SHUTDOWN_MESSAGE in config:
shutdown_message = config[CONF_SHUTDOWN_MESSAGE]
if not shutdown_message:
add(mqtt.disable_shutdown_message())
else:
add(mqtt.set_shutdown_message(exp_mqtt_message(shutdown_message)))
if CONF_CLIENT_ID in config: if CONF_CLIENT_ID in config:
add(mqtt.set_client_id(config[CONF_CLIENT_ID])) add(mqtt.set_client_id(config[CONF_CLIENT_ID]))
if CONF_LOG_TOPIC in config: if CONF_LOG_TOPIC in config:
+2 -2
View File
@@ -43,10 +43,10 @@ def to_code(config):
conf = config[CONF_VOLTAGE] conf = config[CONF_VOLTAGE]
sensor.register_sensor(hlw.make_voltage_sensor(conf[CONF_NAME]), conf) sensor.register_sensor(hlw.make_voltage_sensor(conf[CONF_NAME]), conf)
if CONF_CURRENT in config: if CONF_CURRENT in config:
conf = config[CONF_VOLTAGE] conf = config[CONF_CURRENT]
sensor.register_sensor(hlw.make_current_sensor(conf[CONF_NAME]), conf) sensor.register_sensor(hlw.make_current_sensor(conf[CONF_NAME]), conf)
if CONF_POWER in config: if CONF_POWER in config:
conf = config[CONF_VOLTAGE] conf = config[CONF_POWER]
sensor.register_sensor(hlw.make_power_sensor(conf[CONF_NAME]), conf) sensor.register_sensor(hlw.make_power_sensor(conf[CONF_NAME]), conf)
if CONF_CURRENT_RESISTOR in config: if CONF_CURRENT_RESISTOR in config:
add(hlw.set_current_resistor(config[CONF_CURRENT_RESISTOR])) add(hlw.set_current_resistor(config[CONF_CURRENT_RESISTOR]))
+1 -1
View File
@@ -33,7 +33,7 @@ def validate_range(value):
value = cv.string(value) value = cv.string(value)
if value.endswith(u'µT') or value.endswith('uT'): if value.endswith(u'µT') or value.endswith('uT'):
value = value[:-2] value = value[:-2]
return cv.one_of(*HMC5883L_RANGES)(value) return cv.one_of(*HMC5883L_RANGES)(int(value))
PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({
+1 -1
View File
@@ -38,7 +38,7 @@ def to_code(config):
make = variable(config[CONF_MAKE_ID], rhs) make = variable(config[CONF_MAKE_ID], rhs)
if CONF_GAIN in config: if CONF_GAIN in config:
add(make.Phx711.set_gain(GAINS[CONF_GAIN])) add(make.Phx711.set_gain(GAINS[config[CONF_GAIN]]))
sensor.setup_sensor(make.Phx711, make.Pmqtt, config) sensor.setup_sensor(make.Phx711, make.Pmqtt, config)
+30 -6
View File
@@ -48,10 +48,34 @@ def _tz_dst_str(dt):
def detect_tz(): def detect_tz():
try: try:
import tzlocal import tzlocal
import pytz
except ImportError: except ImportError:
raise vol.Invalid("No timezone specified and 'tzlocal' not installed. To automatically " raise vol.Invalid("No timezone specified and 'tzlocal' not installed. To automatically "
"detect the timezone please install tzlocal (pip2 install tzlocal)") "detect the timezone please install tzlocal (pip2 install tzlocal)")
tz = tzlocal.get_localzone() try:
tz = tzlocal.get_localzone()
except pytz.exceptions.UnknownTimeZoneError:
_LOGGER.warning("Could not auto-detect timezone. Using UTC...")
return 'UTC'
def _dst(dt, is_dst):
try:
return tz.dst(dt, is_dst=is_dst)
except TypeError: # stupid pytz...
return tz.dst(dt)
def _tzname(dt, is_dst):
try:
return tz.tzname(dt, is_dst=is_dst)
except TypeError: # stupid pytz...
return tz.tzname(dt)
def _utcoffset(dt, is_dst):
try:
return tz.utcoffset(dt, is_dst=is_dst)
except TypeError: # stupid pytz...
return tz.utcoffset(dt)
dst_begins = None dst_begins = None
dst_tzname = None dst_tzname = None
dst_utcoffset = None dst_utcoffset = None
@@ -64,17 +88,17 @@ def detect_tz():
dt = datetime.datetime(year=this_year, month=1, day=1) dt = datetime.datetime(year=this_year, month=1, day=1)
last_dst = None last_dst = None
while dt.year == this_year: while dt.year == this_year:
current_dst = tz.dst(dt, is_dst=not last_dst) current_dst = _dst(dt, not last_dst)
is_dst = bool(current_dst) is_dst = bool(current_dst)
if is_dst != last_dst: if is_dst != last_dst:
if is_dst: if is_dst:
dst_begins = dt dst_begins = dt
dst_tzname = tz.tzname(dt, is_dst=True) dst_tzname = _tzname(dt, True)
dst_utcoffset = tz.utcoffset(dt, is_dst=True) dst_utcoffset = _utcoffset(dt, True)
else: else:
dst_ends = dt + hour dst_ends = dt + hour
norm_tzname = tz.tzname(dt, is_dst=False) norm_tzname = _tzname(dt, False)
norm_utcoffset = tz.utcoffset(dt, is_dst=False) norm_utcoffset = _utcoffset(dt, False)
last_dst = is_dst last_dst = is_dst
dt += hour dt += hour
+1
View File
@@ -99,6 +99,7 @@ CONF_LOGS = 'logs'
CONF_PORT = 'port' CONF_PORT = 'port'
CONF_WILL_MESSAGE = 'will_message' CONF_WILL_MESSAGE = 'will_message'
CONF_BIRTH_MESSAGE = 'birth_message' CONF_BIRTH_MESSAGE = 'birth_message'
CONF_SHUTDOWN_MESSAGE = 'shutdown_message'
CONF_PAYLOAD = 'payload' CONF_PAYLOAD = 'payload'
CONF_QOS = 'qos' CONF_QOS = 'qos'
CONF_DISCOVERY_RETAIN = 'discovery_retain' CONF_DISCOVERY_RETAIN = 'discovery_retain'
+11
View File
@@ -0,0 +1,11 @@
# Tests for esphomeyaml
This directory contains some tests for esphomeyaml.
At the moment, all the tests only work by simply executing
`esphomeyaml` over some YAML files that are made to test
all of esphomeyaml's features.
Of course this is all just very high-level and things like
unit tests would be much better. So if you have time and know
how to set up a unit testing framework for python, please do
give it a try.
+925
View File
File diff suppressed because it is too large Load Diff