From 76cd15e39af530f82396dfb825cd21a64202256b Mon Sep 17 00:00:00 2001 From: Michele Riva Date: Wed, 29 Dec 2021 21:01:08 +0100 Subject: [PATCH] fix: fixed devtools urls --- Makefile | 7 +++++++ README.md | 7 +++++++ chromium/chromium.go | 12 +++++++++++- controller/controller.go | 1 + docker-compose-develop.yml | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 docker-compose-develop.yml diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..609803d --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +DC=docker-compose + +container-dev: + $(DC) -f docker-compose-develop.yml up --build + +container-prod: + $(DC) up \ No newline at end of file diff --git a/README.md b/README.md index 23d71f2..886d4ea 100644 --- a/README.md +++ b/README.md @@ -96,5 +96,12 @@ routes: I'm currently writing more documentation, it will be available on **Gitbook**: [http://micheleriva.gitbook.io/gauguin](http://micheleriva.gitbook.io/gauguin) +# Env Variables +```env +PORT= # HTTPS Port +DOCKERIZED= # Set to true if running Gauguin in Docker +CHROME_URL= # Optional, the URL of the Chrome REST Debugging APIs +``` + # License **Gauguin** is distributed under the [GPLv3 open source license](/LICENSE.md). diff --git a/chromium/chromium.go b/chromium/chromium.go index 6c30a50..f25431e 100644 --- a/chromium/chromium.go +++ b/chromium/chromium.go @@ -27,9 +27,19 @@ type ChromeDevToolsVersion struct { } var isDockerized bool +var chromeDevToolsURL string func init() { isDockerized = os.Getenv("DOCKERIZED") == "true" + chromeURL := os.Getenv("CHROME_URL") + + if isDockerized && chromeURL == "" { + chromeDevToolsURL = "http://alpine_chrome:9222/json/version" + } else if chromeURL != "" { + chromeDevToolsURL = chromeURL + } else { + chromeDevToolsURL = "http://localhost:9222/json/version" + } } func getCDTData() ChromeDevToolsVersion { @@ -37,7 +47,7 @@ func getCDTData() ChromeDevToolsVersion { client := resty.New() - resp, err := client.R().SetHeader("HOST", "localhost").Get("http://alpine_chrome:9222/json/version") + resp, err := client.R().SetHeader("HOST", "localhost").Get(chromeDevToolsURL) if err != nil { log.Fatal(err) } diff --git a/controller/controller.go b/controller/controller.go index 2ac4058..23fff30 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -73,6 +73,7 @@ func HandleRoutes(c *gin.Context) { image := chromium.GenerateImage(tpl.String(), sizes.width, sizes.height) img := bytes.NewReader(image) + c.Header("Cache-Control", "max-age=604800") c.Render(http.StatusOK, render.Reader{ContentType: "image/jpeg", ContentLength: int64(img.Len()), Reader: img}) } diff --git a/docker-compose-develop.yml b/docker-compose-develop.yml new file mode 100644 index 0000000..303a231 --- /dev/null +++ b/docker-compose-develop.yml @@ -0,0 +1,37 @@ +version: '3.7' + +services: + + alpine_chrome: + image: zenika/alpine-chrome:latest + container_name: gauguin-chrome-alpine + command: [chromium-browser, "--headless", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage", "--remote-debugging-address=0.0.0.0", "--remote-debugging-port=9222"] + ports: + - 9222:9222 + restart: unless-stopped + networks: + - gauguin_net + + gin_gonic: + container_name: gauguin-gin-gonic + build: + context: . + dockerfile: Dockerfile + links: + - alpine_chrome + depends_on: + - alpine_chrome + ports: + - 5491:5491 + expose: + - '5491' + volumes: + - ./templates:/app/templates + - ./gauguin.yaml:/app/gauguin.yaml + restart: unless-stopped + networks: + - gauguin_net + +networks: + gauguin_net: + driver: bridge