I use Yarn for a monorepo project. We also use Lerna to help automate some of the commands across the various workspaces. I'm trying to create a Yarn script command that accepts a variable for the workspace name. I have a working command:
"deploy:dryrun": "dotenv -e .env.local yarn workspace project1 deploy:dryrun"
This can be invoked with yarn deploy:dryrun.
What I would like is to have the workspace name (project1) be a variable provided on the command line. I would like to be able to invoke it as yarn deploy:dryrun project1 and have the workspace name substituted into the script command like
"deploy:dryrun": "dotenv -e .env.local yarn workspace $workspacename deploy:dryrun"
Is there a way to achieve this without turning the script into an actual bash script file?
Related
I'm wondering: if your terminal's current working directory is inside a yarn workspace, is there a way to run a yarn script that's defined at the project root without changing the current directory to be outside of a workspace?
For instance, you can run a command for a particular workspace by running yarn workspace workspace-name script-name but is it possible to use that yarn workspace command to target not a subpackage, but the root package itself?
I couldn't find a way to do it with yarn workspace, but you can do it by specifying the current working directory (cwd) when running the root command. Assuming you're running your command from ~/packages/subpackage, you'll need to go back two times with ../..:
yarn --cwd="../.." my-root-script
Scripts that contain a : in their name can be run from anywhere!
For example, your root script called "root:something" can be called from within any workspace by running yarn root:something.
Note that this even works if the : script is not a root script, but a workspace script. See yarn docs.
I'm pretty new to the bash/shell script world, I'm trying to do the below and it could be pretty simple but I wasn't able to figure out the command, would be great if someone could help me out here and also point me to some documentation wrt to shell script topics. Thank you in advance.
My build.sh and Dockerfile resides under a folder called .settings and this folder lives directly under the app root. Now inside my build.sh and Dockerfile when I refer something like $(pwd) or COPY . /apps/ it might not work since my build.sh and Dockerfile does not live directly under the app root.
What command I can use in this scenario inside the files that I referenced above. Hope I made it clear. Once again this could be very simple since I'm a newbie in this arena I find it a little difficult.
inside build.sh, reference to $(pwd)
docker run \
-u root \
--rm \
-v $(pwd):/app \ ----> this $(pwd) references the application root, but if I
move this build.sh inside a folder called .settings then the $(pwd) context
would change and I still want to refer it to the root.
<MYIMAGE NAME FROM LOCAL REPO>
The last arg to docker build, often something like docker build . is the build context in docker. This directory is sent to the server where the build runs and all COPY and ADD commands are performed using this context. These commands do not run on the client, and docker is a client/server application, so anything not in that context simply doesn't exist for the purpose of building an image.
So in the above example, docker build . the current directory is the build context and if that's run while you're inside of the .settings directory, only those files are part of the build context. Therefore your build.sh script needs to pass a different directory, and also reference where the Dockerfile is inside of that build context. That would look like:
docker build -f .settings/Dockerfile ..
When you do this, all of the COPY and ADD commands will now be relevant to parent directory, so you may need to adjust your Dockerfile to compensate.
For your $(pwd) reference, you can either cd .. before running your docker run command or update the command to look like:
docker run \
-u root \
--rm \
-v $(pwd)/..:/app \
<your image>
How to change the gitlab multi runner build path.
in my server it have /home/gitlab-runner/builds.
I want to change this path to my secondary HDD that is mounted in the same server.
You can change your runners build path by adjusting the config.toml. In the [[runners]] section add or change the builds_dir directory.
For further reference on runner configuration you can check out the documentation here.
On macOS I was able to find one more way (can be helpful if you have many runners, I guess):
Edit ~/Library/LaunchAgents/gitlab-runner.plist
and modify the path under --working-directory to whatever you want
e.g. from Terminal vim /Users/Me/Library/LaunchAgents/gitlab-runner.plist
or using your favorite Text Editor
Restart it for the changes to take effect
gitlab-runner restart
One may prefer to setup build directories globally.
In the file /etc/systemd/system/gitlab-ci-multi-runner.service there is a line
Environment="DAEMON_ARGS=run --working-directory /var/lib/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner"
So, you may change --working-directory /var/lib/gitlab-runner to whatever path you want, and wouldn't specify the --builds-dir on every new registered runner
Environment="DAEMON_ARGS=run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner"
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.
I use bower and grunt in my workflow, and I wanted to install bower at the same time as grunt and pull down all my bower dependencies. So I created a package.json file that has a script attached on postinstall, which I also pass my github project repo, and dropped my post_install.sh into /root/bin.
{ // snippet of package.json
...
"scripts": {
"postinstall": "bin\\post_install.sh https://github.com/blah/blah.git
},
...
}
so running npm install would run post_install.sh, which runs
#!/bin/bash
node_modules/.bin/bower install
grunt setup
git init
git add .
git commit -m "Initial commit of project artifacts"
git remote add origin $1
git push -u origin master
This only works if I set git bash to open in my project directory. So I've been trying to figure out how to switch directories from where git bash opens at /htdocs to /htdocs/myproject using an alias. I read up on how to set this I thought, but I can't figure out how to invoke this file... incidentally also tried putting it in another .sh file to see if that worked.
#!.bashrc
alias projDir='cd /onloadsolutions'
What am I doing wrong that the alias above in /bin/.bashrc won't execute in my post_install.sh when dropped above "grunt setup"?
Dropping this into post_install.sh
echo "script running has basename `basename $0`, dirname `dirname $0`"
echo "present working directory is `pwd`"
gives a basename of D:/htdocs/onloadsolutions/bin/post_install.sh, but my present working directory is /d/htdocs, which when the bower and git commands run they do it in the wrong directory.
Not 100% sure what you mean but I am guessing when you open bash you want to
be able to type a command to take you to your project
then type npm install and have it pull down all your dependencies
Try editing your .bashrc file (this should be in your home directory, not in the /bin folder) to access this you can use something like
nano ~/.bashrc
(~/ is a shortcut to your home directory)
and look in it for any existing alias commands or add yours down the bottom.
then after opening another bash session (.bashrc only runs when you first start terminal) you should be able to see your current aliases by typing "alias"
you can launch the alias you mentioned above by typeing "projDir" into the console. It would be much better to add the full path in your alias i.e.
alias projDir='cd /var/www/onloadsolutions'
then you can call it from anywhere. Otherwise you might end up in a different folder than you expect.
UPDATE
See comments below.
Put cd $2 in the second to top line of the post_install.sh file and add a second parameter to the package.json file that calls it.