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

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

Related

How to get Lando to run it's own scripts

I'm new to Lando, and am surprised at the way it works. I'm following the example at https://docs.lando.dev/wordpress/getting-started.html, and got a WP site up and running.
But I've been reading docs and trying a few things, and can't find a way to avoid having to manually run the lando init function.
I would have thought that having a lando.yml file saying the recipe is wordpress would be enough to get you up and running - my idea being that I could take that same YAML file, modify a few variables like the app URL, and run "lando start" or something to have lando recreate the entire site.
Is there a way to do this?
Andy
You can in fact do exactly this, you don't need to run lando init on a project unless you want to use the included wizard to fill out the .lando.yml file. You can simply do the following to run a WordPress site:
name: awesome-wp-project
recipe: wordpress
place that in the .lando.yml in the root of your project and then run lando start. You'll have a new instance of Lando with the default configuration for the WordPress recipe running. The important thing to note is that each project needs to have a unique name and should run from a different folder (not nested inside eachother).
You can then include the same customizations in multiple projects (like adding a node container to compile theme assets, or using a specific version of PHP, config file, or folder structure). Just make sure to name each application uniquely.

Cannot setup CodeCommit in EB CLI

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.

Alter where my Jenkins Project build execute shell CWD to a sub-folder of the GIT repository

We have a Jenkins Build server running on Ubuntu 14.04 x64 which is processing three other projects just dandy. We are integrating a fourth Node.js project but due to fact the outside contractor developing it put all the project files inside a folder of the repository. So to clarify, the root of the repository is a single folder; in which the actual project root is located.
Jenkins checks the repository out but when it runs the NPM commands for install and build fails as its looking for the package.json in the repository root versus the subfolder where all the necessary files are located.
There is lots of information out there on use case which have some similarities as mine, but nothing which provided a solution which worked for me.
I've tried using the full path when executing the shells commands, altering the projects workspace to the subfolder, even researched a way to checkout the specific folder using Git which appears to not be a trivial thing.
I cannot believe there isn't a way to execute a Jenkins build into the checkout repositories as if a specific subfolder was the root (CWD) for all the scripts being executed in the shell instance.
Any help would be greatly appreciated!!!
As hinted in the comment, the solution is to cd into the subfolder before the calls to npm.

How to get write permission to a /var/lib folder for app installed as a distiubutable package

I'm creating a mono app and I've build up a *.deb installer.
In windows I write quite a bit of configuration information into the program data directory. The linux corollary seems to be /var/lib/[appname]. I've figured out how to create the directories as part of the install package, but when the app goes to run I get an excpetion because the app doesn't have write permission.
How do I get my app to have write permission to the /var/lib/[appname] folder? Is that the correct place to put things like a local db for an app?
It seems the only way to do this is via the postinst script file.
You can use that hook to execute a script to chmod the directories to anything you want. You can find the complete documentation for the postinst file here: https://www.debian.org/doc/manuals/maint-guide/dother.en.html#maintscripts

Execute command after deploy AWS Beanstalk

I have problem with execute command after deploy, i have some node.js project and script, this script use some bin from node_modules, if i write my command for script in .ebextensions/.config he execute before npm install and return error ("node_modules/.bin/some": No such file or directory). How i can execute command after deploy. Thanks.
I found the following solution
I add to beanstalk config next command:
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/some_job.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
cd /var/app/current
export PATH=$PATH:$(ls -td /opt/elasticbeanstalk/node-install/node-* | head -1)/bin
npm run some_script
This commands create(if not exist) folder for post-hooks scripts and adds bash script. Scripts in this folders execute only after npm install, this very important for my problem.
Thanks to this guy http://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts/
create a file called .ebextensions/post_actions.config:
container_commands:
<name of container_command>:
command: "<command to run>"
this will be executed after the code was extracted, but before it was launched.
A better approach would be to go with the aws platform hooks. Where you can define the postdeploy hooks AWS Patform Hooks
In that inside the project root directory you can add .platform/hooks/postdeploy/
Insdie this path you can create xxx-postdeploy-script.sh. Files here run after the Elastic Beanstalk platform engine deploys the application and proxy server.This is the last deployment workflow step
If you read the AWS ebextensions documentation they mention the execution, specifically where they mention that all commands are executed before the application version is deployed.
"You can use the container_commands key to execute commands for your
container. The commands in container_commands are processed in
alphabetical order by name. They run after the application and web
server have been set up and the application version file has been
extracted, but before the application version is deployed."
If you deploy it for a second time it should work; this is because your application is already unpacked. This however is not a working solution because every new instance that is spawned will error.

Resources