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

Adding support for S3-compatible Storage for Repository part #332

Merged
merged 32 commits into from
Jan 7, 2021

Conversation

pedro-stanaka
Copy link
Contributor

This PR is related to issue #228. I tried to keep it simple and contained, but there were too many places where it the local filesystem was taken as a guarantee. So there was a lot of refactoring involved.

I tried to follow the conventions you used in the code, but if I failed to respect some convention please let me know and I will fix it.

Apart from the strong test suite of yours, I also tested the application inside a private hosted server with the ansible setup and it worked well for both the local and for the new S3 storage. The only problem that I could find is when migrating from local to S3, but I think in a later PR someone (or me) can provide a proper command to migrate files from local to S3 storage.

Once again, if you see any problems on the PR, let me know and I will fix in a manageable time, I spend almost a month working on this, so I would like to see it merged 😸 .

Thanks for the awesome tool you guys are providing for the community.

@codecov
Copy link

codecov bot commented Dec 4, 2020

Codecov Report

Merging #332 (d0cb4a3) into master (3373813) will decrease coverage by 0.17%.
The diff coverage is 94.65%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #332      +/-   ##
============================================
- Coverage     99.53%   99.35%   -0.18%     
- Complexity     1822     1855      +33     
============================================
  Files           295      297       +2     
  Lines          5754     5858     +104     
============================================
+ Hits           5727     5820      +93     
- Misses           27       38      +11     
Impacted Files Coverage Δ Complexity Δ
src/Service/ReadmeExtractor.php 96.00% <80.00%> (-4.00%) 7.00 <0.00> (+1.00) ⬇️
src/Service/Organization/PackageManager.php 92.98% <86.20%> (-7.02%) 19.00 <5.00> (+2.00) ⬇️
src/Service/Dist/Storage/StorageImpl.php 89.09% <89.09%> (ø) 17.00 <17.00> (?)
src/Controller/RepoController.php 98.57% <91.66%> (-1.43%) 16.00 <2.00> (+1.00) ⬇️
src/Command/ClearMetadataCacheCommand.php 94.73% <92.85%> (-5.27%) 5.00 <1.00> (ø)
src/Controller/ProxyController.php 100.00% <100.00%> (ø) 13.00 <0.00> (ø)
src/Service/AmazonWebServices/S3AdapterFactory.php 100.00% <100.00%> (ø) 8.00 <8.00> (?)
src/Service/Dist/FilePatternFilterIterator.php 100.00% <100.00%> (ø) 8.00 <8.00> (?)
src/Service/Proxy.php 96.83% <100.00%> (+0.26%) 60.00 <0.00> (+3.00)
src/Service/Proxy/DistFile.php 100.00% <100.00%> (ø) 3.00 <3.00> (?)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3373813...d0cb4a3. Read the comment docs.

Copy link
Contributor Author

@pedro-stanaka pedro-stanaka left a comment

Choose a reason for hiding this comment

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

Last few comments from my side.

Copy link
Member

@akondas akondas left a comment

Choose a reason for hiding this comment

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

Ffirst of all, many thanks for the effort 👏 🍻 .
We are happy to merge these changes.

But first, please make these minor corrections. Then we will test these changes on our side.

If everything works, we will merge next week 🎉

@akondas
Copy link
Member

akondas commented Dec 4, 2020

I must admit that you create very elegant commit descriptions. I appreciate 👏

@akondas
Copy link
Member

akondas commented Dec 7, 2020

After initial testing I found two small bugs, I push a fix.
However, the scanning of packages still does not work. Look like Storage::filename return wrong path, before this PR it looks like this:

public function filename(Dist $dist): string
    {
        return sprintf(
            '%s/%s/dist/%s/%s_%s.%s',
            $this->distsDir,
            $dist->repo(),
            $dist->package(),
            $dist->version(),
            $dist->ref(),
            $dist->format()
        );
    }

As you can see, full relative path from content root is returned.

@pedro-stanaka
Copy link
Contributor Author

After initial testing I found two small bugs, I push a fix.
However, the scanning of packages still does not work. Look like Storage::filename return wrong path, before this PR it looks like this:

public function filename(Dist $dist): string
    {
        return sprintf(
            '%s/%s/dist/%s/%s_%s.%s',
            $this->distsDir,
            $dist->repo(),
            $dist->package(),
            $dist->version(),
            $dist->ref(),
            $dist->format()
        );
    }

As you can see, full relative path from content root is returned.

Now we are passing the $this->distDir as base for the filesystem so we shouldn't need this part anymore. I will take a look this afternoon and add more tests if needed. Same for the Filesystem::put() problem.

@pedro-stanaka
Copy link
Contributor Author

Regarding: #332 (comment)

How did you manage to reproduce the bug? Can you help me by pointing a class or giving me the exception stack trace so I can try to write a test case?

@akondas
Copy link
Member

akondas commented Dec 9, 2020

Regarding: #332 (comment)

How did you manage to reproduce the bug? Can you help me by pointing a class or giving me the exception stack trace so I can try to write a test case?

I have a package added earlier and I run security scanner for it. I think there will be the same problem for the newly added package. Security scanner probably wasn't tested externally, only as a separate service and that's why this problem.

@pedro-stanaka pedro-stanaka force-pushed the feature/s3-storage branch 4 times, most recently from 7532f0e to c551ee3 Compare December 18, 2020 07:16
@pedro-stanaka
Copy link
Contributor Author

pedro-stanaka commented Dec 18, 2020

Hi @akondas sorry for the immense delay in my response. I tried to test locally and now I am getting one error while doing the security check, is this by any chance the same error as you are getting?

image

If so, can you tell me why it does not get logged neither reported to sentry? And maybe how can I see trace and debug it?

@pedro-stanaka
Copy link
Contributor Author

AH! I think I got it. I will fix it ASAP. 😃 I found one place where I didnt change how we are reading the Zip files. But still, I was hoping this exception was going to be reported to Sentry.

@akondas
Copy link
Member

akondas commented Dec 18, 2020

AH! I think I got it. I will fix it ASAP. I found one place where I didnt change how we are reading the Zip files. But still, I was hoping this exception was going to be reported to Sentry.

Yes, in prod env it will be reported to sentry 😉

@pedro-stanaka
Copy link
Contributor Author

pedro-stanaka commented Dec 18, 2020

Okay, I managed to solve this SecurityScanner problem. I will use the application a bit more locally to be sure I dont find any other problems, but I guess it is fine.

@pedro-stanaka
Copy link
Contributor Author

pedro-stanaka commented Dec 18, 2020

@akondas now I only have a problem with this conflict, if you could help me resolve it would be nice. I tried to resolve locally by doing a rebase, but had to run composer update --lock -W which upgraded many dependencies and ended up totally breaking the tests (and I suppose the application itself).

Detail: I am using composer v2, from what I see in your docker image you are using it as well, but I dunno if that should be a problem.

@akondas
Copy link
Member

akondas commented Dec 18, 2020

Yes, I can help you with this. I will correct it immediately when testing this branch

{
$basePath = $basePath ?? dirname(__DIR__, 1).DIRECTORY_SEPARATOR.'Resources';
Copy link
Contributor

@karniv00l karniv00l Dec 21, 2020

Choose a reason for hiding this comment

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

what's the reason for level 1 in dirname and use of DIRECTORY_SEPARATOR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was just to avoid the relative paths with ../ on it. I had problems when using those in conjunction with the composer repositories, specially the paths. Regarding the DIRECTORY_SEPARATOR, I try to use it whenever I can for portability. If you guys prefer just / I can replace it as well.

Now running the suite again with the old code I see that I don't get any errors 🤷‍♂️ . So I can easily revert it, just say the word. 😃

Copy link
Contributor

Choose a reason for hiding this comment

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

It's ok, it's just that 1 is a default level for the dirname function and we don't really support windows in other places 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OMG, I didn't even see that (default value). I will go back to the old code to avoid confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There you go! Thanks for catching such fine grained detail 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Cheers, good job overall 🍻

@akondas
Copy link
Member

akondas commented Dec 23, 2020

We tested everything (for the local filesystem) and it looks like it works, we still have s3 configuration to check. Due to the fact that holidays are coming, we will probably merge this branch in the first week of January. Forgive me for taking so long, but I would like to supervise this myself. Thanks for the work and Merry Christmas.

@pedro-stanaka
Copy link
Contributor Author

pedro-stanaka commented Dec 26, 2020 via email

@akondas
Copy link
Member

akondas commented Jan 4, 2021

Hello @pedro-stanaka, I hope all is well in the new year. Tests showed that managing the private packages works flawlessly, but we had a small problem with the proxy on s3. I am attaching an error dump:

Screenshot from 2021-01-04 11-54-54

@pedro-stanaka
Copy link
Contributor Author

pedro-stanaka commented Jan 4, 2021

Okay, I will fix this ASAP. I already know the problem, the file is on remote location and fstat requires the file to be on local file system.

@akondas would it be okay if we pass the file size inside the constructor for src/Service/Proxy/Metadata.php?

@akondas
Copy link
Member

akondas commented Jan 4, 2021

I guess that should be ok 👍. Too bad I thought fstat worked for stream data as well.

Pedro Tanaka added 5 commits January 5, 2021 09:47
We were using fstat, but sadly it does not work for remote streams
I dropped the usage of the function in favor of Flysystem methods and a
custom function using fstat + stream_get_meta_data
@pedro-stanaka
Copy link
Contributor Author

@akondas I think it should be fine now. I introduced a class for the Dist File for the proxy, because there we really only had the stream, so I added class to have information about the file size we are proxying. Hope solution is fine enough.

@@ -2,7 +2,7 @@
/**
* CRM PROJECT
* THIS FILE IS A PART OF CRM PROJECT
* CRM PROJECT IS PROPERTY OF Legal One GmbH
* CRM PROJECT IS PROPERTY OF Legal One GmbH.
*
* @copyright Copyright (c) 2020 Legal One GmbH (http://www.legal.one)
*/
Copy link
Member

Choose a reason for hiding this comment

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

✂️ 😉

@akondas
Copy link
Member

akondas commented Jan 6, 2021

Everything seems to be working properly now. Thanks for a great job. Please delete this one comment and we are ready to merge it 🎉

Copy link
Member

@akondas akondas left a comment

Choose a reason for hiding this comment

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

One more thing to fix: repman:metadata:clear-cache cli command. This is last place where local files are used 😉.

@pedro-stanaka
Copy link
Contributor Author

I will work on solution for the cli command. The symfony filesystem component is a really nice helper, but wont work with the new Flysystem adapter. I will have devise a "by-hand" solution, by iterating the contents of the distDir. Luckily this is cronjob, so no problem taking a bit more of time.

@pedro-stanaka
Copy link
Contributor Author

@akondas I managed to find a solution for the file finding. I took " inspiration" from symfony filesystem lib. Please take a look and see if this is adequate. 👍

@akondas akondas requested a review from karniv00l January 7, 2021 07:22
Copy link
Member

@akondas akondas left a comment

Choose a reason for hiding this comment

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

LGTM 👍 👏

@akondas
Copy link
Member

akondas commented Jan 7, 2021

@pedro-stanaka Thank you for all your hard work on this functionality 🙏 👏 🎖️

@akondas akondas merged commit b863acd into repman-io:master Jan 7, 2021
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