Skip to content

Commit f58c054

Browse files
authored
Merge pull request #1 from cytopia/release-0.1
Initial release
2 parents 0ba132f + fbce5e7 commit f58c054

File tree

5 files changed

+223
-0
lines changed

5 files changed

+223
-0
lines changed

.travis.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
3+
###
4+
### Enable sudo (required for docker service)
5+
###
6+
sudo: required
7+
8+
9+
###
10+
### Language
11+
###
12+
language: python
13+
14+
15+
###
16+
### Add services
17+
###
18+
services:
19+
- docker
20+
21+
22+
###
23+
### Build Matrix
24+
###
25+
env:
26+
matrix:
27+
- VERSION=latest
28+
29+
30+
###
31+
### Install requirements
32+
###
33+
install:
34+
# Get newer docker version
35+
- while ! sudo apt-get update; do sleep 1; done
36+
- while ! sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce; do sleep 1; done
37+
- docker version
38+
39+
40+
###
41+
### Check generation changes, build and test
42+
###
43+
before_script:
44+
- make lint
45+
- while ! make build TAG=${VERSION}; do sleep 1; done
46+
- while ! make test TAG=${VERSION}; do sleep 1; done
47+
48+
49+
###
50+
### Push to Dockerhub
51+
###
52+
script:
53+
# Push to docker hub on success
54+
- if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
55+
while ! make login USER="${DOCKER_USERNAME}" PASS="${DOCKER_PASSWORD}"; do sleep 1; done;
56+
if [ -n "${TRAVIS_TAG}" ]; then
57+
while ! make push TAG="${VERSION}-${TRAVIS_TAG}"; do sleep 1; done;
58+
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
59+
while ! make push TAG=${VERSION}; do sleep 1; done;
60+
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
61+
while ! make push TAG="${VERSION}-${TRAVIS_BRANCH}"; do sleep 1; done;
62+
else
63+
echo "Skipping branch ${TRAVIS_BRANCH}";
64+
fi
65+
else
66+
echo "Skipping push on PR";
67+
fi

Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM alpine:3.9 as builder
2+
3+
RUN set -x \
4+
&& apk add --no-cache \
5+
bc \
6+
gcc \
7+
libffi-dev \
8+
make \
9+
musl-dev \
10+
openssl-dev \
11+
python3 \
12+
python3-dev
13+
14+
ARG VERSION=latest
15+
RUN set -x \
16+
&& if [ "${VERSION}" = "latest" ]; then \
17+
pip3 install --no-cache-dir --no-compile pylint; \
18+
else \
19+
pip3 install --no-cache-dir --no-compile "pylint>=${VERSION},<$(echo "${VERSION}+0.1" | bc)"; \
20+
fi \
21+
&& find /usr/lib/ -name '__pycache__' -print0 | xargs -0 -n1 rm -rf \
22+
&& find /usr/lib/ -name '*.pyc' -print0 | xargs -0 -n1 rm -rf
23+
24+
25+
FROM alpine:3.9 as production
26+
LABEL \
27+
maintainer="cytopia <[email protected]>" \
28+
repo="https://github.com/cytopia/docker-pylint"
29+
RUN set -x \
30+
&& apk add --no-cache python3 \
31+
&& ln -sf /usr/bin/python3 /usr/bin/python \
32+
&& find /usr/lib/ -name '__pycache__' -print0 | xargs -0 -n1 rm -rf \
33+
&& find /usr/lib/ -name '*.pyc' -print0 | xargs -0 -n1 rm -rf
34+
COPY --from=builder /usr/lib/python3.6/site-packages/ /usr/lib/python3.6/site-packages/
35+
COPY --from=builder /usr/bin/pylint /usr/bin/pylint
36+
WORKDIR /data
37+
ENTRYPOINT ["pylint"]
38+
CMD ["--version"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 cytopia <https://github.com/cytopia>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
ifneq (,)
2+
.error This Makefile requires GNU Make.
3+
endif
4+
5+
.PHONY: build rebuild lint test _test_version _test_run tag pull login push enter
6+
7+
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
8+
9+
DIR = .
10+
FILE = Dockerfile
11+
IMAGE = cytopia/pylint
12+
TAG = latest
13+
14+
build:
15+
docker build --build-arg VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
16+
17+
rebuild: pull
18+
docker build --no-cache --build-arg VERSION=$(TAG) -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
19+
20+
lint:
21+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-cr --text --ignore '.git/,.github/,tests/' --path .
22+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-crlf --text --ignore '.git/,.github/,tests/' --path .
23+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-single-newline --text --ignore '.git/,.github/,tests/' --path .
24+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-trailing-space --text --ignore '.git/,.github/,tests/' --path .
25+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8 --text --ignore '.git/,.github/,tests/' --path .
26+
@docker run --rm -v $(CURRENT_DIR):/data cytopia/file-lint file-utf8-bom --text --ignore '.git/,.github/,tests/' --path .
27+
28+
test:
29+
@$(MAKE) --no-print-directory _test_version
30+
@$(MAKE) --no-print-directory _test_run
31+
32+
_test_version:
33+
@echo "------------------------------------------------------------"
34+
@echo "- Testing correct version"
35+
@echo "------------------------------------------------------------"
36+
@if [ "$(TAG)" = "latest" ]; then \
37+
echo "Fetching latest version from GitHub"; \
38+
LATEST="$$( \
39+
curl -L -sS https://github.com/PyCQA/pylint/releases/ \
40+
| tac | tac \
41+
| grep -Eo "PyCQA/pylint/releases/tag/(pylint-)?[.0-9]+" \
42+
| head -1 \
43+
| sed 's/.*tag\///g' \
44+
| grep -Eo '[.0-9]+' \
45+
)"; \
46+
echo "Testing for latest: $${LATEST}"; \
47+
if ! docker run --rm $(IMAGE) --version | grep -E "$${LATEST}$$"; then \
48+
echo "Failed"; \
49+
exit 1; \
50+
fi; \
51+
else \
52+
echo "Testing for tag: $(TAG)"; \
53+
if ! docker run --rm $(IMAGE) --version | grep -E "^$(TAG)"; then \
54+
echo "Failed"; \
55+
exit 1; \
56+
fi; \
57+
fi; \
58+
echo "Success"; \
59+
60+
_test_run:
61+
@echo "------------------------------------------------------------"
62+
@echo "- Testing pep8 standard"
63+
@echo "------------------------------------------------------------"
64+
@if ! docker run --rm -v $(CURRENT_DIR)/tests:/data $(IMAGE) test.py ; then \
65+
echo "Failed"; \
66+
exit 1; \
67+
fi; \
68+
echo "Success";
69+
70+
tag:
71+
docker tag $(IMAGE) $(IMAGE):$(TAG)
72+
73+
pull:
74+
@grep -E '^\s*FROM' Dockerfile \
75+
| sed -e 's/^FROM//g' -e 's/[[:space:]]*as[[:space:]]*.*$$//g' \
76+
| xargs -n1 docker pull;
77+
78+
login:
79+
yes | docker login --username $(USER) --password $(PASS)
80+
81+
push:
82+
@$(MAKE) tag TAG=$(TAG)
83+
docker push $(IMAGE):$(TAG)
84+
85+
enter:
86+
docker run --rm --name $(subst /,-,$(IMAGE)) -it --entrypoint=/bin/sh $(ARG) $(IMAGE):$(TAG)

tests/test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'''
2+
module docstring
3+
'''
4+
5+
def main():
6+
'''function docstring'''
7+
print("Hello, World!")
8+
9+
10+
if __name__ == '__main__':
11+
main()

0 commit comments

Comments
 (0)