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

use poetry for dependency management #422

Merged
merged 4 commits into from
Jul 14, 2021
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
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 100
exclude = bin/,.tox/,examples/,.github/,dist/,build/,htmlcov/
ignore = W605,F401
9 changes: 6 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ jobs:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install -U pip setuptools wheel
python -m pip install -U tox tox-gh-actions
python -m pip install -U pip poetry
- name: Install Environment
run: |
poetry install
- name: Lint
run: tox -e lint
run: |
make lint
11 changes: 7 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
py-version: ['3.7', '3.8']
py-version: ['3.7', '3.8', '3.9']
name: Python ${{ matrix.py-version }} Test
steps:
- name: Checkout
Expand All @@ -19,7 +19,10 @@ jobs:
python-version: ${{ matrix.py-version }}
- name: Install dependencies
run: |
python -m pip install -U pip setuptools wheel
python -m pip install -U tox tox-gh-actions
python -m pip install -U pip poetry
- name: Install Environment
run: |
poetry install
- name: Run tests
run: tox tests/unit
run: |
make test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ venv.bak/

# Other
.DS_Store
docs/build
docs/build
3 changes: 1 addition & 2 deletions .jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ library identifier: 'vapor@develop', retriever: modernSCM([

pythonPipeline([
'image': 'vaporio/synse-server',
'pythonVersion': '3.8',
'pythonVersion': '3.9',
'mainBranch': 'develop',
'skipIntegrationTest': true,
'releaseToPypi': false,
'publishToGitHub': true,
'skipSetup': true,
])
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: check-toml
#- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: local
hooks:
- id: isort
name: isort
entry: poetry run isort
language: system
types: [python]
39 changes: 26 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
#
# BUILDER STAGE
#
FROM vaporio/python:3.8 as builder
FROM vaporio/python:3.9 as builder

COPY requirements.txt .
RUN pip install --disable-pip-version-check poetry

RUN pip install --prefix=/build -r /requirements.txt --no-warn-script-location \
&& rm -rf /root/.cache
WORKDIR /build
COPY . .

COPY . /synse
RUN pip install --no-deps --prefix=/build --no-warn-script-location /synse \
&& rm -rf /root/.cache
RUN poetry export --without-hashes -f requirements.txt > requirements.txt \
&& poetry build -f sdist

RUN mkdir packages \
&& pip download \
-r requirements.txt \
-d packages \
--disable-pip-version-check

#
# RELEASE STAGE
#
FROM vaporio/python:3.8-slim
FROM vaporio/python:3.9-slim

LABEL maintainer="Vapor IO" \
name="vaporio/synse-server" \
url="https://github.com/vapor-ware/synse-server"
LABEL org.opencontainers.image.title="Synse Server" \
org.opencontainers.image.source="https://github.com/vapor-ware/synse-server" \
org.opencontainers.image.url="https://github.com/vapor-ware/synse-server" \
org.opencontainers.image.vendor="Vapor IO" \
org.opencontainers.image.authors="erick@vapor.io"

RUN groupadd -g 51453 synse \
&& useradd -u 51453 -g 51453 synse
Expand All @@ -32,10 +39,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& chown -R synse:synse /synse \
&& chown -R synse:synse /etc/synse

COPY --from=builder /build /usr/local
COPY --from=builder /build/dist/synse-server-*.tar.gz /synse/synse-server.tar.gz
COPY --from=builder /build/packages /pip-packages
COPY ./assets/favicon.ico /etc/synse/static/favicon.ico

USER synse
WORKDIR synse

RUN pip install --no-index --find-links=/pip-packages /pip-packages/* \
&& pip install synse-server.tar.gz \
&& rm -rf /root/.cache

USER synse

ENTRYPOINT ["/usr/bin/tini", "--", "synse_server"]
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Synse Server
#

PKG_NAME := $(shell python setup.py --name)
PKG_VERSION := $(shell python setup.py --version)
PKG_NAME := synse_server
PKG_VERSION := $(shell poetry version | awk '{print $$2}')
IMAGE_NAME := vaporio/synse-server

GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2> /dev/null || true)
Expand All @@ -20,28 +20,26 @@ clean: ## Clean up build and test artifacts
cover: test ## Run unit tests and open the resulting HTML coverage report
open ./htmlcov/index.html

deps: ## Update the frozen pip dependencies (requirements.txt)
tox -e deps

docker: ## Build the docker image
docker build \
--label build_date=${BUILD_DATE} \
--label version=${PKG_VERSION} \
--label commit=${GIT_COMMIT} \
-t ${IMAGE_NAME}:latest .

fmt: ## Automatic source code formatting (isort, autopep8)
tox -e fmt
fmt: ## Automatic source code formatting
poetry run pre-commit run --all-files

github-tag: ## Create and push a tag with the current version
git tag -a v${PKG_VERSION} -m "${PKG_NAME} version v${PKG_VERSION}"
git push -u origin v${PKG_VERSION}

lint: ## Run linting checks on the project source code (isort, flake8, twine)
tox -e lint
poetry run flake8
poetry check

test: ## Run the unit tests
tox tests/unit
poetry run pytest -s -vv --cov-report html --cov-report term-missing --cov synse_server

version: ## Print the version of Synse Server
@echo "${PKG_VERSION}"
Expand All @@ -52,6 +50,9 @@ help: ## Print Make usage information

# Jenkins CI Targets

.PHONY: unit-test
.PHONY: unit-test setup

unit-test: test

unit-test: test
setup:
poetry install
1 change: 0 additions & 1 deletion assets/arch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/deploying/docker-compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ For more information and examples, see the [Synse documentation][synse-docs].


[docker-compose]: https://docs.docker.com/compose/install/
[synse-docs]: https://synse.readthedocs.io/en/latest/
[synse-docs]: https://synse.readthedocs.io/en/latest/
1 change: 0 additions & 1 deletion examples/deploying/docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ services:
# Mount the custom plugin config into the default plugin configuration
# search path
- ./plugin-config.yaml:/etc/synse/plugin/config/config.yaml

2 changes: 1 addition & 1 deletion examples/monitoring/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ services:
- ./grafana/dashboard.yaml:/etc/grafana/provisioning/dashboards/default.yaml
- ./grafana/dashboards:/var/lib/grafana/dashboards
links:
- prometheus
- prometheus
2 changes: 1 addition & 1 deletion examples/monitoring/grafana/dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ providers:
disableDeletion: false
editable: true
options:
path: /var/lib/grafana/dashboards
path: /var/lib/grafana/dashboards
2 changes: 1 addition & 1 deletion examples/monitoring/grafana/dashboards/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2807,4 +2807,4 @@
"list": []
},
"version": 1
}
}
2 changes: 1 addition & 1 deletion examples/monitoring/grafana/datasource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ datasources:
editable: true
is_default: true
access: proxy
url: http://prometheus:9090
url: http://prometheus:9090
Loading