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

chore: add package link and unlink scripts #6238

Merged
merged 3 commits into from
May 18, 2020

Conversation

aldeed
Copy link
Contributor

@aldeed aldeed commented Apr 29, 2020

Impact: minor
Type: chore

Issue

It's difficult to properly link a work-in-progress plugin (or other npm package) into the API running in a Docker container.

Solution

Adds two new scripts in bin:

Run docker-compose up -d before running any of these commands, and wait until the API has fully started.

  • Enter bin/package-link <package-name> to link locally cloned package repo into the container and npm link it. This assumes that the package lives in ../api-plugins, which will be true if it's a plugin package and you used the make clone-api-plugins command to clone it.
  • Alternatively enter bin/package-link <package-name> <path-to-package-repo> for any package that is not located in ../api-plugins
  • When you're done testing, run bin/package-unlink <package-name>

Some additional points

  • It should work to link multiple plugins at once (one at a time)
  • If you do not unlink before you stop the api service, you will likely get into a loop where the API won't ever start. If this happens, delete the node_modules volume with something like docker volume rm reaction_api_node_modules, and then docker-compose up -d should work.
  • When you make changes to the package repo code, run the same bin/package-link command again. You do NOT have to (and must not) manually restart the api container. The Reaction API will magically restart after the linking finishes.

Example workflow

I cloned reaction-development-platform and ran make. API is now running the latest production.

Now I want to make a change in the api-plugin-shops plugin.

First I can clone all plugins by running this in the reaction-development-platform directory:

make clone-api-plugins

Now I need to switch the API to run in development mode:

make dev-reaction

Now let's move into the API directory:

cd reaction

Then I'll view the logs to make sure the API fully starts:

docker-compose logs -f api

When I see that it's running, I'll CTRL+C to stop.

Now I can open <reaction-development-platform directory>/api-plugins/api-plugin-shops in my editor and make some changes.

When I'm ready to link in those changes to test them, I run this in the API directory:

bin/package-link api-plugin-shops

The API will restart when it's done and should reflect the local code changes.

I then make more changes and again run:

bin/package-link api-plugin-shops

When everything is working properly I run:

bin/package-unlink api-plugin-shops

This reverts the link. Then I can docker-compose down if I want to, or link in other packages.

Breaking changes

None

Testing

Try it out!

@aldeed aldeed requested review from kieckhafer and mpaktiti April 29, 2020 20:59
Copy link
Member

@kieckhafer kieckhafer left a comment

Choose a reason for hiding this comment

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

Works as described.

This is a great way to improve linking and testing packages, nice work!

@imbhupendra41
Copy link

@aldeed I have followed the same steps but I am getting following errors
bash: bin/package-link: No such file or directory
I am unable to find any package-link file in bin folder. I have cloned the truck branch from reaction-development.

Is there something I am missing?

@kieckhafer
Copy link
Member

@imbhupendra41 we had a bug report and have created a new bug fix PR. Please try again using the branch from this PR: #6251

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