Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial implementation of artifacts for test command #4302

Merged
merged 7 commits into from
May 23, 2024

Conversation

maroshii
Copy link
Contributor

Proposed changes

Adds artifacts to test command that allows to export files to the local file system after buildkit execution:

test:
  echo:
    artifacts:
      - a
      - b
      - c
      - d
    commands:
      - mkdir a b c d
      - echo "A" > a/1.txt
      - echo "B" > b/2.txt
      - echo "C" > c/3.txt
      - echo "D" > d/4.txt
      - ls -l

The above manifest will export the following the local filesystem:

./.okteto-output/
├── a
│   └── 1.txt
├── b
│   └── 2.txt
├── c
│   └── 3.txt
└── d
    └── 4.txt

Open Questions

  • Do we want to write to .okteto-output or do we rather just right relative to the cwd?

⚠️ CAVEAT ⚠️

This was marked as a partial implementation because it only works for successful builds. If the build fails nothing will get written. I'm not sure if buildkit has a way to export regardless of failure but this is still a big unknown for this feature. The docs for local export has no info on this and assumes that the build succeeds. I'll keep investigating cc @pchico83

@maroshii maroshii requested a review from a team as a code owner May 20, 2024 20:07
@andreafalzetti
Copy link
Contributor

andreafalzetti commented May 20, 2024

Code changes LGTM. About the failing build I have no suggestions yet, but I've done some initial tests, so far so good, only one odd behaviour perhaps with the following scenario, I think due to cache, when exporting artifacts, it also includes previous ones. For example:

test:
  unit:
    context: unit
    artifacts:
      - /
    commands:
      - name: Run unit tests
        command: mkdir report && echo hola > report/hola.txt && echo ciao > report/ciao.txt
okteto test

# i  Using ******@ ***** as context
# i  'go-getting-started' was already deployed. To redeploy run 'okteto deploy'
# i  Executing 'unit'


ls -la .okteto-output
drwx------   4 andrea  staff  128 20 May 22:31 .
drwxr-xr-x  19 andrea  staff  608 20 May 22:31 ..
-rw-r--r--   1 andrea  staff    5 20 May 09:26 hola.txt
drwxr-xr-x   4 andrea  staff  128 20 May 22:28 report

ls -la .okteto-output/report
drwxr-xr-x  4 andrea  staff  128 20 May 22:28 .
drwx------  4 andrea  staff  128 20 May 22:31 ..
-rw-r--r--  1 andrea  staff    5 20 May 22:28 ciao.txt
-rw-r--r--  1 andrea  staff    5 20 May 22:28 hola.txt

then modify okteto.yml and change the manifest to:

test:
  unit:
    context: unit
    artifacts:
      - /
    commands:
      - name: Run unit tests
        command: mkdir report && echo hola > report/hola2.txt && echo ciao > report/ciao2.txt

Run again and observe the duplicates:

okteto test

# i  Using ******@ ***** as context
# i  'go-getting-started' was already deployed. To redeploy run 'okteto deploy'
# i  Executing 'unit'


ls -la .okteto-output
drwx------   4 andrea  staff  128 20 May 22:38 .
drwxr-xr-x  19 andrea  staff  608 20 May 22:37 ..
-rw-r--r--   1 andrea  staff    5 20 May 09:26 hola.txt
drwxr-xr-x   6 andrea  staff  192 20 May 22:38 report

ls -la .okteto-output/report
drwxr-xr-x  6 andrea  staff  192 20 May 22:38 .
drwx------  4 andrea  staff  128 20 May 22:38 ..
-rw-r--r--  1 andrea  staff    5 20 May 22:28 ciao.txt
-rw-r--r--  1 andrea  staff    5 20 May 22:38 ciao2.txt
-rw-r--r--  1 andrea  staff    5 20 May 22:28 hola.txt
-rw-r--r--  1 andrea  staff    5 20 May 22:38 hola2.txt

If I use this to export test reports, especially for HTML based reports, it's very likely that this could be an issue. WDYT?

@pchico83
Copy link
Contributor

I think exporting only on success is okay for this iteration. I don't think buildkit will help, we would need to always return success at the buildkit level and manage the error on our side.
About .okteto-output, I think the experience is better if we write relative to the cwd. That helps, for example, if you do things like go mod tidy. In general, adopting the Okteto Test requires fewer changes if we use the current path. And we can always make this path optional if it becomes an issue

@jLopezbarb
Copy link
Contributor

Should we support something like what CircleCI does to export it to a custom local path:

- store_artifacts:
          path: /tmp/artifact-1
          destination: artifact-file

I think it's ok to have a default destination but I think the user could want to export to a specific file that is already in the .oktetoignore. WDYT?

@jLopezbarb
Copy link
Contributor

Tested and working correctly. Also tested removing a file and checked if the cache would regenerate the file. So despite of the question that I asked I think the code and behaviour is ok

@maroshii
Copy link
Contributor Author

Should we support something like what CircleCI does to export it to a custom local path:

- store_artifacts:
          path: /tmp/artifact-1
          destination: artifact-file

I think it's ok to have a default destination but I think the user could want to export to a specific file that is already in the .oktetoignore. WDYT?

If we want to have buildkit and the concept of containerization abstracted away from the user, path/destination doesn't really mean anything. I think it makes sense if we want to expose (conceptually) that the execution context is not the user's filesystem. Given that we already have "context" in the test manifest and that we do document how tests and remote deploy works, we are already in the path of not hiding it away so I would add it 👌

@maroshii
Copy link
Contributor Author

maroshii commented May 21, 2024

I don't think buildkit will help, we would need to always return success at the buildkit level and manage the error on our side.

Yeah, agree that's the way to go. It will have an impact on buildkit metrics tho since once we change this all builds will succeed

@maroshii
Copy link
Contributor Author

If I use this to export test reports, especially for HTML based reports, it's very likely that this could be an issue. WDYT?

@andreafalzetti Looking at it in more detail, I think that's the expected behavior. If you add an && ls -l in the command you will see that the previous files are not in the container filesystem which is good.

I think the "issue" is that when files are exported, buildkit is smart enough to merge the local filesystem with the exported files. I think it's acceptable, if user don't want this they can nuke the folder before running okteto test. In CI it will have no effect I guess

@maroshii
Copy link
Contributor Author

PR is good to go. New changes:

  • Extended syntax for path and destination in artifact section is supported
  • output is no longer written to ./okteto-output, it is now written to the context root path
  • fix linting errors

@maroshii maroshii changed the title [okteto test] Partial implementation of artifacts Partial implementation of artifacts for test command May 21, 2024
Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 43.11%. Comparing base (98675e6) to head (1bac634).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4302      +/-   ##
==========================================
+ Coverage   43.07%   43.11%   +0.04%     
==========================================
  Files         370      371       +1     
  Lines       30020    30045      +25     
==========================================
+ Hits        12931    12954      +23     
+ Misses      15966    15964       -2     
- Partials     1123     1127       +4     

@pchico83
Copy link
Contributor

I don't think buildkit will help, we would need to always return success at the buildkit level and manage the error on our side.

Yeah, agree that's the way to go. It will have an impact on buildkit metrics tho since once we change this all builds will succeed

@maroshii we don't rely on buildkit for metrics, the build status is reported by the Okteto CLI. We would also have control on the metrics generated by failed builds

@pchico83
Copy link
Contributor

  • Extended syntax for path and destination in artifact section is supported

@maroshii could you explain the new syntax with a few samples if needed?

@andreafalzetti
Copy link
Contributor

andreafalzetti commented May 22, 2024

as discussed offline, with the latest changes in this PR, the logs of the test commands are not visibile. Example

test:
  load:
    context: .
    commands:
      - name: "Say Hi"
        command: echo hiii && exit 1

With 2.27.21 I get:

 i  Using ** @ ** as context
 i  'tmp.RMs0oBYF6M' was already deployed. To redeploy run 'okteto deploy'
 i  Executing 'load'
 i  Running stage 'load'
 i  Running 'Say Hi'
hiii
 x  Error on stage load:  x  Exit status 1

With this build:

 i  Using ** @ ** as context
 i  'tmp.RMs0oBYF6M' was already deployed. To redeploy run 'okteto deploy'
 i  Executing 'load'

@maroshii
Copy link
Contributor Author

could you explain the new syntax with a few samples if needed?

@pchico83 will do. We still need to update the docs with everything new we added besides this and the latest changes. PRs are in place but postponing until we are feature complete

@maroshii
Copy link
Contributor Author

as discussed offline, with the latest changes in this PR, the logs of the test commands are not visibile. Example

@andreafalzetti thanks for report this. It was indeed a regression.

The error was that when no artifacts were defined, there were no CPOY --from=runner ... instructions in the final image so the runner image was never built, just the scratch. This is because BuildKit only builds the stages that the target stage depends on as opposed to the previous docker builder

Now, we save the cachekey value in a file and include it no the final image if no artifacts are defined, which ensures the runner image is always considered in builds.

Fixed here: a98bce5

@maroshii maroshii merged commit 823c6d7 into master May 23, 2024
10 of 12 checks passed
@maroshii maroshii deleted the fran/test-outputs branch May 23, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants