FROM docker.io/library/alpine:latest as builder
ARG TRANSLATE_SHELL_VERSION
# Install build dependencies
RUN apk add --no-cache gawk bash make
# Download the release
RUN wget -q https://github.com/soimort/translate-shell/archive/refs/tags/v${TRANSLATE_SHELL_VERSION}.tar.gz \
    && tar -xzf v${TRANSLATE_SHELL_VERSION}.tar.gz \
    && rm -rf v${TRANSLATE_SHELL_VERSION}.tar.gz \
    && mv translate-shell-${TRANSLATE_SHELL_VERSION} translate-shell-src
# Build
WORKDIR /translate-shell-src
RUN make build

FROM docker.io/library/alpine:latest
# Install runtime dependencies
RUN apk add --no-cache bash gawk less hunspell curl fribidi rlwrap mpg123
COPY --from=builder /translate-shell-src/build/trans /usr/local/bin/trans
# Create a normal user
RUN adduser -D -s /sbin/nologin -h /home/trans trans
USER trans
# Entrypoint
ENTRYPOINT ["/usr/local/bin/trans"]
