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

Build zipped package #550

Merged
merged 18 commits into from
Oct 25, 2021
Merged

Conversation

mtojek
Copy link
Contributor

@mtojek mtojek commented Oct 21, 2021

Issue: elastic/package-registry#728

This PR modifies:
-build command to also built .zip packages (--zip flag)
-clean command to clean built .zip

@mtojek mtojek self-assigned this Oct 21, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Oct 21, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-10-25T13:29:46.535+0000

  • Duration: 35 min 45 sec

  • Commit: 92ef5d7

Test stats 🧪

Test Results
Failed 0
Passed 438
Skipped 4
Total 442

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@mtojek mtojek requested a review from jsoriano October 21, 2021 16:56
@mtojek mtojek marked this pull request as draft October 21, 2021 16:56
@mtojek
Copy link
Contributor Author

mtojek commented Oct 21, 2021

The package registry tried to load the .zip archive, but it failed:

�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 zookeeper           	     0.4.0	/packages/snapshot/zookeeper/0.4.0
�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 zookeeper           	     1.0.0	/packages/snapshot/zookeeper/1.0.0
�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 zscaler             	     0.3.0	/packages/snapshot/zscaler/0.3.0
�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 zscaler             	     0.3.1	/packages/snapshot/zscaler/0.3.1
�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 zscaler             	     0.3.2	/packages/snapshot/zscaler/0.3.2
�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 zscaler             	     0.3.3	/packages/snapshot/zscaler/0.3.3
�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 zscaler             	     0.4.1	/packages/snapshot/zscaler/0.4.1
�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 zscaler             	     0.4.2	/packages/snapshot/zscaler/0.4.2
�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 zscaler             	     0.4.3	/packages/snapshot/zscaler/0.4.3
�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 Packages in /packages/development:
�[36mpackage-registry_1           |�[0m 2021/10/21 16:54:51 reading packages from filesystem failed: loading package failed (path: /packages/development/apache-0.0.1.zip): failed to determine root directory in package (path: /packages/development/apache-0.0.1.zip)

@jsoriano should I start the EPR differently?

@jsoriano
Copy link
Member

@jsoriano should I start the EPR differently?

The problem seems to be in the format of the package. Implementation in package-registry expects to have the files under the <package>-<version> directory, but this implementation is archiving the files directly in the root directory:

This is an example package in the package registry repo:

$ unzip -l testdata/local-storage/example-1.0.1.zip 
Archive:  testdata/local-storage/example-1.0.1.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2021-07-29 19:26   example-1.0.1/
      516  2021-07-29 19:26   example-1.0.1/manifest.yml
...

This is a package built with this implementation:

$ unzip -l build/integrations/apache-0.0.1.zip
Archive:  build/integrations/apache-0.0.1.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      234  2021-10-25 11:27   changelog.yml
        0  2021-10-25 11:27   data_stream/
        0  2021-10-25 11:27   data_stream/access/
        0  2021-10-25 11:27   data_stream/access/agent/
...

I think I did this because I don't like archives that you decompress and they spread all over the current directory 🙂 But we are probably in time to reconsider this format if needed.

(Btw, side thoughts now, having the package assets inside a directory might allow to embed in the zip other validation or control data, like a signature 🙂)

@mtojek
Copy link
Contributor Author

mtojek commented Oct 25, 2021

I think we need to be consistent with current .zip files, for example: https://epr.elastic.co/epr/aws/aws-1.1.0.zip , so I will adjust the logic here :)

(Btw, side thoughts now, having the package assets inside a directory might allow to embed in the zip other validation or control data, like a signature 🙂)

So with this approach we agree on the content addressed signatures. WDYT?

ImplicitTopLevelFolder: false,
}

// Create a temporary work directory to properly name the root directory in the archive, e.g. aws-1.0.1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the temporary folder with proper name to create the .zip package with root <packageName>-<version>. It's a workaround for mholt/archiver, which doesn't support it.

If you think that copy to temp is an overkill, I will have to implement our own simple zip archiver.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, we can revisit it later if problems are found.

@jsoriano
Copy link
Member

I think we need to be consistent with current .zip files, for example: https://epr.elastic.co/epr/aws/aws-1.1.0.zip , so I will adjust the logic here :)

Ah yes, this is a stronger point 🙂

(Btw, side thoughts now, having the package assets inside a directory might allow to embed in the zip other validation or control data, like a signature slightly_smiling_face)

So with this approach we agree on the content addressed signatures. WDYT?

This would be some kind of content addressed signatures, yes. The good point is that everything would be contained inside the package, we wouldn't need an extra file for the signature. Do you have any preference?

@mtojek
Copy link
Contributor Author

mtojek commented Oct 25, 2021

To be honest I prefer the extra file as it's more intuitive :) Take the .zip file, sign it and have a signature. Frankly speaking we need to decide about this now, as it impacts both PRs: this and EPR.

Comment on lines 33 to 35
tempDir := filepath.Join(os.TempDir(), folderNameFromFileName(destinationFile))
os.MkdirAll(tempDir, 0755)
defer os.RemoveAll(tempDir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using os.MkdirTemp() to be sure that different executions don't affect each other.

Suggested change
tempDir := filepath.Join(os.TempDir(), folderNameFromFileName(destinationFile))
os.MkdirAll(tempDir, 0755)
defer os.RemoveAll(tempDir)
tmpBaseDir, err := os.MkdirTemp("", "elastic-package-")
if err != nil { ... }
defer os.RemoveAll(tmpBaseDir)
tempDir := filepath.Join(tmpBaseDir, folderNameFromFileName(destinationFile))
os.MkdirAll(tempDir, 0755)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try it, but have to preserve the last element (for example: aws-1.0.1).

ImplicitTopLevelFolder: false,
}

// Create a temporary work directory to properly name the root directory in the archive, e.g. aws-1.0.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, we can revisit it later if problems are found.

@jsoriano
Copy link
Member

To be honest I prefer the extra file as it's more intuitive :) Take the .zip file, sign it and have a signature. Frankly speaking we need to decide about this now, as it impacts both PRs: this and EPR.

Ok, let's go with the extra file.

@mtojek mtojek marked this pull request as ready for review October 25, 2021 13:19
}
workDir := filepath.Join(tempDir, folderNameFromFileName(destinationFile))
os.MkdirAll(workDir, 0755)
defer os.RemoveAll(tempDir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defer should be immediately after the if err.... If at some moment we handle the error returned by MkdirAll and return there we may forget of removing the temp dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants