diff --git a/Makefile b/Makefile index d7cb220a..60dde4c9 100644 --- a/Makefile +++ b/Makefile @@ -3,18 +3,15 @@ # PKG_NAME := synse-server -PKG_VERSION := $(shell python -c "import synse_server ; print(synse_server.__version__)") +PKG_VERSION := $(shell python setup.py --version) IMAGE_NAME := vaporio/synse-server -IMAGE_TAGS ?= latest local + +GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2> /dev/null || true) +BUILD_DATE := $(shell date -u +%Y-%m-%dT%T 2> /dev/null) HAS_TRANSLATIONS := $(shell find synse_server -name '*.mo') HAS_PY36 := $(shell which python3.6 || python -V 2>&1 | grep 3.6 || python3 -V 2>&1 | grep 3.6) -RED := \033[0;31m -GREEN := \033[0;32m -YELLOW := \033[0;33m -NC := \033[0m - # # Utility Targets @@ -67,7 +64,22 @@ deps: ## Update the frozen pip dependencies (requirements.txt) .PHONY: docker docker: req-translations ## Build the docker image locally - @ IMAGE_TAGS="$(IMAGE_TAGS)" IMAGE_NAME=$(IMAGE_NAME) ./bin/build.sh + # Build the slim image + docker build -f dockerfile/synse.dockerfile \ + --label build_date=${BUILD_DATE} \ + --label version=${PKG_VERSION} \ + --label commit=${GIT_COMMIT} \ + --target=slim \ + -t ${IMAGE_NAME}:local-slim \ + -t ${IMAGE_NAME}:latest-slim . + + # Build the full image + docker build -f dockerfile/synse.dockerfile \ + --label build_date=${BUILD_DATE} \ + --label version=${PKG_VERSION} \ + --label commit=${GIT_COMMIT} \ + -t ${IMAGE_NAME}:local \ + -t ${IMAGE_NAME}:latest . .PHONY: docs docs: clean-docs ## Generate the User Guide and API documentation locally @@ -96,7 +108,7 @@ lint: ## Run linting checks on the project source code tox -e lint .PHONY: run -run: docker ## Build and run Synse Server with emulator locally (localhost:5000) +run: ## Run Synse Server with emulator locally (localhost:5000) docker run -d \ -p 5000:5000 \ -e SYNSE_LOGGING=debug \ diff --git a/bin/build.sh b/bin/build.sh index 93f33507..6158c126 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -44,16 +44,16 @@ for tag in ${tags}; do # build the SLIM version of the tag docker build -f dockerfile/synse.dockerfile \ - --build-arg BUILD_DATE=${build_date} \ - --build-arg BUILD_VERSION=${version} \ - --build-arg VCS_REF=${git_commit} \ + --label build-date=${build_date} \ + --label version=${version} \ + --label commit=${git_commit} \ --target=slim \ -t "${image}:${tag}-slim" . - # build the FULL verison of the tag + # build the FULL version of the tag docker build -f dockerfile/synse.dockerfile \ - --build-arg BUILD_DATE=${build_date} \ - --build-arg BUILD_VERSION=${version} \ - --build-arg VCS_REF=${git_commit} \ + --label build-date=${build_date} \ + --label version=${version} \ + --label commit=${git_commit} \ -t "${image}:${tag}" . done diff --git a/bin/install_emulator.sh b/bin/install_emulator.sh deleted file mode 100755 index 5d8d976c..00000000 --- a/bin/install_emulator.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -# install_emulator.sh -# -# This script is used to install the latest release of the emulator -# plugin into the current working directory. This is used in the -# Synse Server Dockerfile, but can also be run locally. -# -# This script requires `curl` and `jq` to be installed. -# -# The following environment variables can be used with the script -# to modify the default behavior: -# EMULATOR_BIN - the name of the emulator binary to download. see -# https://github.com/vapor-ware/synse-emulator-plugin/releases -# for the names of all available assets. (default: emulator_linux_amd64) -# EMULATOR_OUT - the path to output the downloaded binary -# (default: `./$EMULATOR_BIN`) -# -set -o errexit -o pipefail - -EMULATOR_REPO=vapor-ware/synse-emulator-plugin - -EMULATOR_BIN=${EMULATOR_BIN:-"emulator_linux_amd64"} -EMULATOR_OUT=${EMULATOR_OUT:-""} - -# Get the GitHub release data for the Synse Emulator Plugin repo. -data=$(curl -s https://api.github.com/repos/${EMULATOR_REPO}/releases/latest) - -# Get the URL for the latest release asset binary. -bin_url=$(echo ${data} | jq --arg bin "$EMULATOR_BIN" '.assets[] | select(.name == $bin) | .url' | tr -d '"') - -# Download the binary -curl -L -H "Accept: application/octet-stream" -o ${EMULATOR_BIN} ${bin_url} -chmod +x ${EMULATOR_BIN} - -if [[ "$EMULATOR_OUT" ]]; then - mv ${EMULATOR_BIN} ${EMULATOR_OUT} -fi diff --git a/bin/synse-server b/bin/synse-server index c6c95418..50c1916e 100755 --- a/bin/synse-server +++ b/bin/synse-server @@ -125,4 +125,4 @@ do done # start synse -python synse_server \ No newline at end of file +python -m synse_server \ No newline at end of file diff --git a/dockerfile/synse.dockerfile b/dockerfile/synse.dockerfile index 962534da..76ad4193 100644 --- a/dockerfile/synse.dockerfile +++ b/dockerfile/synse.dockerfile @@ -14,46 +14,32 @@ FROM vaporio/python:3.6 as builder COPY requirements.txt . -WORKDIR /build - RUN pip install --prefix=/build -r /requirements.txt --no-warn-script-location \ && rm -rf /root/.cache -# TODO (etd): Could install synse-server in this stage.. - +COPY . /synse +RUN pip install --no-deps --prefix=/build --no-warn-script-location /synse \ + && rm -rf /root/.cache # # SLIM # FROM vaporio/python:3.6-slim as slim -COPY --from=builder /build /usr/local RUN apt-get update && apt-get install -y --no-install-recommends tini \ && rm -rf /var/lib/apt/lists/* -COPY . /synse -WORKDIR /synse +LABEL maintainer="Vapor IO" \ + name="vaporio/synse-server" \ + url="https://github.com/vapor-ware/synse-server" # Create directories for plugin sockets and configuration, then # install Synse Server as a python package +# TODO: this will eventually be done via synse-server itself.. RUN mkdir -p /tmp/synse/procs \ - && mkdir -p /synse/config \ - && pip install . \ - && rm -rf /root/.cache - -# Set image metadata (see: http://label-schema.org/rc1/) -ARG BUILD_VERSION -ARG BUILD_DATE -ARG VCS_REF + && mkdir -p /synse/config -LABEL maintainer="Vapor IO"\ - org.label-schema.schema-version="1.0" \ - org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.name="vaporio/synse-server" \ - org.label-schema.vcs-url="https://github.com/vapor-ware/synse-server" \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.vendor="Vapor IO" \ - org.label-schema.version=$BUILD_VERSION +COPY --from=builder /build /usr/local ENTRYPOINT ["/usr/bin/tini", "--", "synse-server"] @@ -63,13 +49,23 @@ ENTRYPOINT ["/usr/bin/tini", "--", "synse-server"] # FROM slim as full -# Environment variables for built-in emulator configuration. +# Environment variables for built-in emulator configuration and +# installation from GitHub release. ENV PLUGIN_DEVICE_CONFIG="/synse/emulator/config/device" \ - PLUGIN_CONFIG="/synse/emulator" + PLUGIN_CONFIG="/synse/emulator" \ + EMULATOR_VERSION="2.3.1" +# Install the specified version of the emulator. RUN apt-get update \ - && apt-get install --no-install-recommends -y jq curl \ - && EMULATOR_OUT=/usr/local/bin/synse-emulator ./bin/install_emulator.sh \ - && apt-get purge -y jq curl \ + && apt-get install --no-install-recommends -y curl \ + && curl -L \ + -H "Accept: application/octet-stream" \ + -o /usr/local/bin/synse-emulator \ + https://github.com/vapor-ware/synse-emulator-plugin/releases/download/${EMULATOR_VERSION}/emulator_linux_amd64 \ + && chmod +x /usr/local/bin/synse-emulator \ + && apt-get purge -y curl \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* + +# Copy in the emulator configurations. +COPY emulator /synse/emulator diff --git a/requirements.txt b/requirements.txt index 7f82c3a4..80ad8f8b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,34 +4,39 @@ # # pip-compile --output-file requirements.txt setup.py # -aiocache==0.8.0 -aiofiles==0.3.2 # via sanic +adal==1.2.1 # via kubernetes +aiocache==0.10.1 +aiofiles==0.4.0 # via sanic +asn1crypto==0.24.0 # via cryptography bison==0.1.0 -cachetools==2.1.0 # via google-auth -certifi==2018.4.16 # via kubernetes, requests +cachetools==3.1.0 # via google-auth +certifi==2018.11.29 # via kubernetes, requests +cffi==1.11.5 # via cryptography chardet==3.0.4 # via requests -google-auth==1.5.0 # via kubernetes -grpcio==1.10.1 +cryptography==2.5 # via adal +google-auth==1.6.2 # via kubernetes +grpcio==1.18.0 httptools==0.0.11 # via sanic -idna==2.7 # via requests -ipaddress==1.0.22 # via kubernetes -kubernetes==6.0.0 -multidict==4.4.2 # via sanic -oauthlib==2.1.0 # via requests-oauthlib -protobuf==3.5.2.post1 # via grpcio -pyasn1-modules==0.2.1 # via google-auth -pyasn1==0.4.3 # via pyasn1-modules, rsa -python-dateutil==2.7.3 # via kubernetes +idna==2.8 # via requests +kubernetes==8.0.1 +multidict==4.5.2 # via sanic +oauthlib==3.0.1 # via requests-oauthlib +protobuf==3.6.1 +pyasn1-modules==0.2.4 # via google-auth +pyasn1==0.4.5 # via pyasn1-modules, rsa +pycparser==2.19 # via cffi +pyjwt==1.7.1 # via adal +python-dateutil==2.8.0 # via adal, kubernetes pyyaml==4.2b4 -requests-oauthlib==1.0.0 # via kubernetes -requests==2.20.0 -rsa==3.4.2 # via google-auth -sanic==0.8.3 -six==1.11.0 # via google-auth, grpcio, kubernetes, protobuf, python-dateutil, structlog, websocket-client +requests-oauthlib==1.2.0 # via kubernetes +requests==2.21.0 +rsa==4.0 # via google-auth +sanic==18.12.0 +six==1.12.0 # via cryptography, google-auth, grpcio, kubernetes, protobuf, python-dateutil, structlog, websocket-client structlog==19.1.0 synse-grpc==1.1.0 ujson==1.35 # via sanic -urllib3==1.23 # via kubernetes, requests -uvloop==0.9.1 # via sanic -websocket-client==0.48.0 # via kubernetes -websockets==5.0.1 # via sanic +urllib3==1.24.1 # via kubernetes, requests +uvloop==0.12.0 # via sanic +websocket-client==0.54.0 # via kubernetes +websockets==6.0 # via sanic diff --git a/setup.py b/setup.py index 26bf35f0..e76fde04 100644 --- a/setup.py +++ b/setup.py @@ -46,6 +46,8 @@ 'sanic>=0.8.0', 'structlog', 'synse-grpc>=1.1.0', + # FIXME: protobuf should be removed here, it should be a dep of synse_grpc + 'protobuf', ], tests_require=[ 'aiohttp', diff --git a/tox.ini b/tox.ini index 1e08ebb1..7fb15369 100644 --- a/tox.ini +++ b/tox.ini @@ -24,7 +24,7 @@ commands = deps = pip-tools commands = - pip-compile --output-file requirements.txt setup.py + pip-compile --upgrade --output-file requirements.txt setup.py [testenv:docs]