diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..278e1a0 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,34 @@ +variables: + WKHTMLTOPDF_VERSION: "0.12.6" + + # explicit tag to be used within pipeline + BUILD_IMAGE_NAME: "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA" + + # we also publish a floating tag to simplify manual testing + BUILD_IMAGE_NAME_LATEST: "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:latest" + +build: + image: docker:20.10.6 + stage: build + services: + - name: docker:20.10.6-dind + + before_script: + - | + for i in $(seq 1 30); do + if ! docker info &> /dev/null; then + echo "Docker not responding yet. Sleeping for 2s..." && sleep 2s + else + echo "Docker ready. Continuing build..." + break + fi + done + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" + script: + - docker build + -f Dockerfile-${WKHTMLTOPDF_VERSION} + --tag "$BUILD_IMAGE_NAME" + --tag "$BUILD_IMAGE_NAME_LATEST" + . + - docker push "$BUILD_IMAGE_NAME" + - docker push "$BUILD_IMAGE_NAME_LATEST" diff --git a/Dockerfile-0.12.6 b/Dockerfile-0.12.6 new file mode 100644 index 0000000..c70cd8c --- /dev/null +++ b/Dockerfile-0.12.6 @@ -0,0 +1,30 @@ +# first stage: build kwkhtmltopdf_server + +FROM golang:1.11 +WORKDIR /tmp +COPY server/kwkhtmltopdf_server.go . +RUN go build kwkhtmltopdf_server.go + +# second stage: server with wkhtmltopdf + +FROM ubuntu:18.04 + +RUN set -x \ + && apt update \ + && apt -y install --no-install-recommends curl ca-certificates fonts-liberation2 \ + && curl -o /tmp/wkhtmltox.deb -SL https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb \ + && echo "3a9a5619d9b423103cabd316ed9634e1c71d4504 /tmp/wkhtmltox.deb" | sha1sum -c - \ + && apt -y install /tmp/wkhtmltox.deb \ + && apt -y purge wget --autoremove \ + && apt -y clean \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=0 /tmp/kwkhtmltopdf_server /usr/local/bin/ + +RUN adduser --disabled-password --gecos '' kwkhtmltopdf +USER kwkhtmltopdf +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 + +EXPOSE 8080 +CMD /usr/local/bin/kwkhtmltopdf_server diff --git a/server/kwkhtmltopdf_server.go b/server/kwkhtmltopdf_server.go index 3182208..a5b9d5e 100644 --- a/server/kwkhtmltopdf_server.go +++ b/server/kwkhtmltopdf_server.go @@ -70,6 +70,10 @@ func httpAbort(w http.ResponseWriter, err error) { func handler(w http.ResponseWriter, r *http.Request) { log.Printf("%s %s", r.Method, r.URL.Path) + if r.URL.Path == "/status" { + w.WriteHeader(http.StatusOK) + return + } if r.Method != http.MethodPost { httpError(w, errors.New("http method not allowed: "+r.Method), http.StatusMethodNotAllowed) return