xcaddy build --with module=$(pwd) fails if 'go.mod' includes 'replace' directive

This issue has been created since 2021-10-21.

Hi,

module <mod>

// Required Go version
go 1.16

replace (
        github.com/qri-io/jsonschema => github.com/qri-io/jsonschema v0.2.2-0.20210831022256-780655b2ba0e
        <my_mod> => <mod_on_gitlab_private_repo>.git <ver>
)

require (
        github.com/caddyserver/caddy/v2 v2.4.5
        go.uber.org/zap v1.19.0
        <my_mod> <ver>
)

I am trying to build caddy with builtin own customized plugin with:

xcaddy build --with mod=$(pwd)

but command returns:

(...)
get "golang.org/x/term": found meta tag vcs.metaImport{Prefix:"golang.org/x/term", VCS:"git", RepoRoot:"https://go.googlesource.com/term"} at //golang.org/x/term?go-get=1
get "google.golang.org/protobuf": found meta tag vcs.metaImport{Prefix:"google.golang.org/protobuf", VCS:"git", RepoRoot:"https://go.googlesource.com/protobuf"} at //google.golang.org/protobuf?go-get=1
go get: added github.com/caddyserver/caddy/v2 v2.4.5
2021/10/21 10:35:48 [INFO] Build environment ready
2021/10/21 10:35:48 [INFO] Building Caddy
2021/10/21 10:35:48 [INFO] exec (timeout=0s): /usr/bin/go mod tidy
go: found a in a v0.0.0-00010101000000-000000000000
go: [email protected] requires
        <my_mod>@<ver>: unrecognized import path "<my_mod>": parse <my_mod>?go-get=1: no go-import meta tags ()
2021/10/21 10:35:49 [INFO] Cleaning up temporary folder: /tmp/buildenv_2021-10-21-1035.826449881
2021/10/21 10:35:49 [FATAL] exit status 1

However when I am developing, simply issuing command:

xcaddy run --config Caddyfile

works perfectly. My plugin is loaded and everything is up and running.

Thanks

francislavoie wrote this answer on 2021-10-21

<my_mod>@: unrecognized import path "<my_mod>": parse <my_mod>?go-get=1: no go-import meta tags ()

This means the tooling is trying to do a lookup against your private repo with a query ?go-get=1 but is failing to get a proper response.

You might need to adjust some configuration on your Gitlab repo to make it work.

https://docs.gitlab.com/ee/development/go_guide/dependencies.html#fetching-packages

But ultimately this isn't an issue with xcaddy. All xcaddy does is wrap Go's build tooling to automate the usual steps required to properly assemble a build of Caddy with plugins. The error comes from running go mod tidy.

bataliero wrote this answer on 2021-10-22

Thanks for the answer @francislavoie.
However I am still wondering how it is possible that when I use xcaddy run instead of xcaddy build --with ... everything works correctly and caddy starts:

(...)
2021/10/22 10:27:10 [INFO] Build environment ready
2021/10/22 10:27:10 [INFO] Building Caddy
2021/10/22 10:27:10 [INFO] exec (timeout=0s): /usr/bin/go mod tidy
go: found a in a v0.0.0-00010101000000-000000000000
2021/10/22 10:27:10 [INFO] exec (timeout=0s): /usr/bin/go build -o <path>/caddy -ldflags -w -s -trimpath
2021/10/22 10:27:13 [INFO] Build complete: ./caddy
2021/10/22 10:27:13 [INFO] Cleaning up temporary folder: /tmp/buildenv_2021-10-22-1027.954374132
2021/10/22 10:27:13 [INFO] Running [./caddy run]
(...)

And I didn't change go.mod in a meantime.

francislavoie wrote this answer on 2021-10-22

When you use xcaddy run, it just uses files on disk in your current directory, and doesn't attempt to pull your module from the internet.

bataliero wrote this answer on 2021-10-26

Is not xcaddy build --with <module>=$(pwd) working the same way ? It point to my current directory by using <module>=$(pwd), where all sources are already downloaded (so no pull from the internet is necessary).

mholt wrote this answer on 2021-10-26

Is not xcaddy build --with =$(pwd) working the same way ?

Nope, the way the go.mod file is crafted is different (you can try various commands/inputs, and compare the resulting go.mod files each time). I think you can use XCADDY_SKIP_CLEANUP=1 to preserve the go.mod files.

This file has the logic; compare runDev and runBuild: https://github.com/caddyserver/xcaddy/blob/master/cmd/main.go

More Details About Repo
Owner Name caddyserver
Repo Name xcaddy
Full Name caddyserver/xcaddy
Language Go
Created Date 2020-03-21
Updated Date 2022-09-22
Star Count 381
Watcher Count 14
Fork Count 72
Issue Count 3

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
CORS problem with real domain in installer 0 2021-01-16 2022-08-01
FYI: CREATE and CREATE2 don't work this way 6 2022-04-15 2022-09-06
How to handle literals in FETCH response 5 2021-11-25 2022-09-09
NOeSIS II - Incorrect file names encoding 1 2021-09-11 2022-08-21
Why do not excludes "none" answers in ATOMIC datasets? 2 2021-02-17 2022-09-13
Different inference resullt 1 2021-01-20 2022-08-05
Feeding a bigger size of the input event than 18. 2 2020-06-24 2022-04-02
Environment install problems 2 2021-05-10 2022-08-07
Task:Classifying Generated Tupes 1 2020-07-15 2022-08-16
Incorrect indentation of `\setlength` within `list` environment 5 2021-03-01 2022-07-06
Auto Sort creates errors 2 2021-01-23 2022-09-17
[BUG] Contract Sync error 'ERC20: transfer amount exceeds balance' 6 2022-05-29 2022-09-23
How to get monitor to run monitor.sh -tdr -a -b after restart 4 2021-01-05 2022-05-23
Duplicates are being allowed if tag contains whitespace 4 2019-02-20 2022-09-06
Source Map Pointing To Dev Local File 1 2020-07-24 2022-09-06
Add Plausible Analytics 0 2021-07-20 2022-09-11
Blockquote styling 1 2021-07-19 2021-12-25
Redirect RSS and surface / link feed 1 2021-07-20 2022-09-13
Search map review 0 2021-07-20 2021-12-25
How to set font pack : regular,italic,bold,bold italic 0 2021-06-13 2022-09-20
Carousel items not rendering in unit tests (jest+RTL) 3 2020-11-11 2022-07-29
Local development using a VM 0 2021-07-29 2022-09-12
ORA-44004: invalid qualified SQL name 2 2022-05-19 2022-09-18
Deadbeef crashes since kernel 5.14 3 2021-09-20 2022-08-22
Add `getpass` configuration option to read secrets from password managers 1 2021-12-16 2022-09-23
Unexpected existence_error if attribute_goals//1 is not defined 2 2022-04-17 2022-07-21
Create dark mode theme 1 2022-02-25 2022-05-29
Adding a book to list that already has the book gives vague error 0 2022-02-27 2022-05-29
Most Beloved Book on Instance has zero local reviews 1 2022-02-27 2022-05-29
Entering a percentage with a decimal does not post 1 2022-02-21 2022-05-29
rizin tests 0 2021-09-29 2021-12-31
Propogate "--key-password" websockify option to launch.sh 3 2020-11-13 2022-09-01
After discarding a voice message a restart is required 1 2022-03-11 2022-07-21
Add ARM support for app_server image 1 2022-07-28 2022-09-09
TGUI Number input cannot be autofocused/selected 0 2022-01-02 2022-07-20
Add Stoplight branding to docs 0 2020-12-16 2022-07-16
We need a worker SDK extension package for Tables 1 2022-01-25 2022-09-17
Update Global Game Jam 2021 with featured games 0 2022-01-12 2022-09-28
Very long type signatures are not dealt with well 2 2020-04-24 2022-07-25
Can we add CN and organization info in blackbox labels 2 2021-05-03 2022-09-28
Annoying book banner in docs 0 2022-01-06 2022-09-17
Element ID CSS Selectors for events don't work 0 2022-09-02 2022-09-21
Quickstart Issues 4 2021-10-31 2021-12-27
No lovelace-background display for themes 1 2021-12-04 2022-07-14
justMyCode: false yields error "This configuration can only be used as defined by `purpose`." 6 2021-09-09 2022-09-08
Missing releases for last two versions 2 2022-02-04 2022-09-21
chore(deps-dev): [security] bump semantic-release from 15.14.0 to 17.4.4 0 2021-06-16 2022-09-14
Missing 'cluster scheduled for deletion' message when deleting cluster 0 2022-07-01 2022-08-27
Add some more <meta> tags 1 2021-09-04 2022-09-29
IOperation support for list patterns 5 2021-10-17 2022-01-30