Publishing Gitlab wiki?

I need to write some documentation for a system and like to make use of the Gitlab wiki feature.

Is there a way to publish this content from the wiki to a static website using Caddy 2? I see there is a plugin available by vrongmeal but I was wondering if there any other methods?

Thanks in advance for any pointers…

Yep, the git plugin is probably the best option for keeping it up to date automatically without user interaction.

You’ll probably want to also make use of the templates directive which will let you render the markdown on the fly with Caddy, and wrap a layout around the markdown content.

Thanks Francis.

Would it use the same format as the v1 git plugin? I took a look at the example for v2 and it seems somewhat different.

This will be my first time using it so am treading cautiously, indeed it’s my first time using Caddy at all!

Is there an example file I could look at other than the one on the authors site? I did do a search but couldn’t find much in the way of people showcasing this.

Thanks!

No, it’s a complete rewrite from the v1 plugin. Also, unfortunately it doesn’t have Caddyfile support yet, but that should come soon enough. All the docs for it are in the README.

You can write your config with Caddyfile syntax first, then use the caddy adapt command to convert it to JSON and make your modifications to configure caddygit for now.

1 Like

I am trying to get this working but not having much luck!

My code:

{
  "apps": {
    "git": {
      "clients": [
        {
          "repo": {
            "url": "http://gitlab.caminfo.local/root/system.wiki.git",
            "path": "/var/www/system",
            "branch": "master",
            "single_branch": true,
            "depth": 1
          },
          "service": {
            "type": "poll",
            "interval": "10m"
          },
          "commands_after": [
            {
              "async": true
            }
          ]
        }
      ]
    }
  }
}

When I run caddy it comes up with:
adapt: Caddyfile:26 - Error during parsing: Unexpected EOF

I think your config file is still named Caddyfile, so Caddy tries to parse it as a Caddyfile and not as JSON.

If you’re using JSON, you should probably rename the file to caddy.json or something.

I’ve renamed it to caddy.json and tried again.

Now I get this when I run “caddy validate”:

validate: decoding config: unexpected end of JSON input

$ caddy validate --config caddy.json 
2020/06/12 15:26:40.860	INFO	using provided configuration	{"config_file": "caddy.json", "config_adapter": ""}
validate: loading git app module: unknown module: git

Works fine for me with your config from above, although I don’t have the git module compiled in on my local copy.

Getting there!

My config validates fine when I do as you did.

When I run Caddy now I am receiving this output:

2020/06/12 15:36:11.232 INFO    using provided configuration    {"config_file": "caddy.json", "config_adapter": ""}
2020/06/12 15:36:11.232 INFO    admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["[::1]:2019", "127.0.0.1:2019", "localhost:2019"]}
2020/06/12 15:36:11.232 INFO    git     starting module
2020/06/12 15:36:11.233 INFO    autosaved config        {"file": "/root/.config/caddy/autosave.json"}
2020/06/12 15:36:11.233 INFO    serving initial configuration
Successfully started Caddy (pid=636) - Caddy is running in the background
root@docs:/# 2020/06/12 15:36:11.233    INFO    git     setting up repository   {"path": "/system.wiki"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xc0 pc=0x73e227]

goroutine 17 [running]:
os/exec.(*Cmd).String(0x0, 0x0, 0x15)
        os/exec/exec.go:203 +0x37
github.com/vrongmeal/caddygit/client.(*Command).String(0xc00020b708, 0x0, 0x17b4177)
        github.com/vrongmeal/caddygit@v0.0.0-20200504202456-aefa223497b8/client/commands.go:77 +0x39
github.com/vrongmeal/caddygit/client.(*Commander).Run(0xc0001e1b90, 0x1af3760, 0xc000096d00, 0x0, 0x0)
        github.com/vrongmeal/caddygit@v0.0.0-20200504202456-aefa223497b8/client/commands.go:23 +0x82
github.com/vrongmeal/caddygit/client.(*Client).Start(0xc00015a2c0, 0x1af3760, 0xc000096d00, 0xc0001c9200, 0xc0004791a0)
        github.com/vrongmeal/caddygit@v0.0.0-20200504202456-aefa223497b8/client/client.go:188 +0x56b
created by github.com/vrongmeal/caddygit.(*App).StartClients
        github.com/vrongmeal/caddygit@v0.0.0-20200504202456-aefa223497b8/caddygit.go:107 +0x70

Not sure if those errors are normal or not as this is early release software (probably me doing something wrong! :slight_smile: )

I am running Caddy on a separate server to where the Gitlab instance is installed. It has an internal name of “docs.caminfo.local”. How do I get it to publish to here? Just http://docs.caminfo.local would be fine as it’s an internal only site. That hostname is resolvable by internal DNS.

At present when I visit http://docs.caminfo.local I just get a timeout! :expressionless:

Oof. Yeah that probably shouldn’t happen.

Hey @vrongmeal could you look into this?

Hey @cphillips . If your config is same as above, the error is because there is no command in the config. You need to provide a command along with the “async” parameter. The error is basically you’re trying to execute a command that does not exist.

   "commands_after": [
      {
        "command": [ "echo", "hello world" ],
        "async": true
      }
    ]

This actually works as a feedback though. Need to improve validation for commands. I’ll definitely take a look at this particular error. Thanks!

3 Likes

I’m still having issues with this!

I am just after a barebones config file to publish the content of the Wiki in Gitlab.

My config now looks like this:


  "apps": {
    "git": {
      "clients": [
        {
          "repo": {
            "url": "http://gitlab.caminfo.local/root/system.wiki.git",
          },
          "service": {
            "type": "poll",
            "interval": "10m"
          },
        }
      ]
    }
  }
}

I enter this in a JSON Schema Validator site and it says everything is ok.

If I then run “caddy validate --config caddy.json” it comes back with:

validate: decoding config: invalid character '}' looking for beginning of object key string

I assume the “service” section does a check and updates the published site every 10 minutes? That’s why I’ve left it in as that is useful… If not, is it safe to remove?

I’m not a JSON expert as you may have noticed!

You can’t have a comma at the end of the url line because it’s the last item in the JSON object.

Unfortunately, JSON is pretty strict about syntax.

Thanks, it’s running now!

Final question, hopefully. How do I get it to actually publish to http://docs.caminfo.local ?

At the moment I am getting nothing displayed in a web browser when I go to http://docs.caminfo.local.

Not sure how I would use the contents of a Caddyfile to specify the destination server etc and also make use of the caddy.json file which I seem to need to run the git plugin.

Also, remember that you can use the caddy adapt command to get JSON from your Caddyfile.

Right, I am back to trying to get this up and running.

This code is working ok, with JSON validation passing:

{
"apps": {
    "git": {
      "clients": [
        {
          "repo": {
            "url": "http://gitlab.caminfo.local/root/system.wiki.git",
            "path": "/var/www"
          },
          "service": {
            "type": "poll",
            "interval": "10m"
          }
        }
      ]
    }
  }
}

However, when I run it, nothing is displayed in a web browser. I believe it’s because there is no code telling it the hostname/details of where the caddy server is running.

I used caddy adapt to generate the JSON for the required hostname (http://docs.caminfo.local) and that gave me this:

{"apps":{"http":{"servers":{"srv0":{"listen":[":80"],"routes":[{"match":[{"host":["docs.caminfo.local"]}],"terminal":true}],"automatic_https":{"skip":["docs.caminfo.local"]}}}}}}

So, how do I merge this information into my JSON file above? I’ve tried several iterations but can’t seem to get it right…

Any help greatfully appreciated! :slight_smile:

Just take the http part and put it beside the one with git (both inside apps). The apps are separate.

So I’ve done this, think it’s what you meant:

{
	"apps": {
		"git": {
			"http": {
				"servers": {
					"srv0": {
						"listen": [":80"],
						"routes": [{
							"match": [{
								"host": ["docs.caminfo.local"]
							}],
							"terminal": true
						}],
						"automatic_https": {
							"skip": ["docs.caminfo.local"]
						}
					}
				}
			},
			"clients": [{
				"repo": {
					"url": "http://gitlab.caminfo.local/root/system.wiki.git",
					"path": "/var/www"
				},
				"service": {
					"type": "poll",
					"interval": "10m"
				}
			}]
		}
	}
}

When I run a caddy validate against it, it is returning:

validate: loading git app module: decoding module config: git: json: unknown field "http"

http doesn’t go inside git, it goes inside apps.

http is an app, git is an app. They are separate, they don’t go inside eachother.

Please look at the JSON structure here:

(And I’m hoping that sometime next month the JSON docs on the website will be able to include the third-party modules.)

1 Like