Skip to content

Instantly share code, notes, and snippets.

@Genzer
Last active January 11, 2022 11:42
Show Gist options
  • Save Genzer/22c40a2e3d65e13c81903e3dd6874c42 to your computer and use it in GitHub Desktop.
Save Genzer/22c40a2e3d65e13c81903e3dd6874c42 to your computer and use it in GitHub Desktop.
Use Retype (https://retype.com/) in Docker

Retypeapp Docker Image (unofficial)

This Docker image is built for my own purposes and is not an official made by Retype.

Overview

Since Retype is an executable binary built by .NET, the base image debian:bullseye-20211201-slim is enough. The binary is downloaded and put in /usr/local/bin/retype thus making it available in $PATH.

Usage Examples

Watch

The image does not set any specific directory as its working directory, you are free to choose where to put it. It's important to specify it via --workdir.

It's important to also specify the --host 0.0.0.0 so that you can access from your browser to the web server running inside the container. Omitting this and you cannot access to the site.

# Suppose you are in ~/my-docs
~/my-docs$> docker run --rm --init \
  -p 5000:5000 \
  -v $(pwd):/opt/ \
  --workdir /opt \
  genzerhawker/retype:1.11.1 retype watch --host 0.0.0.0

A Compose file could save you all the details

services:
  retype:
    image: genzerhawker/retype:1.11.1
    init: true
    working_dir: /opt/
    command: "retype watch --host 0.0.0.0"
    ports:
      - 5000:5000
    volumes:
      - ./:/opt/

Put this as docker-compose.yaml in your document directory and docker compose up.

Build Pipeline

It is possible to use this image in a multi-stage Dockerfile.

FROM genzerhawker/retype:1.11.1 as build

COPY . /opt/page
WORKDIR /opt/page/
RUN retype build

# This will be the final Docker image serving the static site.
# Feel free to choose whatever web server works for you.
FROM nginxinc/nginx-unprivileged:1.20.2 as final

COPY --from=build /opt/page/.retype/. /usr/share/nginx/html
# For an old version using Node.js base image:
# https://gist.github.com/Genzer/22c40a2e3d65e13c81903e3dd6874c42/08f15da2bf678e30ec172d16291d1d74aa082b28
# NOTE:
# ----
# As Retype is developed using .NET and is built to native binary, so there is no need for Node.js at all.
FROM debian:bullseye-20211201-slim as build
# NOTE:
# ----
# This makes use of NPM Registry API (used by `npm`) to fetch the tarball of package `retype-linux-x64` [1].
# The URL and shasum can be found at https://registry.npmjs.org/retypeapp-linux-x64/1.11.1.
# Thanks to @fabriciomurta for the tip [2]!
#
# [1]: https://www.npmjs.com/package/retypeapp-linux-x64
# [2]: https://gist.github.com/Genzer/22c40a2e3d65e13c81903e3dd6874c42#gistcomment-4000189
ARG RETYPE_PACKAGE_URL="https://registry.npmjs.org/retypeapp-linux-x64/-/retypeapp-linux-x64-1.11.1.tgz"
ARG RETYPE_PACKAGE_SHASUM="2a53485d5d74c053be868b4f61a293f80aca39bc"
SHELL [ "/bin/bash", "-c"]
WORKDIR /opt/
RUN set -ueo pipefail; \
apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
ca-certificates \
&& curl "$RETYPE_PACKAGE_URL" \
| tee >(tar -xz --strip-components=2 -f- package/bin/retype) \
| sha1sum -c <(echo "$RETYPE_PACKAGE_SHASUM -") \
&& chmod +x retype
FROM debian:bullseye-20211201-slim as final
# This is to suppress the error
# "Couldn't find a valid ICU package installed on the system.".
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
# These packages has to be install as `retype` is dynamically linked
# with several libs.
ARG PACKAGES="\
libgssapi-krb5-2 \
libssl-dev \
"
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
$PACKAGES \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /opt/retype /usr/local/bin/retype
@Genzer
Copy link
Author

Genzer commented Dec 17, 2021

I tried to use retype on Alpine but it didn't work, the process just hang forever.

ENV export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
RUN apk add --no-cache krb5-libs libc6-compat

It seems Alpine did not work well with dotnet-core (Retype is built by .NET).

@fabriciomurta
Copy link

Hi, amazing job! Alpine really does not have .NET builtin compatibility so we simply couldn't target it. There's some discussion about it in retypeapp/retype#122.

@fabriciomurta
Copy link

A couple suggestions:

  1. Line 23, try retypeapp-linux-x64 and skip the removals from the root.

  2. If you can install .NET 5.x on your docker instance, then you can, instead of npm, use dotnet tool install retypeapp for the smallest download possible. But maybe installing whole .NET would make the final image bigger.

@Genzer
Copy link
Author

Genzer commented Dec 20, 2021

Hi @fabriciomurta,

Thanks for the tip! I had figured out a way to build a Docker image without using Node.js image at all. This greatly reduced the Docker image size 1!

@boscorelly
Copy link

hi,

can you tell me where are stored all the datas please ?
are they in /opt/retype ?

@tekollt
Copy link

tekollt commented Jan 10, 2022

@Genzer is this image functional?

I created a new docker container based on your gist and mapped up the local docs folder with yaml configuration and apropriate port mapping.
retype watch starts with no errors, but i am still not able to connect as i get connection refused

@Genzer
Copy link
Author

Genzer commented Jan 11, 2022

Hi @boscorelly,

can you tell me where are stored all the datas please ?

The final image is only a debian image with the Retype binary located at /usr/local/bin/retype. You are free to choose the directory to mount your site's source (Markdown files). I have added a README.md to give some examples how to use this image. Hope it helps!

@Genzer
Copy link
Author

Genzer commented Jan 11, 2022

Hi @tekollt,

I've been using this image for several projects and it is working fine up until now.

retype watch starts with no errors, but i am still not able to connect as i get connection refused

I also got this. You have to explicitly specify --host 0.0.0.0 so that you can access to the web server inside the container. I have added an README.md to provide some usage examples. Hope it helps!

@tekollt
Copy link

tekollt commented Jan 11, 2022

Thanks @Genzer , works like a charm with --host 0.0.0.0 , was initially under the impression that "url" in retype.yml would work for the same, but i guess not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment