From 621e0793fdcba084aa119b8460597c5371f20460 Mon Sep 17 00:00:00 2001 From: Ambrose Chua Date: Thu, 26 Sep 2019 14:56:53 +0800 Subject: [PATCH] Initial commit --- Dockerfile | 47 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 23 +++++++++++++++++++++++ lwan.conf | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 lwan.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5b130ad --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# +# Build stage +# +FROM alpine:3.10 as build + +# args +ARG version="master" + +# build root +WORKDIR /build + +RUN apk add --no-cache git upx ca-certificates alpine-sdk cmake zlib-dev +# source +RUN git clone https://github.com/lpereira/lwan -b ${version} . + +# build +RUN mkdir build \ + && cd build \ + && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-static" -DCMAKE_C_FLAGS="-static" \ + && make +# compress and test +#RUN cd build \ +# && ls -l src/bin/lwan \ +# && upx --ultra-brute src/bin/lwan/lwan + +# +# Final image +# +FROM scratch + +# labels +LABEL org.label-schema.vcs-url="https://github.com/productionwentdown/lwan" +LABEL org.label-schema.version=${version} +LABEL org.label-schema.schema-version="1.0" + +# copy binary and ca certs +COPY --from=build /build/build/src/bin/lwan/lwan /bin/lwan +COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt + +# copy default caddyfile +COPY lwan.conf /etc/lwan.conf + +# serve from /srv +WORKDIR /srv +EXPOSE 8080 + +ENTRYPOINT ["/bin/lwan", "--config", "/etc/lwan.conf"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..41e21e2 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ + +# [lwan](https://hub.docker.com/r/productionwentdown/lwan/) [![](https://images.microbadger.com/badges/version/productionwentdown/lwan.svg)](https://microbadger.com/images/productionwentdown/lwan "Get your own version badge on microbadger.com") [![](https://images.microbadger.com/badges/image/productionwentdown/lwan.svg)](https://microbadger.com/images/productionwentdown/lwan "Get your own image badge on microbadger.com") + +A tiny Lwan Web Server image compressed with [UPX](https://github.com/upx/upx). + +> Notice: I keep this manually updated. If it goes out of date, ping me via Twitter [@serverwentdown](https://twitter.com/serverwentdown). + +# Usage + +Serve files in `$PWD`: +``` +docker run -it --rm -p 8080:8080 -v $PWD:/srv productionwentdown/lwan +``` + +Overwrite `lwan.conf`: +``` +docker run -it --rm -p 8080:8080 -v $PWD:/srv -v $PWD/lwan.conf:/etc/lwan.conf productionwentdown/lwan +``` + +Run as specific user: +``` +docker run -it --rm -p 8080:8080 -v $PWD:/srv --user 900 productionwentdown/lwan +``` diff --git a/lwan.conf b/lwan.conf new file mode 100644 index 0000000..4d23ea2 --- /dev/null +++ b/lwan.conf @@ -0,0 +1,35 @@ +# Timeout in seconds to keep a connection alive. +keep_alive_timeout = 15 + +# Set to true to not print any debugging messages. (Only effective in +# release builds.) +quiet = false + +# Set SO_REUSEPORT=1 in the master socket. +reuse_port = false + +# Value of "Expires" header. Default is 1 month and 1 week. +expires = 1M 1w + +# Number of I/O threads. Default (0) is number of online CPUs. +threads = 0 + +# Disable HAProxy's PROXY protocol by default. Only enable if needed. +proxy_protocol = false + +# Enable straitjacket by default. The `drop_capabilities` option is `true` +# by default. Other options may require more privileges. +straitjacket { + drop_capabilities = false +} + +listener *:8080 { + serve_files / { + path = /srv + + # When requesting for file.ext, look for a smaller/newer file.ext.gz, + # and serve that instead if `Accept-Encoding: gzip` is in the + # request headers. + serve precompressed files = true + } +}