From 058284c17dd0cf2c3c3bcb742f4a2a9431fe3da2 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 18 May 2022 17:42:55 +0200 Subject: [PATCH] refactor: switch to filiph/linkcheck (#76) --- .drone.yml | 20 +++++++++++++++++-- .gitignore | 1 + Dockerfile | 41 +++++++++++++++++++------------------- Makefile | 29 +++++++++++++++++++++++++++ README.md | 8 ++++---- overlay/bin/link-validator | 17 +++++++++++++--- 6 files changed, 86 insertions(+), 30 deletions(-) create mode 100644 Makefile diff --git a/.drone.yml b/.drone.yml index f0731c7..764660a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -27,6 +27,20 @@ platform: arch: amd64 steps: + - name: binary + image: dart:stable + commands: + - apt-get -qq update && apt-get install -yqq --no-install-recommends make + - make build + + - name: verify + image: dart:stable + commands: + - src/build/linkcheck/linkcheck --help + - src/build/linkcheck/linkcheck --version + depends_on: + - binary + - name: dryrun image: thegeeklab/drone-docker-buildx:20 settings: @@ -42,6 +56,8 @@ steps: when: ref: - refs/pull/** + depends_on: + - verify - name: tags image: thegeeklab/docker-autotag @@ -153,7 +169,7 @@ steps: DOCKER_USER: from_secret: docker_username PUSHRM_FILE: README.md - PUSHRM_SHORT: Custom image for broken-link-checker + PUSHRM_SHORT: Custom image for linkcheck PUSHRM_TARGET: thegeeklab/${DRONE_REPO_NAME} when: status: @@ -201,6 +217,6 @@ depends_on: --- kind: signature -hmac: 146d9e41ffdf9ebeae30b044503608af4a872f420cf7f799e70d4ab3a50f4f77 +hmac: c395bc7653458c3fa8c3bd62cb9f615d3af8c53e7c929b1ea90b6c3a71738e6e ... diff --git a/.gitignore b/.gitignore index 1b763b1..70cb3fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ CHANGELOG.md +/src diff --git a/Dockerfile b/Dockerfile index 8431cd3..a2e4319 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:lts-alpine3.15@sha256:1a9a71ea86aad332aa7740316d4111ee1bd4e890df47d3b5eff3e5bded3b3d10 +FROM debian:bullseye-slim LABEL maintainer="Robert Kaussow " LABEL org.opencontainers.image.authors="Robert Kaussow " @@ -8,34 +8,33 @@ LABEL org.opencontainers.image.source="https://gitea.rknet.org/docker/link-valid LABEL org.opencontainers.image.documentation="https://gitea.rknet.org/docker/link-validator" ARG BUILD_VERSION -# renovate: datasource=npm depName=broken-link-checker -ENV BLC_VERSION="${BUILD_VERSION:-0.7.8}" +ARG WAIT_FOR_VERSION +ARG CONTAINER_LIBRARY + + # renovate: datasource=github-releases depName=caddyserver/caddy -ENV CADDY_VERSION="${CADDY_VERSION:-v2.5.1}" +ENV CADDY_VERSION="${BUILD_VERSION:-v2.5.1}" +# renovate: datasource=github-releases depName=thegeeklab/wait-for +ENV WAIT_FOR_VERSION="${WAIT_FOR_VERSION:-v0.2.0}" +# renovate: datasource=git-tags depName=https://gitea.rknet.org/docker/container-library +ENV CONTAINER_LIBRARY="${CONTAINER_LIBRARY:-v0.1.3}" ENV LINK_VALIDATOR_BASE_DIR=/drone/src \ - LINK_VALIDATOR_SERVER_PORT=80 \ - FORCE_COLOR=true \ - NPM_CONFIG_LOGLEVEL=error + LINK_VALIDATOR_SERVER_PORT=8000 COPY overlay/ / -RUN echo "Installing requirements ..." && \ - apk --update add --virtual .build-deps curl && \ +RUN apt-get update && apt-get install -y curl bash ncat media-types && \ + curl -SsL "https://gitea.rknet.org/docker/container-library/releases/download/${CONTAINER_LIBRARY}/container-library.tar.gz" | tar xz -C / && \ curl -sSL "https://github.com/caddyserver/caddy/releases/download/${CADDY_VERSION}/caddy_${CADDY_VERSION##v}_linux_amd64.tar.gz" | tar xz -C /usr/local/bin caddy && \ + curl -SsL -o /usr/local/bin/wait-for "https://github.com/thegeeklab/wait-for/releases/download/${WAIT_FOR_VERSION}/wait-for" && \ chmod 755 /usr/local/bin/caddy && \ - BLC_VERSION="${BLC_VERSION##v}" && \ - BLC_MAJOR="${BLC_VERSION%%.*}" && \ - if [ -z "${BLC_MAJOR//[0-9]}" ] && [ -n "$BLC_MAJOR" ]; then \ - echo "Installing link-checker version '$BLC_VERSION' ..." && \ - npm install -g broken-link-checker@"$BLC_VERSION"; \ - else \ - echo "Installing latest link-checker ..." && \ - npm install -g broken-link-checker; \ - fi && \ - apk del .build-deps && \ - rm -rf /var/cache/apk/* && \ - rm -rf /tmp/* + chmod 755 /usr/local/bin/wait-for && \ + rm -rf /var/lib/apt/lists/* && \ + rm -rf /tmp/* && \ + rm -rf /root/.cache/ + +ADD src/build/linkcheck/linkcheck /usr/local/bin/linkcheck USER root CMD [] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6ef4427 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +# renovate: datasource=github-tags depName=filiph/linkcheck +export BUILD_VERSION ?= 2.0.22 +export PATH := $(PATH):$(HOME)/.pub-cache/bin + +SRC := src + +.PHONY: all +all: build + +.PHONY: build +build: build-src build-bin + +.PHONY: build-src +build-src: + mkdir -p $(SRC); \ + curl -sSL "https://github.com/filiph/linkcheck/archive/$${BUILD_VERSION##v}.tar.gz" | tar xz -C $(SRC) --strip-components=1 + +.PHONY: build-bin +build-bin: + dart --disable-analytics --version; \ + cd $(SRC); \ + dart pub get; \ + dart pub global activate grinder; \ + grind pkg-standalone-linux-x64; \ + tar xzf build/linkcheck-*-linux-x64.tar.gz -C ./build + +.PHONY: clean +clean: + rm -rf $(SRC) diff --git a/README.md b/README.md index 7cc4103..cd798f0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # link-validator -Custom image for broken-link-checker +Custom image for linkcheck [![Build Status](https://img.shields.io/drone/build/docker/link-validator?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/docker/link-validator) [![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/link-validator) @@ -8,16 +8,16 @@ Custom image for broken-link-checker [![Source: Gitea](https://img.shields.io/badge/source-gitea-blue.svg?logo=gitea&logoColor=white)](https://gitea.rknet.org/docker/link-validator) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://gitea.rknet.org/docker/link-validator/src/branch/main/LICENSE) -Custom wrapper Docker image for [broken-link-checker](https://github.com/stevenvachon/broken-link-checker) optimized for CI. +Custom wrapper Docker image for [linkcheck](https://github.com/filiph/linkcheck/) optimized for CI. ## Usage ```Shell docker run -v $(pwd)/public:/drone/src link-validator -# or pass arguments to broken-link-checker +# or pass arguments to linkcheck # ... but DO NOT set the server url! This will be done automatically. See environment variables. -docker run -v $(pwd)/public:/drone/src link-validator -ro +docker run -v $(pwd)/public:/drone/src link-validator -e ``` ## Environment variables diff --git a/overlay/bin/link-validator b/overlay/bin/link-validator index cb16513..bdd3ed3 100755 --- a/overlay/bin/link-validator +++ b/overlay/bin/link-validator @@ -1,5 +1,16 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash + set -eo pipefail -caddy file-server --root "$LINK_VALIDATOR_BASE_DIR" --listen "127.0.0.1:$LINK_VALIDATOR_SERVER_PORT" &> /dev/null & -exec /usr/local/bin/broken-link-checker "$@" http://localhost:"$LINK_VALIDATOR_SERVER_PORT" +# shellcheck disable=SC1091 +. /usr/local/lib/log.sh + +URL="127.0.0.1:$LINK_VALIDATOR_SERVER_PORT" + +caddy file-server --root "$LINK_VALIDATOR_BASE_DIR" --listen "$URL" & + +log_info "Wait for web server on '$URL'" +/usr/local/bin/wait-for "$URL" + +log_info "Start linkcheck" +exec /usr/local/bin/linkcheck "$@" "$URL"