How should I deploy a molecular microservice project on the server without using docker and Kubernetes?
I pull my updated code into a server and run the npm run dev command project run as per aspected.
But now I want to set up pm2 for this project so, what do I need to do?
I try to run npm run start command on a server but I am getting below output and the project is not running.
Please help.
Your problem is that you didn't configure the services to start. For Docker and Kubernetes environment, we use SERVICES env variable to configure what services should be loaded on a Moleculer node.
So you can also use this way, or modify the start script in package.json and set the services what you want to load. E.g.
moleculer-runner -e services/**/*.service.js
I got the solution.
If we not use the Docker and Kubernetes for moleclar project and directly clone our code on server same as like normal NodeJS(Express) project.
Then we need to create index.js file and need to put below lines.
const { ServiceBroker } = require('moleculer');
const config = require('./moleculer.config');
config.hotReload = true;
const broker = new ServiceBroker(config);
broker.loadServices('services', '**/*.service.js');
broker.start();
So, using above command Molecular started all the service of our project
After, index file we can able to start our project using pm2 service.
I created a start script (api-init.json) as below:
[
{
"script": "./node_modules/moleculer/bin/moleculer-runner.js",
"args": "services",
"instances": "max",
"watch": false,
"name": "API"
}
]
Then use pm2 to start:
pm2 start api-init.json
Related
We have an express server that runs on google cloud run. When our server attempts to respond with a HTTP status code of 204 this gets transformed into 502 Bad Gateway. I have confirmed that this is only happening in GCP. In this specific example, we are using Google's fully managed endpoint. Running this on my local machine yields the expected results. Also, sending a 200 status code works successfully with the same code.
Error code: upstream connect error or disconnect/reset before headers. reset reason: protocol error
Here is our express endpoint that responds with the 204 status code:
app.post('/', [cors(corsConfig), jsonParser], async (req, res) => {
res.setTimeout(timeout, () => {
log(’timeout’)
res.sendStatus('204');
res.end();
});
});
Connection details:
Utilizing Google's managed endpoint
HTTP/2 disabled
here is our Dockerfile:
# Use the official lightweight Node.js 12 image.
# https://hub.docker.com/_/node
FROM node:12-slim AS base
# Create and change to the app directory.
WORKDIR /usr/src/app
# Run our webpack build inside a separate stage
FROM base AS build
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
COPY yarn.lock ./
# Install all dependencies for a build
RUN yarn
COPY . ./
RUN yarn build
FROM base AS runtime
COPY package*.json ./
COPY yarn.lock ./
# Copy only the built app output
COPY --from=build /usr/src/app/dist ./dist
# Re-install only production dependencies, to reduce image size ($$)
RUN yarn --only=production
COPY public ./public
COPY partners.yml ./
# Run the web service on container startup.
CMD [ "yarn", "start" ]
We were having the same issue with a Django application in Google Cloud Run. The issue was that our application was not sending an empty response body as is required with a 204 status. The framework we are using added some wrapping around our empty result.
Many servers incorrectly send a body in a 204 response, so browsers generally use heuristics to see if a response body is present (link). The Cloud Run proxy appears to adhere to the standard strictly, which results in an HTTP protocol error when a response body is present.
To fix it you need to make sure you return an actually empty response from your application, or just use a 200 status code.
I've installed Vue CLI v3, and in my terminal:
created a new app using 'vue create my-project' (accepting default config)
navigated to the 'my-project' app directory and run 'npm run serve', the result of which is:
DONE Compiled successfully in 11889ms
App running at:
- Local: http://localhost:8080/
- Network: http://192.168.0.3:8080/
Note that the development build is not optimized. To create a production build, run npm run build.
... and then, when making any change whatsoever to the Hello World component, e.g., a tweak to the css, something obvious like the link color, nothing happens; no response in the terminal, no browser refresh, and no update to the page when manually refreshing.
I've built a few apps using Vue in the past, hot module reloading was working previously, but now there is zero activity/response in the terminal regardless of what I change in any project file; only if I close the terminal tab, re-open a tab, navigate to the project directory and re-run 'npm run serve', and refresh the browser do I see the changes. obviously this is unusable. What am I missing?
This issue has been resolved, though I am not 100% sure what caused it.
I noticed that some people with similar failures of hot reload had mentioned bad directory names. My vue project's parent directory name was legit but I had renamed it at one point (though that was multiple restarts and reinstalls ago), and I also noticed that some of the vue-cli-created project folders were not displaying in the Finder until it was quit and restarted. I figured there was something corrupted about that folder. I created a new folder - a sibling of the dubious folder - and had another go with vue-cli, and it worked as expected.
Hope this helps someone. Thanks again to those of you who offered suggestions.
Whiskey T.
For anyone using WSL. I ran into this exact problem and solved it via this method.
I had the same issue, It seems wsl2 does not watch for file changes
inside the windows filesystem. Everything works fine if the vue
project is inside the Ubuntu filesystem. Check out this link for
further info
https://learn.microsoft.com/en-us/windows/wsl/wsl2-ux-changes.
Source: https://github.com/vuejs/vue-cli/issues/4421#issuecomment-557194129
If u installed Node js as sudo, then Running sudo npm run serve worked for me. Actually node.js was installed as sudo and the project also created as sudo so when I run npm run serve the vue-hot-reload-api cannot access the node server to do hot reload
Additionally if u want the hot reload to work in offline mode, then switch off your network and then npm run serve and then reconnect to your network. That will work as localhost protocol and not use your local network IP.
Cheers
Add following script tag to package.json file
...
"scripts": {
"dev": "cross-env NODE_ENV=development vue-cli-service serve --open --host localhost",
....
},
....
and run with
npm install –save-dev cross-env
npm run dev
source: https://www.davidyardy.com/blog/vue-cli-creating-a-project%E2%80%93issue-with-hot-reload/
Developing full-stack web apps, I would like to have all my code and build logic on a linux machine (i.e. git, docker containers and other terminal commands), but all my development workflow on my windows machine (so my IDE, web browser and REST client) accessing it via SSH.
I've managed to do all of that except for the IDE, I could only edit individual files via SSH instead of managing a folder as a project. So right now I use VSCode on the linux machine (Ubuntu), and it's the last thing preventing me for dropping the graphical interface and install Ubuntu Server on it.
And no, I don't want to use Vim or Emacs. I want to use VSCode, or another modern IDE, but preferably VSCode.
Try using the Remote VSCode plugin as explained here: Using Remote VSCode
This discussion is exactly about your problem: VSCode 13643 issue Github
EDIT: I have recently found a new VSCode plugin on Github: vs-deploy. It was designed to deploy files and folders remotely very quickly. It seems to be working and I haven't found any bugs so far. It works with FTP, SFTP (SSH) and many other protocols.
The SSH.NET nuget Package can be used quite nicly to copy files and folders.
Here is an example:
var host = "YourServerIpAddress";
var port = 22;
var user = "root"; // TODO: fix
var yourPathToAPrivateKeyFile = #"C:\Users\Bob\mykey"; // Use certificate for login
var authMethod = new PrivateKeyAuthenticationMethod(user, new PrivateKeyFile(yourPathToAPrivateKeyFile));
var connectionInfo = new ConnectionInfo(host, port, user, authMethod);
using (var client = new SftpClient(connectionInfo))
{
client.Connect();
if (client.IsConnected)
{
//TODO: Copy folders recursivly etc.
DirectoryInfo source = new DirectoryInfo(#"C:\your\probject\publish\path");
foreach (var file in source.GetFiles())
{
client.UploadFile(File.OpenRead(file.FullName), $"/home/yourUploadPath/{file.Name}", true);
}
}
}
When you create a upload console application using the code above your should be able to automatically trigger an upload by using postbuild events by adding a section to your Project.
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="path to execute your script or application" />
</Target>
If you prefer to do the same but more manual you can perform a
dotnet build --configuration Release
followed by a
dotnet publish ~/projects/app1/app1.csproj
and then use the code above to perform an upload.
Search for the extension SSHExtension developed by Vitaly Kondratiev
Install the extension.
And edit the serverlist json with the server details.
ex:
"sshextension.serverList": [
{
"name": "Kuberntes 212",
"host": "10.64.234.54",
"port": 22,
"username": "root",
"password": "byebye"
}
]
save the file
Then log in using ctrl+shift+p and choose sshextension open ssh extension category. It shall create a session for you.
More Easily if u need the entire directory structure into ur local workspace.
Use extension ftp-simple in vscode. It works as a wonder, trust me.
Install ftp-simple in vscode
ctrl+shift+p
select ftp-simple:config.
Configure your settings
[
{
"name": "Kubernetes 212",
"host": "10.75.64.2",
"port": 22,
"type": "sftp",
"username": "root",
"password": "byebye",
"path": "/home/vinod/",
"autosave": true,
"confirm": true
}]
save the file.
Now ctrl+shift+p
and select ftp-simple:remote directory to workspace.
Viola Your work is done, Life is simple
When working locally I start my application with an npm command in my package.json. The problem is that I need this command to include a password for a remote database:
"scripts": {
"start":
"MONGO_URL='mongodb://USERNAME:PASSWORD#URL:PORT/DB-NAME' meteor --settings settings.json"
},
This is working but I dont want to save my password to my source control. How can I run the same command without committing my password?
You can set the environement variable programmaticaly at startup and store the secret in the settings.json file (which is appropriate to store secrets and shouldn't be in version control - see here)
in the startup/server/index.js file:
let mongoPassword = Meteor.settings.private.mongoPassword;
process.env.MONGO_URL = "mongodb://USERNAME:" + mongoPassword + "#URL:PORT/DB-NAME";
You can also choose to start your app using the meteor command and store the MONGO_URL environment variable in your local development environment
In production, you shouldn't use the meteor command but build with meteor build and then run the bundled app with node main.js
I want to setup apache openwhisk on-premise in my organization. so that we can use it internally within the org. i am not able to find much on the net on this. i tried cloning the code from git and building it in the windows. but it doesn't work. kindly help
Follow these steps to start the platform in a virtual machine in your local environment.
# Clone openwhisk
git clone --depth=1 https://github.com/openwhisk/openwhisk.git
# Change directory to tools/vagrant
cd openwhisk/tools/vagrant
# Run script to create vm and run hello action
./hello
If this works, you should see the following output.
wsk action invoke /whisk.system/utils/echo -p message hello --result
{
"message": "hello"
}
If you encounter problems with these steps, please open an issue in the Github repository for the project.
Deploy OpenWhisk using the ansible playbook in high-availability mode.