I'm setting up a CDK project that have some lambdas in Javascript and Python, I'm trying to figure out what's the best way to build these functions as I would normally pass the build command like this:
// Install dependencies, build and run cdk synth
commands: [
'npm ci',
'npm run build',
'npx cdk synth'
]
or
buildCommand: 'npm run build'
The only thing I can think of is to create a build.sh file inside each lambda, for the ones in JS I'd add npm run build and for the ones in Python pip install -r requirements.txt but I don't really know if this is a good practice and if there's a better way to accomplish this.
What you need is a Bundling docker container. You can
either configure the bundling yourself using the bundling option for Code.fromAsset()
or use the PythonFunction and NodejsFunction constructs which provide standard bundling for Python and Node.js, respectively.
This AWS Blog post gives some more examples for bundling.
Related
I'm experimenting with docker. I have a simple dockerfile, which includes java and node.
https://github.com/Quafadas/scala-mill
https://github.com/Quafadas/scala-mill/blob/master/Dockerfile
It's published to dockerhub. Now, I'd like to build an application downstream
FROM quafadas/scala-mill:latest
RUN java -version
#This doesn't work :-(.
RUN npm --version
The command RUN npm --version works in the base image linked above, but apparently, not when I'm building on top of it using the FROM directive. Is anyone able to help me understand why?
/bin/sh: npm: command not found
15:15:19
The command '/bin/sh -c npm --version' returned a non-zero code: 127
enter code here
``
There seem to have been a few recent commits to the repo which has apparently fixed the issue! I was able to build and run the Dockerfile to get the npm version without any issues!
In case you need additional modules (such as npm) to be installed on a base image that doesn't provide it, use a multi-stage Dockerfile with different FROM commands to get your necessary dependencies onto a single Dockerfile and a docker image later. Reference.
Need your kind advise on this. I am very new to Jenkins pipeline and groovy. I have also Googled quite a bit about this specific thing but can't find any definite answers (mostly due to how inexperience I am so I might be missing it).
I have a groovy that is used to run a Jenkins job, at one point I have to run a python script in $WORKSPACE (see below)
stage("Compile Canary") {
steps {
script {
Map bbMap = [
name: env.STAGE_NAME,
commitID: gitInfo.GIT_COMMIT,
url: env.BUILD_URL,
message: "Local Compile"
]
try {
updateBitBucket.inProgress(bbMap)
sh label: '', script: '''
#!/bin/bash
set -e
cd $WORKSPACE/automation/
pip install --upgrade pip
pip install botocore==1.19.50
pip install boto3==1.16.0
python bin/install-dependencies.py
All the pip install / upgrade and boto installs went fine, it's only when running this section:
python bin/install-dependencies.py
that is having issues due to the fact that it cannot find the file (see below for Jenkins output)
+ python bin/install-lambda-dependencies.py
python: can't open file 'bin/install-dependencies.py': [Errno 2] No such file or directory
The error is obvious, which begs the question, how can I import this file? Can I copy it to the git repo and then import it? I'm using this python script because there are quite a long list of dependencies, and also I want to use this script as a standard across my team.
FYI: the python file is currently residing in the same code repository as the groovy file, it is placed in "bin" directory.
Thank you very much!
I am trying to use code formatter, Prettier, on a Bitbucket pipeline but all I get is a "prettier command not found".
This is my pipeline configuration:
mage: node:latest
pipelines:
branches:
master:
- step:
caches:
- node
script:
- npm install prettier
- prettier --check
Is it even possible to run it through pipelines or would have to forcefully do it locally?
I will suggest you follow the documentation https://prettier.io/docs/en/install.html
install prettier in your repo
npm install --save-dev --save-exact prettier
"--save-dev" because the production will not need prettier to serve your application
add your rules in .prettierrc.json file in the root of the repo
in the pipeline use
npx prettier --check .
What is that npx thing? npx ships with npm and lets you run locally installed tools. We’ll leave off the npx part for brevity throughout the rest of this file!
Note: If you forget to install Prettier first, npx will temporarily download the latest version. That’s not a good idea when using Prettier, because we change how code is formatted in each release! It’s important to have a locked down version of Prettier in your package.json. And it’s faster, too.
When you have installed prettier in your repo, you can even add pre-commit hooks to modify the staged files before pushing.
I'm trying to implement CI with Github Actions to a repository. In the workflow, I would like to run a test script using pytest. However, the test script and the script it is testing had a rospy dependency, although the dependency is not vital to the test, where it is publishing the result of certain calculation (node.Publisher is mocked using pytest).
I'm still new to ROS and I am a bit confused about what I need to install. Do I need to install the whole ROS library for the test or do I only need to install rospy? What is the best way to install the package and add it to the path in Github Actions?
I tried sudo apt-get install -y python-rospy, but the package is not detected by python with ImportError: No module named rospy.
I am running the test in Ubuntu 18.04.
Thank you in advance
I am new to protractor, node and all. I have learned to create scripts with protractor. But now I need to run this test scripts along the build.
I have seen people can run it with npm test/ npm test e2e. How can I achieve this.
My project structure,
webapp/test/e2e
In my project they are using webpack and karma.
Sorry, I am really noob at this and don't know how to set it up.
We also need to configure it in Jenkins, so it runs and generates a flag for success or failure.
Any suggestions to set it up would really really be helpful. Please be as elaborate as possible as it is hard for me to understand things as of now.
Thank you so much!
If the package.json file is in the root folder of the project you can add the code below to it and run it using npm test and npm run test:e2e. This assumes you have Protractor and Karma installed locally in your project which would be a best practice (if it is not in the package.json as a dependency it probably is not).
"scripts": {
"postinstall": "node_modules/protractor/bin/webdriver-manager update",
"test": "node_modules/karma/bin/karma start webapp/test/unit/karma.conf.js"
"test:e2e": "node_modules/protractor/bin/protractor webapp/test/e2e/conf.js"
}
postinstall - This will run webdriver-manager update locally automatically after running npm install, you could run into issues with missing drivers when using a CI Server like Jenkins that is continuously checking our your repository (it also saves you a CI step)
test - This is equivalent to karma start karma.conf.js
test:e2e - This is equivalent to protractor conf.js it is just running it locally. To run these tests type npm run test:e2e from the directory with your package.json
It is recommended to not combine Protractor and Karma together (although possible) Karma should be used for Unit and Integration tests and Protractor should be used for e2e tests.
As an extra tip it is possible to pass protractor or karma command line arguments through the npm scripts. Simply append it the way you normally would (e.g.
"webapp/test/e2e/conf.js --baseUrl=https://yourbaseurl.com/")
Your question regarding integrating NPM into Jenkins has already been answered fairly well here how to run npm/grunt command from jenkins but be aware running your tests entirely in Jenkins will cause it to run headlessly which when using Windows will cause it to run in Session 0 where the screen resolution will be smaller which causes some tests to fail, opening the selenium server beforehand in a Terminal/Powershell window will cause Jenkins to route your tests through that so it will visually display on your computer.