From 17b538f297f93f38a66b53181e9b7dd27a3deb16 Mon Sep 17 00:00:00 2001 From: Romain de Laage Date: Thu, 4 Mar 2021 19:32:46 +0100 Subject: [PATCH] Add docker image --- Dockerfile | 20 ++++++++++++++++++++ Makefile | 12 +++++++++--- README.md | 23 +++++++++++++++++++++++ docker-compose.yml | 15 +++++++++++++++ start.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 start.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cb90961 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.16.0-buster as BUILD + +COPY . mastogem + +RUN cd mastogem && \ + go build -o /mastogem + +FROM debian:buster-slim + +COPY --from=BUILD /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ + +COPY --from=BUILD /mastogem /mastogem + +COPY start.sh /start.sh + +RUN chmod +x /start.sh + +EXPOSE 1965 + +CMD "/start.sh" diff --git a/Makefile b/Makefile index debea2b..9680e49 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,15 @@ -all: amd64 arm7 +VERSION=1.0 +SOURCES=$(shell find . -name "*.go" -type f) -amd64: +all: amd64 arm7 dockerimage + +amd64: $(SOURCES) mkdir -p build GOOS=linux GOARCH=amd64 go build -o build/mastogem-amd64 -arm7: +arm7: $(SOURCES) mkdir -p build GOOS=linux GOARCH=arm GOARM=7 go build -o build/mastogem-arm7 + +dockerimage: Dockerfile start.sh $(SOURCES) + sudo docker build -t dervom/mastogem:$(VERSION) . diff --git a/README.md b/README.md index a76dbea..ba5aeb3 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,29 @@ You should provide the `MASTOGEM_CONFIG_PATH` environment variable when launchin To run the program simply run the executable file corresponding to your architecture in the `build` folder. Make sure the certificate and the key where generated before. +## Run with Docker + +You could use docker or docker-compose to run this program, you must set a `MASTODON_BASE_URL` variable corresponding to the URL to your Mastodon instance (without the tailing slash), you also must bind a certificate (`/cert.pem`) and a key (`/key.rsa`). + +You can set a `TITLE` and a `HOME_MESSAGE` variables. + +### Docker + +``` +sudo docker run -it \ + -p 1965:1965 \ + -e MASTODON_BASE_URL=https://mamot.fr \ + --mount type=bind,source=$(pwd)/certs/cert.pem,destination=/cert.pem \ + --mount type=bind,source=$(pwd)/certs/key.rsa,destination=/key.rsa \ + dervom/mastogem +``` + +### Docker-compose + +``` +sudo docker-compose up -d +``` + ## Contribute You contributions are welcomed, you can send me an email (romain.delaage@rdelaage.ovh). diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f3807f8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.7" + +services: + mastogem: + image: dervom/mastogem:1.0 + build: . + container_name: mastogem + volumes: + - ./certs/key.rsa:/key.rsa:ro + - ./certs/cert.pem:/cert.pem:ro + environment: + MASTODON_BASE_URL: "https://mamot.fr" + ports: + - 1965:1965 + restart: unless-stopped diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..8780af4 --- /dev/null +++ b/start.sh @@ -0,0 +1,41 @@ +#! /bin/sh + +if [ -z "$MASTODON_BASE_URL" ] +then + echo "You must set the MASTODON_BASE_URL variable" + exit 1 +fi + +if [ ! -f /cert.pem ] +then + echo "You must bind a certificate at /cert.pem" + exit 1 +fi + +if [ ! -f /key.rsa ] +then + echo "You must bind a private key at /key.rsa" +fi + +if [ -z "$TITLE" ] +then + TITLE=MastoGem +fi + +if [ -z "$HOME_MESSAGE" ] +then + HOME_MESSAGE="Welcome on MastoGem, a Mastodon proxy for Gemini !" +fi + +cat << EOF > /config.json +{ + "listen": "0.0.0.0:1965", + "cert_path": "/cert.pem", + "key_path": "/key.rsa", + "base_url": "$MASTODON_BASE_URL", + "title": "$TITLE", + "home_message": "$HOME_MESSAGE" +} +EOF + +MASTOGEM_CONFIG_PATH=/config.json /mastogem