Skip to content

Commit

Permalink
feat: probe endpoint /status
Browse files Browse the repository at this point in the history
  • Loading branch information
dnplkndll committed Apr 9, 2022
1 parent d7b0a47 commit 7956de8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -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"
30 changes: 30 additions & 0 deletions Dockerfile-0.12.6
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions server/kwkhtmltopdf_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7956de8

Please sign in to comment.