Adding Cache to ASP.NET MVC Bundles

Sometimes after changing styles, javascript on the application, it still got cached on the end-user browser. The solution for it is adding the version to stylesheets, javascript files with the following format ?v=[whatever the random version number]. However, in .NET MVC, if you use Bundling and Minification through BundleConfig, then you should add the following code to BundleConfig file

BundleTable.EnableOptimizations = true;

Posted by justinpham, 0 comments

Jenkins Pipeline build for NodeJs app

The common issue if you are using Jenkins on Docker image provided by DigitalOcean is the build always failed if we build the solution with NodeJs.

After I tried to install NodeJS Plugin in Jenkin and build the NodeJs App, the error came up which causes the build failed was env: ‘node’: No such file or directory.

Problem: NodeJs is not installed in Docker Jenkins, even the install NodeJs plugin on Jenkin

Solution:

SSH into Docker container Bash/Shell: docker exec -it eager_payne /bin/bash

Install NodeJs with command: apk add nodejs

Posted by justinpham, 0 comments

Access Azure Kubernetes Cluster from Azure Cli


az aks install-cli
az aks get-credentials --resource-group 'resource name' --name 'name of your cluster'
az aks browse --resource-group 'resource name' --name 'name of your cluster'

Azure Cli will browse your resource in cluster and you will be able to accessed your K8s cluster via 127.0.0.1:8001

Posted by justinpham, 0 comments

How do I perform native backups of an RDS SQL Server DB instance?

Issue
I want to perform a native backup of my Amazon Relational Database Service (Amazon RDS) SQL Server DB instance so that I can store the backup file in Amazon Simple Storage Service (Amazon S3), or use the backup file to restore an RDS instance later.
Short Description
Amazon RDS supports native backup and restore for Microsoft SQL Server databases. You can create a full backup of your on-premises database, store the file in Amazon S3, and then restore the backup file to an existing Amazon RDS DB instance running SQL Server. You can also restore this backup file to an on-premises server or to a different Amazon RDS DB instance running SQL Server.

Resolution
To set up a native backup of the SQL Server database, use the following services:

An Amazon S3 bucket to store your backup files
An AWS Identity and Access Management (IAM) role to access the bucket
The SQLSERVER_BACKUP_RESTORE option added to an option group on the DB instance
Note: Create the S3 bucket in the same region as your RDS DB instance.

Open the Amazon RDS console, and choose Option Groups in the navigation pane. Choose Create Group and type the name, description, engine, and engine version of your server. Then, choose Create.
Select the Option Group you created, and choose Add Option. Choose “SQLSERVER_BACKUP_RESTORE”. We recommend creating a new IAM role and choosing Add Option, so that your IAM role has the required privileges. Choose your S3 bucket, or create a new S3 bucket. Then, choose Apply Immediately and Add Option.
Associate the option group with the RDS instance by choosing Instances in the navigation pane, and then choose the instance to back up. For Instance Actions, choose Modify.
Under Database Options, choose the Option Group that you created, and choose Apply Immediately and Continue. Review the information, and then choose Modify DB Instance. This Option Group modification has no downtime because instance reboot is not required.
When the status has changed from modifying to available, connect to the RDS instance through SQL Server Management Studio, and then choose New Query. Enter one of the following SQL statements to initiate the backup of the desired database:
Initiate backup for unencrypted databases
exec msdb.dbo.rds_backup_database
@source_db_name='database_name', @s3_arn_to_backup_to='arn:aws:s3:::bucket_name/file_name_and_extension',
@overwrite_S3_backup_file=1;

Initiate backup for encrypted databases
exec msdb.dbo.rds_backup_database
@source_db_name='database_name',
@s3_arn_to_backup_to='arn:aws:s3:::bucket_name/file_name_and_extension', @kms_master_key_arn='arn:aws:kms:region:
account-id:key/key-id',
@overwrite_S3_backup_file=1;
Note: Replace database_name, bucket_name, file_name_and_extension, region, account-id, and key-id listed in these examples to match your scenario. The backup file, generated in the S3 bucket, can be used later to restore to a new RDS DB instance. When the rds_backup_database/rds_restore_database stored procedure is called, the task starts and outputs the information about the task.

When the lifecycle of the task is SUCCESS, the task is complete. You can then open the Amazon S3 console, choose the bucket in which you created the backup, and view the backup file. You can download this file, or use the file to restore a new RDS instance.

Use one of the following SQL statements to restore from the backup file available in the S3 bucket:

Restore unencrypted databases

exec msdb.dbo.rds_restore_database
@restore_db_name='database_name',
@s3_arn_to_restore_from='arn:aws:s3:::bucket_name/file_name_and_extension';

Restore encrypted databases
exec msdb.dbo.rds_restore_database
@restore_db_name='database_name',
@s3_arn_to_restore_from='arn:aws:s3::: bucket_name/file_name_and_extension',
@kms_master_key_arn='arn:aws:kms:region:account-id:key/key-id';

You can get the Task ID after you perform the backup or restore statement, or you can use the following script to identify all the completed and pending tasks for a particular database:
exec msdb.dbo.rds_task_status @db_name='database_name'

To track the status of the job later, use this SQL statement:
exec msdb..rds_task_status @task_id= 5

Posted by justinpham, 0 comments

Create MongoDb User with Shell

Creating a user in MongoDB is done using createUser method.


db.createUser({
user: "Talent-Dev-App-User",
pwd: "MVp$tud1o",
roles: [{role: "readWrite", db: "Talent-Dev"}]
})

Posted by justinpham, 0 comments

How to return Promise after dispatching with Redux Thunk

It’s very common to use Promise with Redux Thunk, it sounds complicated but it simply just returns Promise.resolve(data) after dispatching to the reducers. Here is an example in the redux action to signup new user, then on Client just uses then(result) to manipulate the screen logic


export const signUpUser = user => {
return dispatch => {
return fetch(`http://840dff44.ngrok.io/identity/authentication/signup`, {
method: "post",
headers: {
"Content-Type": "application/json",
Accept: "json"
},
body: JSON.stringify(user)
})
.then(res => res.json())
.then(data => {
if (data.isSuccess) {
dispatch({
type: TOKEN_UPDATED,
payload: data.token
});
dispatch({
type: TOKEN_EXPIRED_ON,
payload: data.tokenExpiredOn
});
}
return Promise.resolve(data);
})
.catch(error => {
console.log(error);
return Promise.reject(error);
});
};
};

Posted by justinpham in .NET Core, AI, React - Redux, Solution Architecture, 0 comments

React-navigation 3 update the App container

There are some new changes with new react-navigation which is the main navigation system used in React Native app. The significant change which may affect your app is the app container. The app container is responsible for managing app state and linking the top-level navigator to the app environment.


import { createAppContainer } from 'react-navigation';
// you can also import from @react-navigation/native

const AppNavigator = createStackNavigator(...);

const AppContainer = createAppContainer(AppNavigator);

The AppContainer now becomes the main component loaded in the App.js without any wrapping view.

Posted by justinpham, 0 comments
Error: This experience uses an unsupported version of Expo. You may need to update Expo Client on your device.

Error: This experience uses an unsupported version of Expo. You may need to update Expo Client on your device.

Sometime when Expo releases new update with new features, you may have the issue of Expo Client expired when you run your app on Simulator. What you should do it restarts the simulator (Hardward > Restart), deleted Expo app on Simulator and run the application again. Next time when you run, it will install latest Expo client to the Simulator.

Posted by justinpham, 0 comments
Getting state error: undefined is not an object in a function

Getting state error: undefined is not an object in a function

There is a quite common issue with developers who just starting to use ReactJs. The junior and intermediate developers my team always have the issue undefined is not an object when they use this.state.[statement] in function. The problem is in Javascript in general, you need to pass the context of the App to use this keyword in the function. Most of the cases which cause the problem is developer don’t use the constructor way to declare the function which is this.function = this.function.bind(this)

Posted by justinpham, 0 comments