Cannot setup CodeCommit in EB CLI - node.js

After terminating my previous environment in EB CLI with eb terminate , which executed successfully, I have been trying to deploy my node app in a different region. When I navigate to my app folder containing and hit eb init, I am prompted with
$ eb init
Cannot setup CodeCommit because there is no Source Control setup, continuing with initialization
What can I do from here?
I double checked in IAM and the user has full codecommit access

It looks like you have not initialized git in your directory. Try running git init in the directory you want to use with CodeCommit via the EB CLI.
If you have done this and it is still not working the environment you are using may not be accessible to git and may need to be installed.

It happened to me.
I turned out that it happens because I already have a .elasticbeanstalk folder in this directory.
Which means there is already an elastic bean application configured.
And it will continue with the existing configurations.
Solution:
Delete the .elasticbeanstalk directory.

Related

Pulling a git repo from a startup script on google cloud compute engine

To show my team how the app that I am building is progressing, I created a small dev server on google cloud compute engine. This server is usually switched off to save cost and only is switched on when we are working together. I am developing and pushing to a git repo when the server is not on. When I start the server, the latest changes should be pulled, the node packages installed and the node server should be started. To do this I have created the following startup script:
#! /bin/bash
cd /to/my/server/folder
git pull
sudo npm install --no-progress
nohup node src/ &
I have created an ssh key and added that as a read only deploy key in my gitlab account on this particular repo. The script is tested on the server and works totally fine. Now the fun part.
When the script is run as a startup script (https://cloud.google.com/compute/docs/startupscript) it doesn't work. The error:
permission denied (public key)
fatal: could not read from repo make sure it exists.
I tried these fixes:
Getting permission denied (public key) on gitlab. The problem being that they can not pull git repos in general. In my case it works fine from command line, it works fine from shell script, but it just doesn't work from startup script.
I also tried a whole bunch of other stuff on the whole spectrum from 'could be it' to 'a wild guess'. Clearly there is something I am missing here. Could anyone help me out?
Finally found the answer here: https://superuser.com/a/868699/852795. Apparently something goes wrong with the SSH keys that are used in a google startup script. The solution is to explicitly tell git what key to use. Like this: GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa" git pull.

Can git be used to handle projects within a repo?

I setup a git server on Debian and created a folder called git in /srv/git/.
Inside the folder, I'd like to divide my git projects by cloud hosted cloud and on-prem hosted on-prem. Inside of these two folders contain the hostname and it's specific files needed for deployment, redeployment, etc.
So a server that does apache on the cloud with a hostname like webapp will have a folder structure like /srv/git/repos/cloud/webapp.
Should the command git init be ran from the cloud folder or webapp folder?
I presume your setting up the bare repo.
As you mentioned in the question, you want to have separate git projects plural here so what I understood is you want to have more than one project under cloud directory.
Method 1:
cloud
|------->webapp
|------->something1
|------->something2
Very straight way is doing /srv/git/repos/cloud/webapp.git here webapp is the git repo.
Setting up the webapp as git repo.
git init --bare /srv/git/repos/cloud/webapp.git
--bare: for the bare repo you can skip this using on exisiting repo.
Though init is not harmful to give on existing repository is safe. It will not overwrite things that are already there
Method 2:
cloud (git repo)
|------->webapp (submodule)
|------->something1 (submodule)
|------->something2 (submodule)
In another option where you can keep cloud as git repo and make webapp as submodule. That is repo inside the git repo.
You can choose what fits to you best.
I suggest to use two different repo, if your have plenty of submodules in one git repo it might be cumbersome at the start to keep track of things.
The answer to your question is that you should run git init from the cloud folder, giving webapp as the first argument, i.e. git init webapp.
That said, you could also create the webapp directory, change into it, and then run git: mkdir webapp; cd webapp; git init; The end result will be exactly the same, but why bother?.

How do I change directory to deployment-archive to run gulp?

I am using aws code deploy to deploy a nodejs server to an ec2 instance.
aws code deploy agent downloads bundle to following path:
/opt/codedeploy-agent/deployment-root/deployment-group-id/deployment-id/deployment-archive/gulpfile.js
which means my gulpfile.js reside at
/opt/codedeploy-agent/deployment-root/deployment-group-id/deployment-id/deployment-archive/gulpfile.js
however any bash command I run will run from
/opt/codedeploy-agent
How do I change directory to dynamically generated
deployment-group-id/deployment-id/deployment-archive
and also install node modules from package.json?
You may use the environment variables as for changing directory
$DEPLOYMENT_GROUP_ID/$DEPLOYMENT_ID/deployment-archive/
You can refer this for how to use them.
You can also change the root directory where code deploy adds the deployment-group-id/deployment-id/deployment-archive by changing it from the agent configuration file: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-agent-configuration.html
By default it's in /opt/codedeploy-agent/deployment-root but you can change that.
Furthermore you can tell CodeDeploy to copy your files over to a different directory in the appspec file by controlling each file's source and destination:
https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-files.html
What I understand is you can not run
BeforeInstall from root of your project, you have to move the code to AfterInstall.
To find the full path of root of after install and then navigate from there check this out:
AWS CodeDeploy AfterInstall script is being run from code-deploy agent dir

How do I deploy to GAE from the Google Cloud Source Repository?

I'm considering moving my php Google App Engine project from Codenvy to the Google Source Repository and edit it there with the Source Editor, but I don't see how to cause it to deploy my project. How do I do that?
Here's what works for me, found through guesswork, trial, error, Billy and only a little docs.
I had set up GC Repositories to have a repository which is a mirror to bitbucket , auto-named default. Note: gcloud for default below can fail to recognise a repository that got that name by Rename. And can mistake a non-existent repository for an empty one.
Recipe 1
UPDATE: Now, after updating the bitbucket source, the deployed app does not show the update, despite "Deployment successful"]4. I don't know why - perhaps due to version number. Workaround: Use Recipe 2.
1 Ensure project's app.yaml file contains application: and version: e.g. this
2 Go to Google Cloud Patform and select the project
3 Click Activate Google Cloud Shell http://i.imgur.com/Axjy17q.png
4 In Google Cloud Shell, enter:
gcloud source repos clone default
appcfg.py update default
rm -rf default
This took ~20s to deploy and ~30s to complete.
Recipe 2
1 Ensure project's app.yaml file does not contain application: or version: (else you'll get an error like this) e.g. this
2 Go to Google Cloud Patform and select the project
3 Click Activate Google Cloud Shell http://i.imgur.com/Axjy17q.png
4 In Google Cloud Shell enter:
gcloud source repos clone default
gcloud --quiet app deploy default/app.yaml
rm -rf default
Warning: This can leave a previous version accessible.
This took ~65s to complete.
Re timing, compare this, taking ~20s . Timings are for a Hello World project.

Best way to (git) push changes to a development server and have it automatically restart a Node app?

Previously and on my local machine, I've been using nodemon which watches for changes made to a Node app and reloads it upon every change. But running the development server on my own machine is no longer feasible, so I've setup git for the app on a designated development server.
In advance, I prefer Sublime Text, so editing files on the development server via the terminal doesn't match my workflow, plus I like having a copy of everything on my local machine by default. I had also checked out rsync, but I like the fine-grained version control that git offers.
So how can I edit files locally, git push them to a development server, and have the Node app automatically reload after every push?
You can write a server side hook. In your .git directory there is a hook directory. Just cd in to .git/hooks. There you can write a script in whatever language you need to write it in. Essentially after you push it will run the script you tell it to. Here is more information on git hooks
https://git-scm.com/book/es/v2/Customizing-Git-Git-Hooks
Quick tutorial to make this work:
On the development server, navigate to /home/dev-user/Node and initialize bare repository at /home/dev-user/Node/example.git using git init --bare example.git.
Clone repository into /home/dev-user/Node/example using git clone example.git.
Add files to /home/dev-user/Node/example as necessary, then git add . and git commit -m "init" and finally git push origin master which will push those files to example.git.
Edit or create /home/dev-user/Node/example.git/hooks/post-receive and add the following line:
GIT_WORK_TREE=/home/dev-user/Node/example/ git checkout -f
This will automatically update the files in /home/dev-user/Node/example/ upon any changes pushed to /home/dev-user/Node/example.git.
If you don't have nodemon installed already, install it with npm install -g nodemon. You may have to use sudo.
Assuming your main Node app is located at /home/dev-user/Node/example/app.js, start the app using nodemon /home/dev-user/Node/example/app.js (or if you're already within /home/dev-user/Node/example, just nodemon app.js of course).
On your local machine, navigate to /home/timbur/Node, and assuming you're able to connect to the server automatically via SSH, clone the bare repository using git clone dev-user#dev.server.ip.address:Node/example.git. You'll now have everything in /home/timbur/Node/example.
Edit files on your local machine and add/commit/push files to the development server as usual, and changes will automatically update the server's example directory, which nodemon will detect and the app will be restarted.
The best way would be to setup a continuous integration server, like Jenkins: https://jenkins-ci.org/
And then there are plugins for basically whatever you want to do, like this one for node.js for instance: https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
But that's probably not the easiest way. You could also setup a post-receive hook on your server, that checks out the code whenever you push any changes, and then let it restart your server. Here's a gist I found (but never tried) https://gist.github.com/tlrobinson/8035884

Resources