I’m setting up CI/CD with a .gitlab-ci.yml file & running into some issues with deployment.
My goal is this:
- just run my mocha tests
- ssh to server
- stop running the server
- pull changes
- restart the server
- I’m running a NodeJS server on an AWS EC2 instance.
- The repository I am implementing CI/CD in is private
- I didn’t set up anything special for the runner, so I assume my pipeline just runs on the Gitlab shared runners.
Test stage goes well, connecting to the server is fine, but it fails on trying to pull changes because it asks for a username/password.
I thought I set up my deployment key correctly, so I am confused why this is happening. The public machine key I used for my deployment key I got by using the command,
ssh-keygen -y -f /path_to_key_pair/my-key-pair.pem, which I got from here.
From my understanding, I should be able to pull from the repo w/o a username/password when I ssh into the server (or CI/CD ssh’s into it) now that I have that deployment key set up. But it still asks for a username/password. I’ve tried finding the answer on my own to no avail & am lost now.
.gitlab-ci.yml looks like this:
# Reference for building the CI/CD YAML file: https://docs.gitlab.com/ee/ci/yaml/README.html stages: - test - deploy # Run Tests test_dev: stage: test image: node only: - development before_script: - echo -n "Starting Mocha Tests..." script: - npm install - npm test # Deploy to development server deploy_dev: stage: deploy image: node only: - development before_script: - mkdir -p ~/.ssh - echo -e "$DEV_DEPLOY_SSH_KEY" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh-keyscan $DEV_IP >> ~/.ssh/known_hosts - chmod 644 ~/.ssh/known_hosts script: - bash ./cicd/.gitlab-deploy-dev.sh
This is the
# SSH into server, stop process, pull repo, restart server echo "Deploy project on server $DEV_IP" ssh ec2-user@$DEV_IP 'cd desktop/speed-dating-app-backend/ && pm2 stop all && git pull && pm2 start src/EntryPoint.js'
And finally, this is the error the runner ran into in the deployment stage (before this was just shutting down the server… I didn’t want to put my server’s IP in this post so I left everything before this out)
Super stumped on this issue and would be super grateful for a prompt resolution! Thanks!