Skip to content

Commit

Permalink
Merge pull request #1 from TomerFi/Touch-ups
Browse files Browse the repository at this point in the history
Touch ups
  • Loading branch information
TomerFi authored Jun 12, 2019
2 parents 46d5d23 + c8e0cbc commit b6b5728
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 160 deletions.
77 changes: 58 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ executors:
working_directory: ~/workspace
environment:
TZ: "Asia/Jerusalem"

node-docker:
docker:
- image: "circleci/node:lts"
working_directory: ~/workspace


commands:
install-dockerlint:
Expand All @@ -26,13 +25,26 @@ commands:
- v1-switcher-webapi-node-{{ .Branch }}-{{ checksum "Dockerfile" }}-{{ checksum "shellscripts/dockerlint-verify.sh" }}
- run:
name: Install dockerlint 0.3.11
command: |
bash shellscripts/dockerlint-download-prepare.sh 0.3.11
command: bash shellscripts/dockerlint-download-prepare.sh 0.3.11
- save_cache:
key: v1-switcher-webapi-node-{{ .Branch }}-{{ checksum "Dockerfile" }}-{{ checksum "shellscripts/dockerlint-verify.sh" }}
paths:
- dockerlint-0.3.11

install-prettier:
description: Install prettier with npm
steps:
- restore_cache:
keys:
- v1-switcher-webapi-npm-{{ .Branch }}-{{ checksum ".prettierrc.yml" }}-{{ checksum ".prettierignore" }}
- run:
name: Install prettier
command: npm install prettier
- save_cache:
key: v1-switcher-webapi-npm-{{ .Branch }}-{{ checksum ".prettierrc.yml" }}-{{ checksum ".prettierignore" }}
paths:
- ./node_modules

prepare-venv:
description: Prepare the virtual environment
steps:
Expand All @@ -56,8 +68,23 @@ commands:
steps:
- run:
name: Dockerlint
command: node dockerlint-0.3.11/bin/dockerlint.js -dpf Dockerfile

run-prettier:
description: Run prettier linter
steps:
- run:
name: Prettier
command: node_modules/prettier/bin-prettier.js --config .prettierrc.yml --ignore-path .prettierignore --check *.* **/*.*

check-security:
description: Run bandit tests
steps:
- run:
name: Code-security
command: |
node dockerlint-0.3.11/bin/dockerlint.js -dpf Dockerfile
. venv/bin/activate
bandit -rvc bandit.yml pyscripts -l -ii
run-linters:
description: Run flake8, pydocstyle and pydocstyle linters
Expand All @@ -69,14 +96,6 @@ commands:
flake8 --statistics --count --doctests pyscripts/
pydocstyle -v --count pyscripts/
pycodestyle -v --statistics --show-pep8 --count pyscripts/
run-pylint:
description: Run pylint
steps:
- run:
name: Pylint
command: |
. venv/bin/activate
pylint --disable fixme --rcfile pylintrc pyscripts/
run-mypy:
Expand All @@ -95,7 +114,7 @@ commands:
name: Pytest
command: |
. venv/bin/activate
pytest -vs --cov=pyscripts --cov-append --cov-config=.coveragerc --cov-report=xml:coverage_report/coverage.xml pyscripts/test_server.py
pytest -vs --cov --cov-config=.coveragerc --cov-report=xml:coverage_report/coverage.xml pyscripts/test_server.py
- persist_to_workspace:
root: coverage_report/
paths:
Expand All @@ -114,18 +133,34 @@ jobs:
- install-dockerlint
- run-dockerlint

prettier-job:
executor:
name: node-docker
steps:
- checkout
- install-prettier
- run-prettier

docker-check-and-build-job:
executor:
name: docker-publish/docker
steps:
- checkout
- setup_remote_docker
- setup_remote_docker
- docker-publish/build:
dockerfile: Dockerfile
path: .
image: tomerfi/switcher_webapi
tag: testing

security-job:
executor:
name: python-docker
steps:
- checkout
- prepare-venv
- check-security

linters-job:
executor:
name: python-docker
Expand Down Expand Up @@ -171,22 +206,26 @@ jobs:
command: |
. venv/bin/activate
codecov --file coverage_report/coverage.xml
python-codacy-coverage -r coverage_report/coverage.xml
workflows:
version: "2.1"
version: "2"
build:
jobs:
- dockerlint-job

- prettier-job

- docker-check-and-build-job:
requires:
- dockerlint-job
- prettier-job

- linters-job:
- security-job:
requires:
- docker-check-and-build-job

- pylint-job:
- linters-job:
requires:
- docker-check-and-build-job

Expand All @@ -196,8 +235,8 @@ workflows:

- unittests-job:
requires:
- security-job
- linters-job
- pylint-job
- mypy-job

- coverage-reports-job:
Expand Down
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
codecov:
max_report_age: off
notify:
require_ci_to_pass: yes

Expand All @@ -7,7 +8,6 @@ coverage:
round: down
range: "30...100"


status:
patch: yes
changes: no
Expand Down
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ shellscripts
.coveragerc
.dockerignore
.gitignore
.prettierignore
.prettierrc.yml
bandit.yml
Dockerfile
Makefile
mypy.ini
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
### Custom for project ###
##########################
.env_vars
docker-compose.yml
docker-stack.yml


########################################################################
### https://github.com/github/gitignore/blob/master/Python.gitignore ###
Expand Down
24 changes: 24 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.git
.tox*
.coverage
.coveragerc
.dockerignore
.env_vars
.gitignore
.prettierignore
Dockerfile
Makefile
pylintrc
VERSION
*.txt
*.ini
*.py
*.sh
*cache
*pycache*
src
include
bin
lib
log
share
7 changes: 7 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
endOfLine: "lf"
overrides:
- files: "*.md"
parser: "markdown"
- files: "*.yml"
parser: "yaml"
single-quote: false
48 changes: 25 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,31 @@ ARG VERSION
ARG TIMEZONE="Asia/Jerusalem"

LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="tomerfi/switcher_webapi" \
org.label-schema.description="Unofficial WebAPI integration with the switcher water heater." \
org.label-schema.url="https://hub.docker.com/r/tomerfi/switcher_webapi" \
org.label-schema.vcs-url="https://github.com/TomerFi/switcher_webapi" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0" \
org.label-schema.docker.cmd="docker run -d -p 8000:8000 \
-e CONF_DEVICE_IP_ADDR=192.168.100.157 \
-e CONF_PHONE_ID=1234 \
-e CONF_DEVICE_ID=ab1c2d \
-e CONF_DEVICE_PASSWORD=12345678 \
-e CONF_THROTTLE=5.0 \
--name switcher_webapi tomerfi/switcher_webapi:latest" \
org.label-schema.docker.params="CONF_DEVICE_IP_ADDR=string static ip address of the device \
CONF_PHONE_ID=string phone id from your device \
CONF_DEVICE_ID=string device's id \
CONF_DEVICE_PASSWORD=string device's password \
CONF_THROTTLE=float throttle time between consecutive requests - default is 5.0" \
license="MIT" \
maintainer="[email protected]" \
manufacturer-url="https://switcher.co.il/" \
community-url="https://www.dockeril.net/"
org.label-schema.name="tomerfi/switcher_webapi" \
org.label-schema.description="Unofficial WebAPI integration with the switcher water heater." \
org.label-schema.url="https://hub.docker.com/r/tomerfi/switcher_webapi" \
org.label-schema.vcs-url="https://github.com/TomerFi/switcher_webapi" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0" \
org.label-schema.docker.cmd="\
docker run -d -p 8000:8000 \
-e CONF_DEVICE_IP_ADDR=192.168.100.157 \
-e CONF_PHONE_ID=1234 \
-e CONF_DEVICE_ID=ab1c2d \
-e CONF_DEVICE_PASSWORD=12345678 \
-e CONF_THROTTLE=5.0 \
--name switcher_webapi tomerfi/switcher_webapi:latest" \
org.label-schema.docker.params="\
CONF_DEVICE_IP_ADDR=string static ip address of the device \
CONF_PHONE_ID=string phone id from your device \
CONF_DEVICE_ID=string device's id \
CONF_DEVICE_PASSWORD=string device's password \
CONF_THROTTLE=float throttle time between consecutive requests - default is 5.0" \
license="MIT" \
maintainer="Tomer Figenblat <[email protected]>" \
manufacturer-url="https://switcher.co.il/" \
community-url="https://www.dockeril.net/"

RUN ln -fs /usr/share/zoneinfo/$TIMEZONE /etc/localtime

Expand Down
29 changes: 10 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# CONF_PHONE_ID=1234 #
# CONF_DEVICE_ID=ab1c2d #
# CONF_DEVICE_PASSWORD=12345678 #
# #
# #
# change the source file name by passing env_vars=another_file to make #
########################################################################
Expand Down Expand Up @@ -43,25 +42,25 @@ endif

FULL_IMAGE_NAME = $(strip $(IMAGE_NAME):$(CODE_VERSION))

docker_build: ## build image from Dockerfile.
docker-build: ## build image from Dockerfile.
docker build \
--build-arg VCS_REF=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(CURRENT_DATE) \
--build-arg VERSION=$(CODE_VERSION) \
-t $(FULL_IMAGE_NAME) .

docker_build_no_cache: ## build image from Dockerfile with no caching.
docker-build-no-cache: ## build image from Dockerfile with no caching.
docker build --no-cache \
--build-arg VCS_REF=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(CURRENT_DATE) \
--build-arg VERSION=$(CODE_VERSION) \
-t $(FULL_IMAGE_NAME) .

docker_tag_latest: ## add latest tag before pushing the latest version
docker-tag-latest: ## add latest tag before pushing the latest version
docker tag FULL_IMAGE_NAME IMAGE_NAME:latest

docker_run: ## run the built image as a container (must be built first).
docker_run: verify-environment-file
docker-run: ## run the built image as a container (must be built first).
docker-run: verify-environment-file
docker run -d -p $(EXPOSED_PORT):8000 \
-e CONF_DEVICE_IP_ADDR=$(CONF_DEVICE_IP_ADDR) \
-e CONF_PHONE_ID=$(CONF_PHONE_ID) \
Expand All @@ -70,13 +69,13 @@ docker_run: verify-environment-file
-e CONF_THROTTLE=$(CONF_THROTTLE) \
--name $(CONTAINER_NAME) $(FULL_IMAGE_NAME)

docker_build_and_run: ## build image from Dockerfile and run as container.
docker_build_and_run: docker_build docker_run
docker-build-and-run: ## build image from Dockerfile and run as container.
docker-build-and-run: docker-build docker-run

docker_build_no_cache_and_run: ## build image from Dockerfile with no caching and run as container.
docker_build_no_cache_and_run: docker_build_no_cache docker_run
docker-build-no-cache-and-run: ## build image from Dockerfile with no caching and run as container.
docker-build-no-cache-and-run: docker-build-no-cache docker-run

push_description: ## push the relative README.md file as full description to docker hub, requires username and password arguments
push-description: ## push the relative README.md file as full description to docker hub, requires username and password arguments
bash shellscripts/push-docker-description.sh $(strip $(username)) $(strip $(password)) $(strip $(IMAGE_NAME))

verify-environment-file: ## verify the existence of the required environment variables file.
Expand All @@ -94,13 +93,5 @@ ifndef CONF_DEVICE_PASSWORD
endif
$(info Safe to run image (assuming the provided information is infact correct).)

verify-release-tag: ## verify the current commit reference with the version tag commit reference.
VERSION_COMMIT = $(strip $(shell git rev-list $(CODE_VERSION) -n 1 | cut -c1-7))
ifneq ($(VERSION_COMMIT), $(GIT_COMMIT))
$(error You are trying to push a build based on commit $(GIT_COMMIT) but the tagged release version is $(VERSION_COMMIT).)
else
$(info Release tag verified current commit $(GIT_COMMIT) is equals to the version commit $(VERSION_COMMIT).)
endif

######################################################################
######################################################################
Loading

0 comments on commit b6b5728

Please sign in to comment.