Skip to content

Commit 61d0c83

Browse files
authored
Merge pull request #1 from cytopia/release-0.1
Initial commit
2 parents 8a58113 + 9857e14 commit 61d0c83

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed

.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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM alpine:3.11 as builder
2+
3+
RUN set -x \
4+
&& apk add --no-cache \
5+
curl
6+
7+
ARG VERSION=latest
8+
RUN set -x \
9+
&& if [ "${VERSION}" = "latest" ]; then \
10+
VERSION="$( curl -Ss https://github.com/cytopia/linkcheck/releases \
11+
| tac \
12+
| tac \
13+
| grep -Eo 'archive/v[.0-9]+\.zip' \
14+
| grep -Eo '[.0-9]+[0-9]' \
15+
| sort -V \
16+
| tail -1 )"; \
17+
fi \
18+
&& curl -sS https://raw.githubusercontent.com/cytopia/linkcheck/v${VERSION}/linkcheck > /usr/bin/linkcheck \
19+
&& chmod +x /usr/bin/linkcheck
20+
21+
22+
FROM alpine:3.11 as production
23+
ARG VERSION=latest
24+
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
25+
#LABEL "org.opencontainers.image.created"=""
26+
#LABEL "org.opencontainers.image.version"=""
27+
#LABEL "org.opencontainers.image.revision"=""
28+
LABEL "maintainer"="cytopia <cytopia@everythingcli.org>"
29+
LABEL "org.opencontainers.image.authors"="cytopia <cytopia@everythingcli.org>"
30+
LABEL "org.opencontainers.image.vendor"="cytopia"
31+
LABEL "org.opencontainers.image.licenses"="MIT"
32+
LABEL "org.opencontainers.image.url"="https://github.com/cytopia/docker-linkcheck"
33+
LABEL "org.opencontainers.image.documentation"="https://github.com/cytopia/docker-linkcheck"
34+
LABEL "org.opencontainers.image.source"="https://github.com/cytopia/docker-linkcheck"
35+
LABEL "org.opencontainers.image.ref.name"="linkcheck ${VERSION}"
36+
LABEL "org.opencontainers.image.title"="linkcheck ${VERSION}"
37+
LABEL "org.opencontainers.image.description"="linkcheck ${VERSION}"
38+
39+
RUN set -x \
40+
&& apk add --no-cache bash
41+
COPY --from=builder /usr/bin/linkcheck /usr/bin/linkcheck
42+
WORKDIR /data
43+
ENTRYPOINT ["linkcheck"]
44+
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) 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/linkcheck
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/cytopia/linkcheck/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 "^linkcheck v$${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 "^linkcheck v$(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)