serverless-bundle Missing Dependencies - serverless

I am failing to generate a bundle with serverless-bundle plugin.
tsconfig.json
{
"compilerOptions": {
"lib": ["es2017"],
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"target": "es2017",
"outDir": "dist",
"declaration": true,
"sourceMap": true,
"baseUrl": ".",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"allowJs": false,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["./dist/**/*", "./node_modules/**/*"]
}
serverless.yml
service: serverless-boilerplate
custom:
# Our stage is based on what is passed in when running serverless
# commands. Or falls back to what we have set in the provider section.
stage: ${opt:stage, 'offline'}
region: ${opt:region, 'us-east-1'}
bundle:
linting: false
serverless-offline:
httpPort: 4000
noPrependStageInUrl: true
provider:
name: aws
runtime: nodejs14.x
memorySize: 512
timeout: 10
logRetentionInDays: 90
lambdaHashingVersion: 20201221 # https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
logs:
httpApi: true
httpApi:
# metrics: true # Enable if you need
cors: true
functions:
app:
handler: src/handler.handler
# reservedConcurrency: 100
events:
- httpApi:
path: '/{proxy+}'
method: '*'
package:
individually: true
plugins:
- serverless-dotenv-plugin
- serverless-bundle
- serverless-offline
Here is the .serverless/app.zip file after running sls package
As you see there is no node_modules folder.
If I launch the app with sls offline start --stage offline
It looks like one of the dependencies trying to read a directory (resources) in its own package folder in node_modules:
But since serverless-bundle merges everything into handler.js , there are no node_modules folder and dependency folders, so readdir() is failing.
What I am doing wrong?

Looks like adding externals: all to custom.bundle in serverless.yml fixed the issue.

Related

How to specify an URL in .env file of Gatsby app?

Just in case, I'd like to know against Gatsby app, in case its settings differ from other node based apps.
I want to refactor gatsby-config.js by moving http://localhost:1337 to .env.
From
plugins: [
{
resolve: `gatsby-source-strapi`,
options: {
apiURL: `http://localhost:1337`,
},
},
]
To
plugins: [
{
resolve: `gatsby-source-strapi`,
options: {
apiURL: process.env.STRAPI,
},
},
]
and .env as follows didn't work for me:
STRAPI=$(http://localhost:1337)
Create a file in the root of your project named .env.development and .env.production. There, create your variable, just:
STRAPI= "http://localhost:1337"
In your gatsby-config.js add the following snippet (above module exportation):
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
})
Finally, leave the configuration just with:
plugins: [
{
resolve: `gatsby-source-strapi`,
options: {
apiURL: process.env.STRAPI,
},
},
]
By default, Gatsby will take the .env.development or .env.production when running gatsby develop or gatsby build respectively, allowing you to pass the environment variables to the server files (gatsby-config.js, etc).

./dist/out-tsc folder is always empty

While running "ng build" or "ng build --prod" there is no dist/out-tsc folder and even if i create one the folder remains empty. Although ng serve works fine and the site loads.
I want to host this site but without the output folder it is worthless.
ts-config.json is as below:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/#types"
],
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
Note: the project was generating all the required files until last week but stopped doing it all of a sudden.
I have also tried creating a new project and building it the result is same i.e. no out-tsc folder.
You can solve this issue in two ways.
Method 1
Update outputPath in angular.json
"prefix": "app",
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/out-tsc",
"index": "src/index.html",
"main": "src/main.ts",
Method 2
Use the following command for production build
ng build --prod --output-path=dist/out-tsc/
I've tested both methods for your code. Both are working fine.

publish over ftp jenkins plugin is not uploading subfolder

I have a Jenkinsfile that deploys my angular app code to a site using the Publish over FTP plugin. All of the files in the dist folder are transferred except an assets subfolder. I have tried putting in the following values for the sourceFiles parameter with no success: 'webapp/dist/', 'webapp/dist/**', 'webapp/dist/**/*'.
Here is the publish over FTP part of my Jenkinsfile:
stage('Deploy') {
steps {
echo 'Deploying....'
ftpPublisher paramPublish: null, masterNodeName:'', alwaysPublishFromMaster: true, continueOnError: false, failOnError: true, publishers: [
[configName: 'Angular app', verbose: true, transfers: [
[asciiMode: false, cleanRemote: true, makeEmptyDirs:true, excludes: '', flatten: false,
noDefaultExcludes: false, patternSeparator: '[, ]+',
remoteDirectory: "webapp",
removePrefix: "webapp/dist",
remoteDirectorySDF: false,
sourceFiles: 'webapp/dist/**/*']
], usePromotionTimestamp: false, `enter code here`useWorkspaceInPromotion: false]
]
}
}
I've looked at the Publish over FTP pipeline documentation: https://jenkins.io/doc/pipeline/steps/publish-over-ftp/ and couldn't find anything parameters that I was missing. I'm stuck.
I was able to solve the issue. I changed the title of the pipeline to all lowercase letters without any spaces. I then changed the file path of the workspace folder to 'C:/jenkinsworkspace/${ITEM_FULL_NAME}' by modifying the workspaceDir entry in the config.xml located in the Jenkins root directory. I stopped the Jenkins service before modifying the config.xml. Both the assets folder and the favicon got generated in the build. It was one of the solutions mentioned in https://github.com/angular/angular-cli/issues/9230. Thanks for your help #Alberto L. Bonfiglio.

How to use publish over ssh plugin in pipeline

I would like to SSH to linux server from Jenkins hosted on windows and execute a command over in linux machine, I tried installing publish over ssh plugin and tested the connection in global config and it works fine, I don't know how to proceed next in pipeline. Any help would be appreciated.
If you are using a pipeline project and a Jenkinsfile, then all you need to do is go into your project in Jenkins and click configure. In the pipeline section of the configuration, at the bottom there is a link "pipeline syntax". It will take you to the Snippet Generator. Its self explanatory and in our case it allows to generate "publish over ssh" snippets that you would add to your Jenkinsfile (add it to a steps section inside a stage definition). In the generator you can define what to publish, options to run a shell command, etc. source
In case you were looking for the syntax for a declarative pipeline (Jenkinsfile) for Publish-Over-SSH, (Instead of the scripted pipeline, which is all I could find). Here's what finally worked for me.
pipeline{
agent any
environment {
RELEASENAME="yourProject-ci"
}
stages{
stage("Get the charts..."){
steps {checkout scm}
}
stage('SSH transfer') {
steps([$class: 'BapSshPromotionPublisherPlugin']) {
sshPublisher(
continueOnError: false, failOnError: true,
publishers: [
sshPublisherDesc(
configName: "kubernetes_master",
verbose: true,
transfers: [
sshTransfer(execCommand: "/bin/rm -rf /opt/deploy/helm"),
sshTransfer(sourceFiles: "helm/**",)
]
)
]
)
}
}
stage('Deploy Helm Scripts'){
steps([$class: 'BapSshPromotionPublisherPlugin']) {
sshPublisher(
continueOnError: false, failOnError: true,
publishers: [
sshPublisherDesc(
configName: "kubernetes_master",
verbose: true,
transfers: [
sshTransfer(execCommand: "cd /opt/deploy/helm;helm upgrade ${RELEASENAME} . --install"),
]
)
]
)
}
}
}
}
I have a checkout that happens first and then I copy some helm charts from the checkout to my kubernetes master and then run the charts.
configName: "kubernetes_master" is something I setup in the Publish_over_ssh plugin configuration section (Found under Manage Jenkins > Configure System) so I could reference it. It includes a username, sshkey, destination hostname, and base directory for the destination which I put as /opt/deploy.
FYI execCommand does not use the base directory... it assumes you will use full pathing.
Hope that helps.
edit: I should probably mention that there are lots more options for the sshPublisher than what I used. You can find them here: https://jenkins.io/doc/pipeline/steps/publish-over-ssh/
Based on levis answer, the below has worked for me.
stage('Deploy') {
agent any
steps {
sh 'mv target/my-app-0.0.1-SNAPSHOT.jar my-app.jar'
sshPublisher(
continueOnError: false,
failOnError: true,
publishers: [
sshPublisherDesc(
configName: "my-ssh-connection",
transfers: [sshTransfer(sourceFiles: 'my-app.jar')],
verbose: true
)
]
)
}
}
I got this question some time ago, and here is the answer. Change the code according to your requirement.
pipeline {
agent any
options { timestamps () }
stages {
stage('Publish over ssh plugin in pipeline') {
steps([$class: 'BapSshPromotionPublisherPlugin']) {
script {
List SERVERS_LIST = ["Server_1", "Server_2"]
for(cr_server in SERVERS_LIST){
sshPublisher(
publishers: [
sshPublisherDesc(
configName: cr_server,
transfers: [
sshTransfer(
cleanRemote: false,
excludes: '',
execCommand: '',
execTimeout: 120000,
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: '',
remoteDirectorySDF: false,
removePrefix: '',
sourceFiles: '**/*'
)
],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: false
)
]
)
}
}
}
}
}
}
I don't know how helpful this'll be but I found a tutorial on something that should work until they have a nicer way to do it.

Travis-ci and bintray deployment

I am trying to deploy my code to bintray through travis.
The deploy part of my .travis.yml
- provider: bintray
file: bintray.json
user: triberraar
key:
secure: <encrypted key>
on:
repo: triberraar/triber-todo-config-server
branch: develop
tags: true
And the bintray.json file:
{
"package": {
"name": "triber-todo-config-server",
"repo": "maven",
"vcs_url": "https://github.com/triberraar/triber-todo-config-server",
"github_use_tag_release_notes": true,
"licenses": [
"MIT"
],
"public_download_numbers": false,
"public_stats": false
},
"version": {
"name": "${project.version}",
"vcs_tag": "${project.version}",
"released": "${build.timestamp}"
},
"files": [
{
"includePattern": "triber-todo-config-server/target/(.*\.jar)",
"uploadPattern": "be/tribersoft/triber-todo-config-server/0.0.1-SNAPSHOT/$1"
},
{
"includePattern": "triber-todo-config-server/pom.xml",
"uploadPattern": "be/tribersoft/triber-todo-config-server/${project.version}/triber-todo-config-server-${project.version}.pom"
}
],
"publish": true
}
However when i the build runs on travis the deploy fails due to:
Unexpected HTTP response code 405 returned from Bintray while checking if package 'triber-todo-config-server' exists. Response message: Method Not Allowed
Anyone have experience with this?
You can see the travis log here: travis build
Any help is appreciated.

Resources