balena-io / balena-cli

The official balena CLI tool.
Apache License 2.0
455 stars 143 forks source link

--dockerfile flag should supersede docker-compose.yml in source directory #2566

Open shasderias opened 2 years ago

shasderias commented 2 years ago

Expected Behavior

Running balena push with the --dockerfile flag should build with the specified Dockerfile even if there is a docker-compose.yml in the root of the source directory.

Actual Behavior

balena-cli tries to use docker-compose.yml, ignoring the --dockerfile flag.

C:\dev\gsw>balena push shasderias --dockerfile .\docker\client\Dockerfile --debug
[debug] new argv=[C:\Users\shasderias\scoop\apps\balena-cli\current\balena.exe,C:\snapshot\balena-cli\bin\balena,push,shasderias,--dockerfile,.\docker\client\Dockerfile] length=6
[debug] Deprecation check: 0.01131 days since last npm registry query for next major version release date.
[debug] Will not query the registry again until at least 7 days have passed.
[Debug]   Using build source directory: .
[Debug]   Pushing to cloud for fleet: shasderias
[debug] Event tracking error: Timeout awaiting 'response' for 0ms
| Packaging the project source...[Debug]   Tarring all non-ignored files...
[Debug]   docker-compose.yml file found at "C:\dev\gsw"
data/services should NOT have additional properties

ValidationError: data/services should NOT have additional properties
    at normalizeObjectToComposition (C:\snapshot\balena-cli\node_modules\@balena\compose\dist\parse\compose.js:88:19)
    at Object.normalize (C:\snapshot\balena-cli\node_modules\@balena\compose\dist\parse\compose.js:48:16)
    at createProject (C:\snapshot\balena-cli\build\utils\compose.js:23:33)
    at getServiceDirsFromComposition (C:\snapshot\balena-cli\build\utils\compose_ts.js:354:27)
    at async tarDirectory (C:\snapshot\balena-cli\build\utils\compose_ts.js:393:25)
    at async getTarStream (C:\snapshot\balena-cli\build\utils\remote-build.js:209:27)
    at async getRemoteBuildStream (C:\snapshot\balena-cli\build\utils\remote-build.js:270:23)
    at async Object.startRemoteBuild (C:\snapshot\balena-cli\build\utils\remote-build.js:39:36)
    at async PushCmd.pushToCloud (C:\snapshot\balena-cli\build\commands\push.js:78:27)
    at async PushCmd.run (C:\snapshot\balena-cli\build\commands\push.js:32:17)
    at async PushCmd._run (C:\snapshot\balena-cli\node_modules\@oclif\command\lib\command.js:43:20)
    at async Config.runCommand (C:\snapshot\balena-cli\node_modules\@oclif\config\lib\config.js:175:24)
    at async CustomMain.run (C:\snapshot\balena-cli\node_modules\@oclif\command\lib\main.js:27:9)
    at async CustomMain._run (C:\snapshot\balena-cli\node_modules\@oclif\command\lib\command.js:43:20)
    at async C:\snapshot\balena-cli\build\app.js:76:13
    at async Promise.all (index 2)

For further help or support, visit:
https://www.balena.io/docs/reference/balena-cli/#support-faq-and-troubleshooting

/ Uploading source package to https://builder.balena-cloud.com
C:\dev\gsw>

Steps to Reproduce the Problem

This is the most important and helpful part of a bug report. If we cannot reproduce the problem, it is difficult to tell what the fix should be, or whether code changes have fixed it.

C:\dev>mkdir balenaf

C:\dev>cd balenaf

C:\dev\balenaf>dir
 Volume in drive C has no label.
 Volume Serial Number is 762A-78B8

 Directory of C:\dev\balenaf

11/24/2022  05:11 AM    <DIR>          .
11/24/2022  05:11 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  247,651,012,608 bytes free

C:\dev\balenaf>echo rubbish > docker-compose.yml

C:\dev\balenaf>mkdir docker

C:\dev\balenaf>echo FROM scratch > docker\Dockerfile

C:\dev\balenaf>balena push shasderias --dockerfile docker\Dockerfile
Invalid composition format

Additional information may be available with the `--debug` flag.

For further help or support, visit:
https://www.balena.io/docs/reference/balena-cli/#support-faq-and-troubleshooting

/ Uploading source package to https://builder.balena-cloud.com
C:\dev\balenaf>del docker-compose.yml

C:\dev\balenaf>balena push shasderias --dockerfile docker\Dockerfile
| Packaging the project source...[Info]    Converting line endings CRLF -> LF for file: C:\dev\balenaf\docker\Dockerfile
[Info]     Starting build for shasderias, user lyc
[Info]     Dashboard link: https://dashboard.balena-cloud.com/apps/1803020/devices
[Info]     Building on arm01
[Info]     Pulling previous images for caching purposes...
[Success]  Successfully pulled cache images
[main]     Step 1/1 : FROM scratch
[main]      --->
[main]     No image was generated. Is your Dockerfile empty?
[Error]    Some services failed to build:
[Error]      Service: main
[Error]        Error: No image was generated. Is your Dockerfile empty?
[Info]     Built on arm01
[Error]    Not deploying release.
Remote build failed

(the build failure is expected, just trying to show that the presence of docker-compose.yml forces the build to use it)

Specifications

Additional References

N/A

shasderias commented 2 years ago

As a workaround, I tried putting docker-compose.yml in .dockerignore.

Unfortunately, this does not work, most likely due to the default/hardcoded .dockerignore patterns:

https://www.balena.io/docs/reference/balena-cli/#push-fleetordevice