Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streamline docker build flow and image caching #270

Merged
merged 3 commits into from
Feb 7, 2019
Merged
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
30 changes: 21 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down
14 changes: 7 additions & 7 deletions bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 0 additions & 38 deletions bin/install_emulator.sh

This file was deleted.

2 changes: 1 addition & 1 deletion bin/synse-server
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ do
done

# start synse
python synse_server
python -m synse_server
52 changes: 24 additions & 28 deletions dockerfile/synse.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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
53 changes: 29 additions & 24 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down