|
| 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