From a52f6367b5a8087a9dd119bf52440436e85a4dea Mon Sep 17 00:00:00 2001 From: Emil Dabrowski Date: Mon, 19 Dec 2022 15:44:03 +0100 Subject: [PATCH] Add gtranslate --- .gitmodules | 3 +++ gtranslate/Containerfile | 24 ++++++++++++++++++++++++ gtranslate/README.md | 26 ++++++++++++++++++++++++++ gtranslate/mk-container.sh | 9 +++++++++ gtranslate/source-code | 1 + 5 files changed, 63 insertions(+) create mode 100644 gtranslate/Containerfile create mode 100644 gtranslate/README.md create mode 100755 gtranslate/mk-container.sh create mode 160000 gtranslate/source-code diff --git a/.gitmodules b/.gitmodules index c13969d..f5a2928 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "erpnext/frappe_docker"] path = erpnext/frappe_docker url = https://github.com/frappe/frappe_docker +[submodule "gtranslate/source-code"] + path = gtranslate/source-code + url = https://git.sr.ht/~yerinalexey/gtranslate diff --git a/gtranslate/Containerfile b/gtranslate/Containerfile new file mode 100644 index 0000000..3cb04d5 --- /dev/null +++ b/gtranslate/Containerfile @@ -0,0 +1,24 @@ +# Build stage +FROM golang:1.19.4-alpine3.17 + +WORKDIR /app + +# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change +COPY go.mod go.sum ./ +RUN go mod download && go mod verify +RUN mkdir /builds + +COPY . . + +RUN apk add make +RUN make install +RUN make clean +RUN rm -Rf .git* + +# Final stage to only keep necessary pre-built binaries and source files +FROM alpine:3.17.0 +WORKDIR /app +COPY --from=0 /app /app +COPY --from=0 /usr/local/bin/gtranslate* /usr/local/bin/ +EXPOSE 5000 +CMD ["gtranslate-server"] diff --git a/gtranslate/README.md b/gtranslate/README.md new file mode 100644 index 0000000..061fce4 --- /dev/null +++ b/gtranslate/README.md @@ -0,0 +1,26 @@ +# Containerfile: gtranslate + +[Alexey Yerin](https://git.sr.ht/~yerinalexey) is unfortunately not interested in providing [`gtranslate`](https://git.sr.ht/~yerinalexey/gtranslate) in a container format, so here's a Containerfile for anyone in need. It is a multi-stage build which means that the Golang build environment container isn't a part of the final container. The final container is therefore just a little over 20MB. Thank you Alexey for this neat little tool! + +## Building + +```sh +./mk-container.sh +``` + +## Usage + +Running the server in detached mode and querying it: + +```sh +>>> docker run -it --rm --publish 5000:5000/tcp --name my-gtranslate-instance git.jilits.se/jilits/gtranslate:latest +>>> curl 'http://localhost:5000/api?from=en&to=pl&text=Translate+it' +Przetłumacz to +``` + +Run a single query: + +```sh +>>> docker run -a STDOUT --rm --name dmenugtranslate git.jilits.se/jilits/gtranslate:latest gtranslate-query en pl "Hello, this is Mr. Banana." +Witam, tu Pan Banan. +``` diff --git a/gtranslate/mk-container.sh b/gtranslate/mk-container.sh new file mode 100755 index 0000000..48a9d27 --- /dev/null +++ b/gtranslate/mk-container.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +version="0.1.0" +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +docker build "$script_dir/source-code" -f Containerfile \ + -t jilits/gtranslate:latest \ + -t jilits/gtranslate:$version \ + -t git.jilits.se/jilits/gtranslate:latest \ + -t git.jilits.se/jilits/gtranslate:$version diff --git a/gtranslate/source-code b/gtranslate/source-code new file mode 160000 index 0000000..4244e27 --- /dev/null +++ b/gtranslate/source-code @@ -0,0 +1 @@ +Subproject commit 4244e2734bfc27679d902e477938389bee2b8840