semaphore icon indicating copy to clipboard operation
semaphore copied to clipboard

Packaging semaphore: Starting the service fails with "db/sql/migrations/v0.0.0.sql: no such file or directory"

Open johanneskastl opened this issue 2 years ago • 3 comments

I am trying to package ansible-semaphore for openSUSE, but the semaphore executable fails during semaphore setup with the following message:

[...]
Running: mkdir -p /root..
Configuration written to /root/config.json..
 Pinging db..
Running db Migrations..
Executing migration v0.0.0 (at 2023-04-19 20:12:17.621691151 +0000 UTC m=+19.517298123)...
Creating migrations table
panic: stat /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/db/sql/migrations/v0.0.0.sql: no such file or directory

goroutine 1 [running]:
github.com/ansible-semaphore/semaphore/db/sql.getVersionSQL({0xc0001649d0?, 0xc0000b7648?})
        /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/db/sql/migration.go:40 +0x1aa
github.com/ansible-semaphore/semaphore/db/sql.(*SqlDb).ApplyMigration(0xc000014778, {{0x55707473e04d?, 0x55707475c8fb?}, 0x0?, 0x0?})
        /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/db/sql/migration.go:143 +0x16a
github.com/ansible-semaphore/semaphore/db.Migrate({0x557074b1e4a8, 0xc000014778})
        /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/db/Migration.go:79 +0x253
github.com/ansible-semaphore/semaphore/cli/cmd.doSetup()
        /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/cli/cmd/setup.go:44 +0x1de
github.com/ansible-semaphore/semaphore/cli/cmd.glob..func4(0x557074f3cda0?, {0x55707473dbc1?, 0x0?, 0x0?})
        /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/cli/cmd/setup.go:23 +0x17
github.com/spf13/cobra.(*Command).execute(0x557074f3cda0, {0x557074f793a0, 0x0, 0x0})
        /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/vendor/github.com/spf13/cobra/command.go:860 +0x663
github.com/spf13/cobra.(*Command).ExecuteC(0x557074f3bea0)
        /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/vendor/github.com/spf13/cobra/command.go:974 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/vendor/github.com/spf13/cobra/command.go:902
github.com/ansible-semaphore/semaphore/cli/cmd.Execute()
        /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/cli/cmd/root.go:36 +0x5b
main.main()
        /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/cli/main.go:8 +0x17

The command to build the executable is based on this line: https://github.com/ansible-semaphore/semaphore/blob/develop/Taskfile.yml#L133

go run util/version_gen/generator.go %{version}
go build \
   -mod=vendor \
   -buildmode=pie \
   -o bin/ansible-semaphore ./cli/main.go

The paths like /home/abuild/rpmbuild/BUILD/semaphore-2.8.89/cli/main.go are the paths that were used during build, not sure if -trimpath or similar would help here.

Any idea where I could start looking?

johanneskastl avatar Apr 20 '23 14:04 johanneskastl

Looks like resources not added to package.

Did you call task compile?

fiftin avatar Apr 25 '23 17:04 fiftin

Looks like resources not added to package.

Did you call task compile?

Sorry for the late response.

Yes, I tried to. Due to the build happening in an environment without network connectivity, the parts from compile:fe2 and compile:be are done beforehand, and the resulting web/ directory is handed to the build as a tarball.

I think the problem might be the missing packr step. I'll have a closer look and report back.

johanneskastl avatar May 03 '23 13:05 johanneskastl

I think the problem might be the missing packr step. I'll have a closer look and report back.

I packaged packr (2.x) for openSUSE and am using it to run the packr step. I added some more debugging steps:

%build                                                                                                                                                                                       
mkdir -p web/dist
go run util/version_gen/generator.go %{version}
packr -v --legacy
ls -lh db/db-packr.go || true
ls -lh api/api-packr.go || true
packr -v
ls -lh db/db-packr.go || true
ls -lh api/api-packr.go || true
exit 99                                                                                                                                                                                      
go build \                                                                                                                                                                                   
   -mod=vendor \                                                                                                                                                                             
   -buildmode=pie \                                                                                                                                                                          
   -o bin/ansible-semaphore ./cli/

The output shows, that packr just does not generate the files that (according to Taskfile.yml) should be generated:

[   49s] + cd semaphore-2.8.90
[   49s] + mkdir -p web/dist
[   49s] + go run util/version_gen/generator.go 2.8.90
[   49s] + packr -v --legacy
[   49s] DEBU[2023-05-04T07:54:49Z] *parser.Parser#NewFromRoots options="{\"IgnoreImports\":false,\"Ignores\":null}" roots="[\"/home/abuild/rpmbuild/BUILD/semaphore-2.8.90\"]"
[   49s] DEBU[2023-05-04T07:54:49Z] *parser.Parser#NewFromRoots walking=/home/abuild/rpmbuild/BUILD/semaphore-2.8.90
[   49s] DEBU[2023-05-04T07:54:49Z] *parser.Parser#NewFromRoots found prospects=0
[   49s] DEBU[2023-05-04T07:54:49Z] *parser.Parser#NewFromRoots options="{\"IgnoreImports\":false,\"Ignores\":null}" roots="[\"/home/abuild/rpmbuild/BUILD/semaphore-2.8.90\"]"
[   49s] DEBU[2023-05-04T07:54:49Z] *parser.Parser#NewFromRoots walking=/home/abuild/rpmbuild/BUILD/semaphore-2.8.90
[   49s] DEBU[2023-05-04T07:54:49Z] *parser.Parser#NewFromRoots found prospects=0
[   49s] DEBU[2023-05-04T07:54:49Z] *parser.Parser#NewFromRoots options="{\"IgnoreImports\":false,\"Ignores\":null}" roots="[\"/home/abuild/rpmbuild/BUILD/semaphore-2.8.90\"]"
[   49s] DEBU[2023-05-04T07:54:49Z] *parser.Parser#NewFromRoots walking=/home/abuild/rpmbuild/BUILD/semaphore-2.8.90
[   49s] DEBU[2023-05-04T07:54:49Z] *parser.Parser#NewFromRoots found prospects=0
[   49s] DEBU[2023-05-04T07:54:49Z] found 0 boxes
[   49s] + ls -lh db/db-packr.go
[   49s] ls: cannot access 'db/db-packr.go': No such file or directory
[   49s] + true
[   49s] + ls -lh api/api-packr.go
[   49s] ls: cannot access 'api/api-packr.go': No such file or directory
[   49s] + true
[   54s] + packr -v
[   54s] DEBU[2023-05-04T07:54:54Z] *parser.Parser#NewFromRoots options="{\"IgnoreImports\":false,\"Ignores\":null}" roots="[\"/home/abuild/rpmbuild/BUILD/semaphore-2.8.90\"]"
[   54s] DEBU[2023-05-04T07:54:54Z] *parser.Parser#NewFromRoots walking=/home/abuild/rpmbuild/BUILD/semaphore-2.8.90
[   54s] DEBU[2023-05-04T07:54:54Z] *parser.Parser#NewFromRoots found prospects=0
[   54s] DEBU[2023-05-04T07:54:54Z] *parser.Parser#NewFromRoots options="{\"IgnoreImports\":false,\"Ignores\":null}" roots="[\"/home/abuild/rpmbuild/BUILD/semaphore-2.8.90\"]"
[   54s] DEBU[2023-05-04T07:54:54Z] *parser.Parser#NewFromRoots walking=/home/abuild/rpmbuild/BUILD/semaphore-2.8.90
[   54s] DEBU[2023-05-04T07:54:54Z] *parser.Parser#NewFromRoots found prospects=0
[   54s] DEBU[2023-05-04T07:54:54Z] *parser.Parser#NewFromRoots options="{\"IgnoreImports\":false,\"Ignores\":null}" roots="[\"/home/abuild/rpmbuild/BUILD/semaphore-2.8.90\"]"
[   54s] DEBU[2023-05-04T07:54:54Z] *parser.Parser#NewFromRoots walking=/home/abuild/rpmbuild/BUILD/semaphore-2.8.90
[   54s] DEBU[2023-05-04T07:54:54Z] *parser.Parser#NewFromRoots found prospects=0
[   54s] DEBU[2023-05-04T07:54:54Z] found 0 boxes
[   54s] + ls -lh db/db-packr.go
[   54s] ls: cannot access 'db/db-packr.go': No such file or directory
[   54s] + true
[   54s] + ls -lh api/api-packr.go
[   54s] ls: cannot access 'api/api-packr.go': No such file or directory
[   54s] + true
[   59s] + exit 99

So, this could be because the packr I am using is a lot newer than the one that is being used according to go.mod (v1.10.4).

It would be really nice if #1015 would be tackled soon :-)

johanneskastl avatar May 04 '23 08:05 johanneskastl

After updating to 2.9.56, removing packr and adjusting the build steps I now have a working package, i.e. the service starts and the UI is reachable. I'll further test the package, but this issue is solved...

johanneskastl avatar Mar 25 '24 06:03 johanneskastl