Jenkins - Deploy a Yaml file to Kubernetes from Pipeline Error - javascript

I cannot resolve an issue that I was stuck with in my beginner tutorial. When I try to create just a deployment on Kubernetes from Jenkins, I got the error message.
According to my research, Jackson 2 API v2.10.0, Kubernetes v1.21.3, Kubernetes Client API v4.6.3-1, Kubernetes Continuous Deploy v2.1.2,
and I need to use Kubernetes Credentials v0.5.0 plug-ins. I don't know how can I do this?
How can I solve this problem? Could anyone pls help me?
Error
Starting Kubernetes deployment
Loading configuration: /var/lib/jenkins/workspace/k8sdeploy/k8sdeploy.yml
ERROR: ERROR: Can't construct a java object for tag:yaml.org,2002:io.kubernetes.client.openapi.models.V1Deployment; exception=Class not found: io.kubernetes.client.openapi.models.V1Deployment
in 'reader', line 1, column 1:
apiVersion: apps/v1
^
hudson.remoting.ProxyException: Can't construct a java object for tag:yaml.org,2002:io.kubernetes.client.openapi.models.V1Deployment; exception=Class not found: io.kubernetes.client.openapi.models.V1Deployment
in 'reader', line 1, column 1:
apiVersion: apps/v1
^
My Pipeline
pipeline {
agent any
stages {
stage('Clone App from Github') {
steps {
git credentialsId: 'github', url: 'https://github.com/eneslanpir/k8sdeploy'
}
}
stage("Wait For 5 Seconds"){
steps {
sleep 5
}
}
stage("Kubernetes Create Deployment"){
steps{
script {
kubernetesDeploy(configs: "k8sdeploy.yml", kubeconfigId: "kubeconfig")
}
}
}
}
}
My Deployment yaml from Github (Tested - Working on Kuberentes)
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment-jenkins
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx-jenkins
image: nginx:1.16.1
ports:
- containerPort: 80
When downgrade to Jackson 2 API v2.10.0, everythings are going wrong.

I solved the problem by trying the plugins in the links below.
https://updates.jenkins.io/download/plugins/

Related

Blazor Azure Static Web App not executing Javascript

I'm using a little bit of Javascript in my Blazor app to do some light work. Everything works fine on my local computer. When I publish to my Azure Static Web App, the Javascript does not execute. Here is the error message.
Refused to execute script from 'https://fullUrl/js.download' because its MIME type ('application/octet-stream') is not executable, and strict MIME type checking is enabled.
Here is my yaml file.
trigger:
- main
pool:
vmImage: ubuntu-latest
# vmImage: windows-latest
steps:
- checkout: self
submodules: true
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
- task: AzureStaticWebApp#0
inputs:
app_location: '/'
api_location: ''
output_location: 'wwwroot'
azure_static_web_apps_api_token: $(deployment_token)
I placed this in my staticwebapp.config.json file.
"mimeTypes": {
".json": "text/json",
".js": "application/octet-stream"
}
Does anyone know how to get this to work? Thanks!
I finally got all of this to work. I renamed myfile.js.download to just myfile.js. I then changed another js file to js.js. Anyway, that seemed to be the change that was needed.
Here is the updated yaml file.
trigger:
- master
pool:
vmImage: ubuntu-latest
# vmImage: windows-latest
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
command: 'build'
arguments: '--configuration Release'
projects: 'YourProjectName.csproj'
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration Release'
zipAfterPublish: false
- task: AzureStaticWebApp#0
inputs:
skip_app_build: true
app_location: '/bin/Release/net5.0/publish/wwwroot'
output_location: ''
azure_static_web_apps_api_token: 'YOURDEPLOYMENTTOKEN'

Configure NATS max_payload on Kubernetes

my problem is that I need to increase NATS max_payload in production environment but it uses Kubernetes and I have no idea how to do that, I tried to use ConfigMap but I had not success.
In local/dev environment it uses a NATS config file with docker so it works fine.
Way to make it works local: NATS with moleculer. How can I change NATS max_payload value?
Code inside k8s/deployment.develop.yaml
(...)
apiVersion: v1
kind: ServiceAccount
metadata:
name: nats
namespace: develop
labels:
account: nats
---
apiVersion: v1
kind: Service
metadata:
name: nats
namespace: develop
labels:
app: nats
service: nats
spec:
ports:
- port: 4222
targetPort: 4222
selector:
app: nats
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nats-v1
namespace: develop
labels:
app: nats
version: v1
spec:
replicas: 1
strategy: {}
selector:
matchLabels:
app: nats
version: v1
template:
metadata:
labels:
app: nats
version: v1
spec:
serviceAccountName: nats
containers:
- image: 'nats:alpine'
name: nats
ports:
- containerPort: 4222
restartPolicy: Always
tolerations: []
affinity: {}
Thanks!
The payload value is hardcoded into the docker image (in the nats-server.conf file), so you cannot change it via a configmap. The only solution I found is to build my own nats image with a modified nats-server.conf file.
Here is how to do it.
First, select an image flavor from the official repo and download the content (for example Dockerfile and nats-server.conf from here).
Modify the nats-server.conf file to change the max_payload value : just add the following line (this file is NOT in JSON format)
max_payload: 4Mb
Then build the image : docker image build .
Tag it, upload it to your own repo and use it instead of the official nats image
I would recommend using these NATS Helm charts and then use something like the following:
nats:
limits:
maxPayload: "5mb"
You can find a full example here: https://github.com/nats-io/k8s/tree/master/helm/charts/nats#limits

(Gatsby-Strapi) Error: Request failed with status code 404

I want to follow the instruction :https://strapi.io/blog/building-a-static-website-using-gatsby-and-strapi#allowaccess
But encounter Error: Request failed with status code 404
Node.js version:
v10.13.0
npm version:
6.14.6
Strapi version:
3.1.0-alpha.5
Operating system:
mac
Which example is causing problem?
strapi.io/blog/building-a-static-website-using-gatsby-and-strapi#allowaccess
What is the current behavior?
Graphql Query doesn't work.
the steps to reproduce the problem:
$ gatsby develop
success open and validate gatsby-configs
success load plugins - 2.011s
success onPreInit - 0.004s
success initialize cache - 0.018s
success copy gatsby files - 0.102s
success onPreBootstrap - 0.017s
success createSchemaCustomization -
info Starting to fetch data from Strapi
info Starting to fetch data from Strapi
info Starting to fetch data from Strapi
ERROR #11321 PLUGIN
"gatsby-source-strapi" threw an error while running the sourceNodes lifecycle:
Request failed with status code 404
Error: Request failed with status code 404
createError.js:16 createError
[portfolio_v4]/[gatsby-source-strapi ]/[axios]/lib/core/createError.js:16 :15
settle.js:18 settle
[portfolio_v4]/[gatsby-source-strapi ]/[axios]/lib/core/settle.js:18:12
http.js:202 IncomingMessage.handleSt reamEnd
[portfolio_v4]/[gatsby-source-strapi ]/[axios]/lib/adapters/http.js:202:1 1
task_queues.js:84 processTicksAndRej ections
internal/process/task_queues.js:84:2 1
What is the expected behavior?
What is the expected behavior?
Doesn't work when I try to get from gatsby
http://localhost:8000/___graphql
There is no method allStrapiblogs on http://localhost:8000/___graphql
Please share your gatsby-config.js screen, the gatsby-source-strapi section.
this could be caused by the collectionTypes/singleTypes in the gatsby-source-strapi, or your USERS & PERMISSIONS PLUGIN (roles) in strapi is not set
I've changed contentTypes to collectionTypes
Also there is a new version (v4) of strapi and to make gatsby work with this new version, you need to use the following gatsby-source plugin.
npm install --save gatsby-source-strapi#relate-app/gatsby-source-strapi
This plugin wants a token which you can create at http://localhost:1337/admin/settings/api-tokens
before testing the new plugin make sure to clean out your gatsby cache by using the following command:
gatsby clean
{
resolve: "gatsby-source-strapi",
options: {
apiURL: "http://localhost:1337",
collectionTypes: ["Article", "User", 'Test'],
// Extract images from markdown fields.
markdownImages: {
typesToParse: {
Article: ["body"],
ComponentBlockBody: ["text"],
},
},
// Only include specific locale.
locale: "en", // default to all
// Include drafts in build.
preview: true, // defaults to false
// Use application token.
token:
'Your-strapi-api-token',
// Add additional headers.
headers: {},
},
},
There has also been a article about a new plugin, but this refers to another one which didn't work for me.
https://strapi.io/blog/introducing-the-new-gatsby-source-strapi-plugin
When added "${DOMAIN}/api" on apiURL it worked for me with strapi v4
apiURL: "http://localhost:1337/api",
{
resolve: "gatsby-source-strapi",
options: {
apiURL: "http://localhost:1337/api",
collectionTypes: [`messages`],
// Extract images from markdown fields.
markdownImages: {
typesToParse: {
Article: ["body"],
ComponentBlockBody: ["text"],
},
},
// Only include specific locale.
locale: "en", // default to all
// Include drafts in build.
preview: true, // defaults to false
// Use application token.
token: "token",
// Add additional headers.
headers: {},
},
},
This code solved my problem.
{
resolve:'gatsby-source-strapi',
options:{
apiURL:'*http://localhost:1337/admin/content-manager/collectionType/api::*',
collectionTypes: ['propiedads','paginas','categorias'],
queryLimit:1000
}
}

Deploy a Javascript Policy in Keycloak 10

I've followed the Create a JAR with the scripts to deploy instruction to create a custom Javascript policy for checking user attributes and it seems to be deployed successfully, however, I can't see the policy name in the create policy dropdown. Is there any setting I need to enable for this feature?
After uploading the .jar file to /keycloak/standalone/deployments, it says WFLYSRV0010: Deployed "script.jar" (runtime-name : "script.jar") without any error. I can also see the {filename}.jar.deployed next to my script file.
Setup: I use docker-compose to launch a jboss/keycloak version 10.0.1 container. Here's my docker-compose file:
version: "3.1"
services:
keycloak:
image: jboss/keycloak
restart: always
ports:
- 8080:8080
environment:
KEYCLOAK_PASSWORD: admin
KEYCLOAK_USER: admin
volumes:
- ./deployments:/opt/jboss/keycloak/standalone/deployments
keycloak-scripts.json:
{
"policies": [
{
"name": "my-policy",
"fileName": "my-script-policy.js",
"description": "My Policy from a JS file"
}
]
}
my-script-policy.js:
var context = $evaluation.getContext();
var contextAttributes = context.getAttributes();
if (contextAttributes.containsValue('kc.client.network.ip_address', '127.0.0.1')) {
$evaluation.grant();
}
Client policy setting
Thank you in advance for any suggestions.

Ember 3.6 super-rentals tutorial LEAFLET_MAPS_API_KEY using environment.js

While going through the ember 3.6 super-rentals tutorial I ran into a few snags adding the ember-simple-leaflet-maps.
I couldn't get the environment variable LEAFLET_MAPS_API_KEY to set.
https://guides.emberjs.com/release/tutorial/service/
To my understanding, the tutorial has you set an environment variable on your operating system? Maybe I'm wrong in thinking that, but I wanted a way to just add the variable to my project /config/environment.js
Answer from OP:
After the addon was installed:
ember install ember-simple-leaflet-maps
I opened the geocode.js file to see how the service was injecting the api key. Path is:
node_modules\ember-simple-leaflet-maps\addon\services\geocode.js
The line of code was:
let accessToken = getOwner(this).resolveRegistration('config:environment')['ember-simple-leaflet-maps'].apiKey;
From there I just added the lookup it was looking for to my file /config/environment.js
let ENV = {
modulePrefix: 'super-rentals',
environment,
rootURL: '/',
locationType: 'auto',
'ember-simple-leaflet-maps': {
apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
},
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false
}
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
}
};
Rebuild the project and serve, my maps are now showing up
ember build
ember serve

Categories