Sign inSign up

sistematis/sims

By sistematis

•Updated 5 months ago

Static In Memory Server

Image
0

1.4K

sistematis/sims repository overview

⁠SIMS - Static In Memory Server

⁠A base docker image to create HTML servers for static content that works completely from memory.

All the served files send the Cache-Control headers to be inmutables and algo uses their own md5 as Etag (with the exception of the index that will use the Version env variable if exist)

⁠Use:
FROM sistematis/sims:master

ENV NAME="MyProjectName"
ARG VERSION
ENV VERSION=$VERSION

COPY src /html

VERSION is the version of your build, it will be served as header and used ad eTag for index.html or country local index files.

You must have an index.html file inside your src/ folder.

⁠Run demo:
$ docker run --rm -it -p 8080:80 -e VERSION=demo01 sims
⁠SPA support

Add the env variable SPA=1 to enable SPA mode (SIMS will server index.html for every request that does not exist rater than respond 404).

⁠103 Early Hints

This server support the Early Hints new push technique. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103⁠ for more info. In order to send the propper headers on the response, all you need to do is add a json file on the side of the html file you like the send the headers for. The json file must have a name with the folliwing convention: a dot, then the filename replacing the dots with underscores, and then the subfix '_preloads.json', example: for the index.html the file name should be .index_html_preloads.json and it should be on the same folder. The json file should have the content:

{
  "style": [
    "/styles/main.css"
  ],
  "script": [
    "/js/main.js"
  ],
  "image": [
    "/images/header-bg.svg"
  ],
  "font": [
    "/styles/fonts/super-font.eot"
  ]
}

This will result on adding the headers:

HTTP/1.1 103 Early Hints
Link: </styles/main.css>; rel=preload; as=style
Link: </js/main.js>; rel=preload; as=script
Link: </images/header-bg.svg>; rel=preload; as=image
Link: </styles/fonts/super-font.eot>; rel=preload; as=font

HTTP/1.1 200 OK
Cache-Control: public
Cache-Control: immutable
Cache-Control: max-age=31556926
Content-Type: text/html; charset=utf-8
Etag: 1.0.0
Server: sims/1.0.7
Vnd-App-Build: 2021-09-26T19:54:54-0300
Vnd-App-Name: MyProjectName
Vnd-App-Version: 1.0.0
Date: Sun, 26 Sep 2021 22:55:18 GMT
Transfer-Encoding: chunked

<!DOCTYPE html><html ...
⁠Use with geoIP to server different index based on the client location:
FROM alpine AS build

ARG MAXMIND_LISENCE_KEY

RUN apk update && apk add ca-certificates curl tar gzip

RUN curl "https://download.maxmind.com/app/geoip_download?license_key=$MAXMIND_LISENCE_KEY&suffix=tar.gz&edition_id=GeoLite2-Country" -o geoip.tgz
RUN tar xzvf geoip.tgz
RUN mv */*.mmdb /


FROM sistematis/sims:master

COPY --from=build /GeoLite2-Country.mmdb /
ENV GEOIP_DB="/GeoLite2-Country.mmdb"

ENV NAME="Mi project name"
ARG VERSION
ENV VERSION=$VERSION

COPY src /html

When GEOIP_DB env is available SIMS will try to find the client IP and serve the proper index based on the ISO code of the country, for example, will first try to server us.html and if you don't have that file, will server index.html.

⁠Other options
  • If you set the env variable ADD_HIDDEN_FILES server will serve file starting with a dot (example: /.hello.html is not served unless you set this variable).

  • If you set the env variable SERVER_HEADER server will override the Server header with this value, if value is empty the header is not send (default is sims/X.Y.Z where X.Y.Z is the of the binary).` .

  • If you set the env variable NO_VERSION_HEADERS server will NOT send the headers Vnd-App-Build, Vnd-App-Version, Vnd-App-Name.

  • If you set the env variable NAME server will send this value in Vnd-App-Name header.

  • If you set the env variable VERSION server will send this value in Vnd-App-Version header.

  • If you set the env variable BUILD server will send this value in Vnd-App-Build header.

  • If you set the env variable FORCE_INDEX_ETAG server will send the index.html md5 as Etag, not the Version env variable (default is version if it's setted).

  • You can set the env variable PORT to server on other port than 80.

  • Env variable BASE_URL will define the base path for all the requests (default is /).

  • Env variable HEALTH will enable the GET /health endpoint and response with as text/plain then content of the variable (default is '' or disabled).

  • Env variable PROMETHEUS will enable the GET /metrics endpoint (default is '' or disabled).

  • Env variable LOG_LEVEL can be set to INFO or DEBUG to get more information (default is INFO). Sending a SIGUSR1 will toggle the LOG_LEVEL on run time. And other option to toggle the LOG_LEVEL is to execute on the container the command sims toggle_log_level:

  docker exec my_container_name sims toggle_log_level

Or if running on kubernets

  kubectrl exec pod/my_pod_name -- /sims toggle_log_level

⁠Source code at:

https://gitlab.sistematis.com.ar/OPEN-SOURCE/GO/sims⁠

Tag summary

Content type

Image

Digest

sha256:6076fd097…

Size

3.7 MB

Last updated

5 months ago

docker pull sistematis/sims