Hi everyone! I'm currently trying to setup an ins...
# talk-kratos
q
Hi everyone! I'm currently trying to setup an instance of Kratos on my server, however, I seem to do something wrong, because I keep getting this when starting the migrations:
Copy code
Error: unknown shorthand flag: 'c' in -c /etc/config/kratos.json migrate sql -e --yes
Usage:
  kratos [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  courier     Commands related to the Ory Kratos message courier
  delete      Delete resources
  format      Helpers for formatting code
  get         Get resources
  hashers     This command contains helpers around hashing
  help        Help about any command
  import      Import resources
  lint        Helpers for linting code
  list        List resources
  migrate     Various migration helpers
  remote      Helpers and management for remote Ory Kratos instances
  serve       Run the Ory Kratos server
  validate    Validate resources
  version     Show the build version, build time, and git hash

Flags:
  -h, --help   help for kratos
My setup is as follows: 1. Build a custom docker image based on
oryd/kratos:v0.10.1
with my configuration 2. Create a container and deploy it on my machine using Nomad As soon as Nomad tries to start the migration container, though, I'm getting the error message above. The configuration looks like this:
Copy code
driver = "docker"

      config {
        image = "resource of custom image"
        command = "-c /etc/config/kratos.json migrate sql -e --yes"
        
        ..
      }
Trying it locally with docker compose (Windows) it works like a charm. Soo what could go wrong here? Server's Docker versions are up-to-date:
Copy code
Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:03:11 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:17 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
r
-c
works with compose, but not with nomad? maybe write it out
q
Mornin'! Tried that already, got the same issue. I've tinkered around a little bit more this morning, found out that when using the command option in Nomad it would start the docker container like this:
kratos '-c /etc/config/...'
With docker-compose, however, it wouldn't have the single quotes. Played around with the Nomad configuration then, got this now instead:
Copy code
config {
        image = "<http://containers.tbureck.de/rheinland-games/online-game-platform/id-server:[[.versionToDeploy]]|containers.tbureck.de/rheinland-games/online-game-platform/id-server:[[.versionToDeploy]]>"
        args = ["-c /etc/config/kratos.json", "migrate", "sql", "-e", "--yes"]

        auth {
...
        }
     }
This works up to the point when Kratos wants to load the configuration. It'll now complain the file doesn't exist:
Copy code
time=2022-08-28T08:12:31Z level=debug msg=Adding config files. func=<http://github.com/ory/x/configx.(*Provider).createProviders|github.com/ory/x/configx.(*Provider).createProviders> file=/go/pkg/mod/github.com/ory/x@v0.0.392/configx/provider.go:155 audience=application files=[ /etc/config/kratos.json] service_name=Ory Kratos service_version=v0.10.1
time=2022-08-28T08:12:31Z level=fatal msg=Unable to instantiate configuration. func=<http://github.com/ory/kratos/driver.NewWithoutInit|github.com/ory/kratos/driver.NewWithoutInit> file=/project/driver/factory.go:26 audience=application error=map[message:no such file or directory stack_trace:
<http://github.com/ory/x/watcherx.WatchFile|github.com/ory/x/watcherx.WatchFile>
	/go/pkg/mod/github.com/ory/x@v0.0.392/watcherx/file.go:22
<http://github.com/ory/x/configx.(*KoanfFile).WatchChannel|github.com/ory/x/configx.(*KoanfFile).WatchChannel>
	/go/pkg/mod/github.com/ory/x@v0.0.392/configx/koanf_file.go:89
<http://github.com/ory/x/configx.(*Provider).createProviders|github.com/ory/x/configx.(*Provider).createProviders>
	/go/pkg/mod/github.com/ory/x@v0.0.392/configx/provider.go:163
<http://github.com/ory/x/configx.New|github.com/ory/x/configx.New>
	/go/pkg/mod/github.com/ory/x@v0.0.392/configx/provider.go:117
<http://github.com/ory/kratos/driver/config.New|github.com/ory/kratos/driver/config.New>
	/project/driver/config/config.go:335
<http://github.com/ory/kratos/driver.NewWithoutInit|github.com/ory/kratos/driver.NewWithoutInit>
	/project/driver/factory.go:24
<http://github.com/ory/kratos/cmd/cliclient.(*MigrateHandler).MigrateSQL|github.com/ory/kratos/cmd/cliclient.(*MigrateHandler).MigrateSQL>
	/project/cmd/cliclient/migrate.go:30
<http://github.com/ory/kratos/cmd/migrate.NewMigrateSQLCmd.func1|github.com/ory/kratos/cmd/migrate.NewMigrateSQLCmd.func1>
	/project/cmd/migrate/sql.go:44
<http://github.com/spf13/cobra.(*Command).execute|github.com/spf13/cobra.(*Command).execute>
	/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:860
<http://github.com/spf13/cobra.(*Command).ExecuteC|github.com/spf13/cobra.(*Command).ExecuteC>
	/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:974
<http://github.com/spf13/cobra.(*Command).Execute|github.com/spf13/cobra.(*Command).Execute>
	/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:902
<http://github.com/ory/kratos/cmd.Execute|github.com/ory/kratos/cmd.Execute>
	/project/cmd/root.go:51
main.main
	/project/main.go:35
runtime.main
	/usr/local/go/src/runtime/proc.go:255
runtime.goexit
	/usr/local/go/src/runtime/asm_amd64.s:1581] service_name=Ory Kratos service_version=v0.10.1
When running an
ls
on the folder of that container, however, everything looks good:
Copy code
docker run --entrypoint ls <http://containers.tbureck.de/rheinland-games/online-game-platform/id-server:main-d2f5f2fa|containers.tbureck.de/rheinland-games/online-game-platform/id-server:main-d2f5f2fa> -al /etc/config
total 16
drwxr-xr-x    1 root     root          4096 Aug 28 08:12 .
drwxr-xr-x    1 root     root          4096 Aug 28 08:17 ..
-rw-rw-rw-    1 root     root          2761 Aug 13 07:23 kratos.json
-rw-rw-rw-    1 root     root           952 Aug 13 07:03 player.schema.json
What's weird in the logs is, that the path to the config has a leading space. I'd expect it underlying libraries to handle that correctly, but maybe there's a thing in Go that this is somewhat important? idk
So yeah, leaving away the space between argument flag and value works:
Copy code
args = ["-c/etc/config/kratos.json", "migrate", "sql", "-e", "--yes"]
I don't really understand why this is only the case when deploying via Nomad, I guess it's something with their Docker driver 🤔
r
I guess that’s similar to
CMD
in Docker
i would probably try:
Copy code
“-c“,“/etc/config/kratos.json“,…
But I have no idea about nomad, just casually observing 😅
I think argv parsing is black magic all around. What does nomad give you in your stack? I am curious.
q
Yeah, the documentation suggests, that the command option is mapped to Docker's CMD. But the resulting format was different, so I guess that's why it didn't work
Nomad is a "workload orchestrator". Something like Kubernetes in easier (and less features per se). It lets you deploy different artifacts on your connected machines. I'm using it together with GitLab CI (Build&Test) > Nomad (Deploy) > Consul (Service discovery) > Traefik (RevProxy) for automated deployments