Skip to content

Commit

Permalink
fix: fixed devtools urls
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva committed Dec 29, 2021
1 parent dcf6be4 commit 76cd15e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DC=docker-compose

container-dev:
$(DC) -f docker-compose-develop.yml up --build

container-prod:
$(DC) up
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<number> # HTTPS Port
DOCKERIZED=<boolean> # Set to true if running Gauguin in Docker
CHROME_URL=<string> # Optional, the URL of the Chrome REST Debugging APIs
```

# License
**Gauguin** is distributed under the [GPLv3 open source license](/LICENSE.md).
12 changes: 11 additions & 1 deletion chromium/chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,27 @@ 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 {
var CDTData 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)
}
Expand Down
1 change: 1 addition & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}

Expand Down
37 changes: 37 additions & 0 deletions docker-compose-develop.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 76cd15e

Please sign in to comment.