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

feat(plugin): Add ability to push multiple docker images #7

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

DanielHabenicht
Copy link
Contributor

This feature allows specifying the plugin multiple times in order to push multiple images to a
docker repository.

#4

This feature allows specifying the plugin multiple times in order to push multiple images to a
docker repository.

iteratec#4
@DanielHabenicht
Copy link
Contributor Author

I don't know why but the tests in the
https://github.com/DanielHabenicht/semantic-release-docker/blob/feat/multiple-images/src/shared-logic.spec.ts
file are not executed.

@cmurczek-it
Copy link
Member

Hi @DanielHabenicht, with this PR you'd basically revert my changes to mock/stub the docker dependency during unit tests. I've added more test as examples for how I'd like to proceed. Please review these and update your PR.

@DanielHabenicht
Copy link
Contributor Author

Ahh, ok. I think I misunderstood. I will include your changes as units tests and add my tests as e2e Tests.

@cmurczek-it
Copy link
Member

cmurczek-it commented May 1, 2019 via email

@DanielHabenicht
Copy link
Contributor Author

Finally, I had some time to refactor the code.
I've used the sinon mocks and stubs in the spec files and made it optional to run the tests that are docker dependent.

I take your point on running the tests a lot faster for development, that's why I refactored it.
But I think it is also important to test the whole plugin (including the dockerode part), that's why I included them as e2e tests that can be run separately (this way we can test if the plugin can interact with a real docker API, thus test if the current version of dockerode does work properly in our use case or even test if the publish step works later on)

Have a look and feel free to comment.
I will refactor the other PR after this gets merged.

Copy link
Member

@cmurczek-it cmurczek-it left a comment

Choose a reason for hiding this comment

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

I do get your motivation for bringing in e2e tests, but this way they provide no benefit over good unit tests. The do however cost time, especially when they are part of every build.
If we added e2e tests they should be truly e2e, meaning actually using semantic-realease with this plugin to build a docker image. However, for now at least I don't see the need for that.

I do like the original idea of the PR though. I'm not sure if the way it's implemented is the best strategy. What's your take on something like
{ plugins: [ prepare: [{ path: "@iteratec/semantic-release-docker", images: [{ additionalTags: [], imageName: "", registryUrl: "", repositoryName: "", }] }] }
To me it feels more natural to configure the plugin once, and have it deal with multiple images, instead of loading multiple instances of the same plugin...

src/verifyConditions/index.ts Outdated Show resolved Hide resolved
expect(dockerStub.checkAuth.firstCall.args[0]).to.deep.equal(expected);
});

it('should default to docker hub if no registry is specified', async function() {
Copy link
Member

Choose a reason for hiding this comment

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

why would you remove this test? I want to make sure we let docker decide which registry to use if none is specified

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it basically is a duplicate of "should use the registry from the config" the test checks if the string put into the config is returned. The main difference is that one string is '' and the other is 'my_private_registry'

src/verifyConditions/index.e2e.ts Outdated Show resolved Hide resolved
src/verifyConditions/index.e2e.ts Outdated Show resolved Hide resolved
src/verifyConditions/index.e2e.ts Outdated Show resolved Hide resolved
"commit": "git-cz",
"test": "mocha -r chai -r chai-as-promised -r ts-node/register src/**/*.spec.ts",
"e2e": "mocha -r chai -r chai-as-promised -r ts-node/register src/**/*.e2e.ts",
Copy link
Member

Choose a reason for hiding this comment

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

please remove this script

inputs:
verbose: false
- task: Npm@1
displayName: Build
inputs:
command: custom
customCommand: run build
- task: Npm@1
Copy link
Member

Choose a reason for hiding this comment

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

remove this task

README.md Outdated Show resolved Hide resolved
.gitignore Show resolved Hide resolved
@@ -0,0 +1,2 @@
FROM scratch
ARG TEST
Copy link
Member

Choose a reason for hiding this comment

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

Don't burden yourself with creating actual images while developing this plugin. There is no benefit over (correctly) mocking/stubbing dockerode.

@DanielHabenicht
Copy link
Contributor Author

I do get your motivation for bringing in e2e tests, but this way they provide no benefit over good unit tests. They do however cost time, especially when they are part of every build.

There are numerous reasons and benefits for the e2e tests:

  1. The e2e tests actually check on the machine if the plugin has done what it said it did.
    With the Unit-Tests only the tools 'said' output is tested. For Example the Bug I fixed before was not detected by your unit tests, because it did only check the tool's output, not the actual behaviour of the tool. That's also the reason why I wrote them in the first place.
  2. The e2e tests are independent of the tools you use (ideally).
    You might want to replace dockerode in the future because it gets deprecated or update to the next version. This does change the API of the internally used tools and you have to rewrite your unit tests. While rewriting who checks that the tests and changes you do are correct? (The e2e tests, because they only check the outcome)

If you think the build time is too long I can make them run in parallel. But I think that waiting 22 seconds are worth the amount of time needed for others to test, verify, file a bug and resolve the issue coming from not testing it.

If we added e2e tests they should be truly e2e, meaning actually using semantic-release with this plugin to build a docker image. However, for now, at least I don't see the need for that.

I think of these as integration tests, that's also a good idea but I do align with your view.

I do like the original idea of the PR though. I'm not sure if the way it's implemented is the best strategy. What's your take on something like
{ plugins: [ prepare: [{ path: "@iteratec/semantic-release-docker", images: [{ additionalTags: [], imageName: "", registryUrl: "", repositoryName: "", }] }] }
To me it feels more natural to configure the plugin once, and have it deal with multiple images, instead of loading multiple instances of the same plugin...

I think the way it is implemented is the way to go, with the option to specify multiple images you are bringing in another way of using the plugin, while not fixing the way it already can be used.
For reference the @semantic-release/exec command does it the same way. But it might be a good addition in the future to provide both ways.

@DanielHabenicht
Copy link
Contributor Author

@cmurczek any updates?

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.

2 participants