dnephin / dobi

A build automation tool for Docker applications
https://dnephin.github.io/dobi/
Apache License 2.0
309 stars 36 forks source link

Add an example of job:capture #146

Closed dnephin closed 6 years ago

dnephin commented 6 years ago

Closes #142 Closes #144

Fuco1 commented 6 years ago

Hey @dnephin the example does not seem to work.

[12:12:20]matus@brno-pc-02:~/dev/dobi/examples/env-vars
> cat dobi.yaml

mount=source:
  bind: .
  path: /app

image=bash:
  image: bash
  tags: ['4.4']
  pull: once

job=print-version:
  use: bash
  mounts: [source]
  command: /app/print-version.sh

image=dist:
  image: repo/myapp
  context: .
  tags: ["{env.VERSION}"]
  depends:
    - "print-version:capture(VERSION)"
[12:12:23]matus@brno-pc-02:~/dev/dobi/examples/env-vars
> dobi dist
[WARN] meta.project is not set. Using default "env-vars".
[WARN] [image:pull bash] bash Failed to get image record: stat /home/matus/dev/dobi/examples/env-vars/.dobi/images/bash 4.4: no such file or directory
4.4: Pulling from library/bash
Digest: sha256:72ec7dba36ee88a2296ffc670e30cb1b9f68a0b824bea0e71ea48110d51beaaa
Status: Image is up to date for bash:4.4
[image:pull bash] bash Pulled
[job:capture(VERSION) print-version] /app/print-version.sh Start
[job:capture(VERSION) print-version] /app/print-version.sh Done
[ERROR] a value is required for variable "env.VERSION"
[12:12:29]matus@brno-pc-02:~/dev/dobi/examples/env-vars
> dobi --version
dobi version 0.11.1 (build: ee9138c, date: Sun Jun 24 19:40:44 UTC 2018)

Do I need some newer version than this?

Fuco1 commented 6 years ago

Hmm, weird, when I run it again it works

[12:16:33]matus@brno-pc-02:~/dev/dobi/examples/env-vars
> dobi dist
[WARN] meta.project is not set. Using default "env-vars".
[WARN] [image:pull bash] bash Failed to get image record: stat /home/matus/dev/dobi/examples/env-vars/.dobi/images/bash 4.4: no such file or directory
4.4: Pulling from library/bash
Digest: sha256:72ec7dba36ee88a2296ffc670e30cb1b9f68a0b824bea0e71ea48110d51beaaa
Status: Image is up to date for bash:4.4
[image:pull bash] bash Pulled
[job:capture(VERSION) print-version] /app/print-version.sh Start
3.4.5
[job:capture(VERSION) print-version] /app/print-version.sh Done
Step 1/1 : FROM alpine
 ---> 3fd9065eaf02
Successfully built 3fd9065eaf02
Successfully tagged repo/myapp:3.4.5
[image:build dist] repo/myapp Created

Same with my own job. What I've done was I rewrote the dependency task as capture('VERSION') to which it said [ERROR] invalid capture format "capture('VERSION')" and after that it run through fine.

dnephin commented 6 years ago

That is really strange. There is a test for the examples, which should run in a fresh environment in CI, and it seems to have passed.

I'm not sure how the single quotes around VERSION will work, it's meant to be unquoted.

Fuco1 commented 6 years ago

I mean I caused the build to error with the syntax error, then I removed the quotes and then it passed.

I reproduced this with 3 different projects. I can't send you the production one for obvious reasons but this even happens on the example. I'll try different machine, maybe it's something funny with my computer or maybe there are some caches which are not being cleaned up properly (./dobi/* ?)

dnephin commented 6 years ago

I think the problem might be:

[job:capture(VERSION) print-version] /app/print-version.sh Start
[job:capture(VERSION) print-version] /app/print-version.sh Done

It seems that it ran the command but nothing was captured. I think there is a race condition on capturing the stdout of the process. I believe I've seen this fail in the test suite occasionally.

I'll see if I can find the source of the bug.

dnephin commented 6 years ago

Thanks for reporting the issue. I pushed another commit which I believe fixes the problem. The copy of stdout/stderr happens in another goroutine and I wasn't waiting on the copy to finish.