Deployment to external server using Circle Ci - javascript

It's my first time I'm trying to do that.
I'd like to set up config file in circle.ci in order to deploy my React app to expternal server. Before I just used Ftp connection to upload files to the production server. But now I'd like to do that authomatically. So in my circle config file I've already configured steps to run yarn install and yarn build, all is just doing fine, but the last step needs to be done, I basically have no knowledge how to connect it all, ie. files comes from github, then they are used for build purpose by circle.ci, then I'd like to deploy it to the production server. What is the flow here, and what should I use (ssh somehow, but how?). Thanks

If you're hosting provider supports it, I would suggest using rsync over FTP since it will ensure files are replicated without needing to upload everything, only changes. The --delete option will al\so remove extraneous files on the webhost that you may have removed from github.
- run:
name: Deploy public folder to YOURDOMAIN
command: |
rsync -avz --delete /local/path/ USERNAME#HOSTNAME:/Path/on/remote/server/
if yo have not made any changes to default CIrcleCI images, your local path is likely /home/circleci/project/

Related

NodeJS server side application deployment cosiderations

I am writing a nodejs application with Angular as my front end.
For this I am having Git as my code management server.
For client, I am doing minification and it is ready for production.
But I am not sure, how to prepare server side files for production.
Do we need to just copy all the Git folders into production server?.
Let me know the best way to deploy nodejs server application.
You could use pm2 as your daemon to keep your nodejs app up all the time.
Try not to include node_modules in the repo, cause different machines have different setups/installations, you cannot tell if one package would work before you run it unless you npm install them.
If you are familiar with Docker, use it, pre-bundle all (include node_modules) files into the docker image, and you do not need pm2 here, Docker itself can restart automatically. This is the ideal approach.
It really depends on how you (or your company) want to organize the workflow and the size of the project.
Sometimes I too use a GIT repository, because then is really simple to update: just a git pull and (if server files got edits) a pm2 restart N command.
In this way, you dont have to install the whole development stack in order to compile (and minify) the bundles - I guess you work on your local machine where all the development tools are installed.
Keep in mind to use the --dev flag while installing packages that are only required in development mode, so you can keep the production server as slim as possible.
A good practice I found is to add some random tokens inside the final bundle filename (both for js and css) that get then injected inside the final html static files, to avoid the refresh the page loop.
Once you have the bundle files on your dev machine, just upload them to the server (ftp, git, rsync, sshfs mount, whatever you like) and (if server files got edits) restart/reload the node process (Im using pm2 for this, its really great). If you only edited client files, no reload is needed.
Starting from here, there a lot of ways more or less sophisticated to do the job, like git pipelines for example.. but depends on the situation.
Edit: this is a good article about task runner (gulp vs grunt vs vanilla npm), while may be a little off topic, it analyze some aspect of the common deployment process

Managing application settings in an Electron application

I'm curious to know how can one manage application settings in an Electron application? I have found some excellent resources here (Where to store user settings in Electron (Atom Shell) Application?, for example) and elsewhere when it comes to managing user settings but couldn't find anything related to managing application settings.
To me, the difference between the two is that application settings could vary from environment to environment (dev/test/production) but would remain the same for all users of the application. They would contain things like API endpoints etc. User settings on the other hand would change from user to user based on their preferences like window width/height etc.
What I have done so far?
I have found this excellent package called config and start using it in my project. Based on the instructions, I have created a config folder and a default configuration file (I will create environment specific configuration files later).
It is working fine as long as I am developing the application. The application is picking up the default.json file properly from the config folder and is applying those settings correctly.
The problem comes when I package the application (MSI, DMG etc.). I am using electron-builder package for that purpose.
The problem with config package is that it looks for config folder inside the application's current working directory and because it doesn't find it in the folder where the application is installed, it simply throws an error. I even tried to manually copy this folder in my app folder (which is where electron-builder makes the packages) but that didn't help either. Ideally I would like to bundle the app settings in application's ASAR file so that it can't be decompiled.
My questions are:
How are people managing application settings for an Electron application?
Can config NPM package be used for that? Or is there an alternative to that package specifically for Electron applications?
I am not using an npm package but my approach is similar to what you have mentioned. I have a config directory with different config files for different environments: dev, test, prod. Then in my package.json I have added environment specific build commands. e.g. For prod:
"build-prod-config": "config/buildProdConfig.sh",
"build-renderer-prod": "webpack --config=webpack.config.renderer.prod.js",
"build-main-prod": "webpack --config=webpack.config.main.prod.js",
"build-prod": "npm run build-prod-config && npm run build-main-prod & npm run build-renderer-prod",
buildProdConfig.sh
#!/usr/bin/env bash
cp config/app.config.prod.js config/app.config.js
echo "Copied ProdConfig to Config"
//This is what a config file looks like
const Config = {
suppDataDirectoryPath: '/suppData/',
builtFor: 'prod',
}
module.exports = Config;
I then require Config whereever I need in my application and use the values. This is a simple thing for now, and perhaps doesn't have the flexibility of the config package you linked to, but it works.
Also, another important thing is that I am not packing my application into an ASAR archive, but I think my approach would still work because I am packing everything into a bundle using webpack.

Restore meteorjs source code from build app in .meteor directory

I accidentally erase CLIENT directory of my meteor project.
Fortunately, this project was not "running" so I can see in .meteor/local/build/programs/web.browser/app a file name app.js containing all my source code "compiled" (last build).
Is there a way to get back my CLIENT directory from this app.js ?
Thx
The Isobuild build system used by the Meteor Tool is one-way only. Meteor does not provide a way to reverse the Isobuild compiler, bundler, builder, and linker steps. To restore your client directory, you'll have to reverse engineer the isopack (app.js) file yourself.

Do I need to keep a copy of js library in lib or vendor folder though already installed using npm?

Question 1 :
I am installing my project dependency libraries using npm and it gets stored in the npm_modules folder. Is it necessary to keep the copy of library like angular.js,angular-route.js in lib folder or vendor folder? I could see few people are using lib folder or vendor folders to store the library in the permanent manner. I am confused by seeing this.
Question 2:
Do I need to copy/paste the node_modules folder to production or just run the npm install command on the project folder's command prompt to install all the dependencies in production. How does a dependency library get promoted to production?
Thank you kindly for your advice.
It all depends on how you need to deploy your site to production, really. Ultimately, you will probably want to bundle all your JS files into one or a few files, which are minified and sent with gzip compression.
How you bundle them is up to you. There are quite a few options:
Browserify
Webpack
Grunt / gulp build process
And many more besides
As to whether you need to keep a copy of these bundled javascript files under version control, well I think that boils down to 1 key question: can you run a build process (such as one of the tools using NodeJS) on the production server, or on a build server that creates a zip file or installer? If so, then you don't need to include them, just get the build server or production server to check out the latest copy from version control, npm install and then run the build process.
But if the best you could do is have the production server check files out from source control, then you would want to include the final versions of the files to use in the repository.
Keeping generated files, such as your bundled javascript files, in your source control repo should be avoided where possible. Because otherwise, every commit has to contain the changes to the source files, and the corresponding change to the generated files as well. And the latter is just noise, and has to be ignored by every developer looking at a diff/patch for a commit.

How to upload nodejs project or install nodejs and npm modules on live server

I've made a real time chat application with node and socket io and it is running well in my local machine. But its time to run it on my live windows server. I can't understand to how set it up there. Do I need to upload the files to the server or I've to install node js and npm modules in the server and then upload the files. And how I can do these? How I'll run the command prompt as we do in local machine like node chat.js ? Any help is appreciated.
Thanks in advance.
You can use a deployment client like Capistrano or you can just upload your source files then run npm install (assuming your have node installed) followed by your commands to bring up the server. I'd suggest using a framework like meteor or sails to make deployment easier. Or using a cloud solution like heroku.
You can use Jenkins for deploying your app to server. Running bash commands and setting builds are much more easier.
Keep it simple:
Download and install NodeJS, NPM (here)
You need to establish a simple way to move your files to the remote server. Since you can run your code and do the development at your local machine, I recommend you to use github for this purpose. Set up a repository and clone it at your remote server. Then, you can always push and pull your changes using git.
You need to establish a simple way to run your code at the remote server. Since you use Windows, I recommend you to create a .bat file that does all the preparations and runs your code. In the simplest case, it would contain node path\to\project\chat.js. Then, run this file using a console. If you're going to use github, you probably should include this .bat file to your repository.
Good luck!

Categories

Resources