What I want to do:
I want to start a backend node.js server in step 1 of my pipeline (port 5000); and from the second step of the pipeline, I want to call one of its public endpoint.
The scenario:
I have two repos, one for frontend, and the other for backend. The yml file is present in the frontend repo and I have made all configurations in bitbucket to provide my frontend pipeline the access to clone my backend repo, so all good on that. The server also starts fine on the first step:
My YML:
The issue
In the second step, when I curl GET the public endpoint e.g: http://localhost:5000/search, I get the error:
curl: (7) Failed to connect to localhost port 5000: Connection refused
Screenshot:
I think this is because when we get to step 2 the build in step 1 is already torn down so the server is not available?
How can I access the endpoint in second step so that the curl request passes?
Thanks for any help, much appreciated.
Hi @Shreejan Regmi and welcome to the community!
Pipelines builds run in Docker containers. For each step of your build, a Docker container starts, the repo is cloned in that container, and then the commands from the step's script are executed. When the commands finish successfully or if a certain command fails, the Docker container gets destroyed.
What you are asking is not possible because the Docker container from the first step no longer exists when the second step runs. You will need to start the server in the same step where you want to use it.
Please also keep in mind that if you clone a different repo in the first step, that clone will not be available in the second step. You can make use of artifacts for any files that are generated or downloaded during a step if you want them to become available in subsequent steps:
If you have any other questions, please feel free to reach out.
Kind regards,
Theodora
Hi Theodora, thanks for your help, starting both in the same step did work :)
I am wondering though... if the backend server and frontend app needs two different versions of node to install and run, how can I manage that in the same step? Do I use a version manager such as nvm or volta, or do you suggest any other proper way?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shreejan,
Thank you for the update, it's good to hear that this worked!
I am wondering though... if the backend server and frontend app needs two different versions of node to install and run, how can I manage that in the same step? Do I use a version manager such as nvm or volta, or do you suggest any other proper way?
If the tests you do for the backend are independent from the tests for the frontend, you could use a version manager. Another option would be to test the backend in one step and the frontend in a different step, and use a different Docker image as a build container for each step in your bitbucket-pipelines.yml file (with each image using a different node version).
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Shreejan Regmi
Like you mentioned, the process might be killed at this point, and further-more, the second process might not be running on the same host/container.
The safer approach would to either run the two servers in the same step or run the servers on a dedicated runner which can host the servers.
Note: the second approach is far less recommended because it would make life very complicated when trying to run your builds in parallel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Erez! It worked when I started both of the servers in the same step. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.