Sitelet https://github.com/cytopia/docker-mypy/commit/97a35f0b3bd5847034ae6e689eab7d7441187bd3
Skip to content

Commit 97a35f0

Browse files
committed
Release 0.1
1 parent 76b78f5 commit 97a35f0

4 files changed

Lines changed: 231 additions & 0 deletions

File tree

‎.travis.yml‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
3+
###
4+
### Enable sudo (required for docker service)
5+
###
6+
sudo: required
7+
8+
9+
###
10+
### Language
11+
###
12+
language: minimal
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+
- retry() {
35+
for ((n=0; n<10; n++)); do
36+
echo "[${n}] ${*}";
37+
if eval "${*}"; then
38+
return 0;
39+
fi;
40+
done;
41+
return 1;
42+
}
43+
44+
45+
###
46+
### Check generation changes, build and test
47+
###
48+
before_script:
49+
- retry make lint
50+
- retry make build TAG=${VERSION}
51+
- retry make test TAG=${VERSION}
52+
53+
54+
###
55+
### Push to Dockerhub
56+
###
57+
script:
58+
# Push to docker hub on success
59+
- if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
60+
while ! make login USER="${DOCKER_USERNAME}" PASS="${DOCKER_PASSWORD}"; do sleep 1; done;
61+
if [ -n "${TRAVIS_TAG}" ]; then
62+
while ! make push TAG="${VERSION}-${TRAVIS_TAG}"; do sleep 1; done;
63+
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
64+
while ! make push TAG=${VERSION}; do sleep 1; done;
65+
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
66+
while ! make push TAG="${VERSION}-${TRAVIS_BRANCH}"; do sleep 1; done;
67+
else
68+
echo "Skipping branch ${TRAVIS_BRANCH}";
69+
fi
70+
else
71+
echo "Skipping push on PR";
72+
fi

‎Dockerfile‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM alpine:3.9 as builder
2+
3+
RUN set -eux \
4+
&& apk add --no-cache \
5+
bc \
6+
gcc \
7+
musl-dev \
8+
python3 \
9+
python3-dev
10+
11+
ARG VERSION=latest
12+
RUN set -eux \
13+
&& if [ "${VERSION}" = "latest" ]; then \
14+
pip3 install --no-cache-dir --no-compile mypy; \
15+
else \
16+
pip3 install --no-cache-dir --no-compile "mypy>=${VERSION},<$(echo "${VERSION}+0.1" | bc)"; \
17+
fi \
18+
\
19+
&& mypy --version | grep -E '^mypy\s[0-9]+' \
20+
\
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+
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
27+
#LABEL "org.opencontainers.image.created"=""
28+
#LABEL "org.opencontainers.image.version"=""
29+
#LABEL "org.opencontainers.image.revision"=""
30+
LABEL "maintainer"="cytopia <cytopia@everythingcli.org>"
31+
LABEL "org.opencontainers.image.authors"="cytopia <cytopia@everythingcli.org>"
32+
LABEL "org.opencontainers.image.vendor"="cytopia"
33+
LABEL "org.opencontainers.image.licenses"="MIT"
34+
LABEL "org.opencontainers.image.url"="https://github.com/cytopia/docker-mypy"
35+
LABEL "org.opencontainers.image.documentation"="https://github.com/cytopia/docker-mypy"
36+
LABEL "org.opencontainers.image.source"="https://github.com/cytopia/docker-mypy"
37+
LABEL "org.opencontainers.image.ref.name"="mypy ${VERSION}"
38+
LABEL "org.opencontainers.image.title"="mypy ${VERSION}"
39+
LABEL "org.opencontainers.image.description"="mypy ${VERSION}"
40+
41+
RUN set -eux \
42+
&& apk add --no-cache python3 \
43+
&& ln -sf /usr/bin/python3 /usr/bin/python \
44+
&& find /usr/lib/ -name '__pycache__' -print0 | xargs -0 -n1 rm -rf \
45+
&& find /usr/lib/ -name '*.pyc' -print0 | xargs -0 -n1 rm -rf
46+
COPY --from=builder /usr/lib/python3.6/site-packages/ /usr/lib/python3.6/site-packages/
47+
COPY --from=builder /usr/bin/mypy /usr/bin/mypy
48+
WORKDIR /data
49+
ENTRYPOINT ["mypy"]

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

0 commit comments

Comments
 (0)