Friday 27 March 2020

ember project with old version, eg,v1.12


How to create a ember version specific project?

https://stackoverflow.com/questions/38701667/how-to-create-a-ember-version-specific-project

Followed above link, but didn't work.

2nd option >> ember version didn't exist in package.json
1st option >> installed ember-cli@0.2.0 but it still was showing the current version v2.11

ember v1.12.2 >> ember-clie@0.2.0
https://github.com/emberjs/ember.js/blob/v1.12.2/package.json

inheeoh@192-168-1-107 client % sudo npm install -g ember-cli@0.2.0 
npm WARN deprecated mkdirp@0.5.4: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated esperanto@0.6.34: Esperanto is deprecated in favour of http://rollupjs.org
npm WARN deprecated natives@1.1.6: This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs@4.x.
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
/usr/local/bin/ember -> /usr/local/lib/node_modules/ember-cli/bin/ember

> ws@0.5.0 install /usr/local/lib/node_modules/ember-cli/node_modules/testem/node_modules/socket.io/node_modules/engine.io/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

sh: builderror.log: Permission denied

> ws@0.4.31 install /usr/local/lib/node_modules/ember-cli/node_modules/testem/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

sh: builderror.log: Permission denied
npm WARN ember-cli@0.2.0 had bundled packages that do not match the required version(s). They have been replaced with non-bundled versions.

+ ember-cli@0.2.0
added 919 packages from 571 contributors in 58.175s

ember -v
ember-cli: 2.11.1
node: 13.5.0
os: darwin x64


I just decided to keep the current ember version, v3.15, that was installed.

Just copied the ember project ...
from: /Users/inheeoh/work/sydney-camera-repair
to: /Users/inheeoh/aws/aws-serverless-ember/client

and deploy the serverless ember version.







Thursday 26 March 2020

AWS ClouldFormation tutorials


CloudFormation Tutorial (Word press)


YOu may have this error after AWS CloudFormation tutorial.
Your server is running PHP version 5.4.16 but WordPress 5.2 requires at least 5.6.20

SSH to your output server.
ssh -i ./keypair/Amazon_linux2_ami_keypair.pem ec2-user@the url shown in the output

Install below to resolve issue.
https://acloud.guru/forums/aws-csa-2019/discussion/-LeK7R4pgAYrlyM71CZU/yourserverisrunningphp_ver

The given url shows
http://ec2-18-138-227-120.ap-southeast-1.compute.amazonaws.com/wordpress/
>> Not found

http://ec2-18-138-227-120.ap-southeast-1.compute.amazonaws.com/index.php
>> Installation page
>> go on

admin:
http://ec2-18-138-227-120.ap-southeast-1.compute.amazonaws.com/wp-admin/

home:
http://ec2-18-138-227-120.ap-southeast-1.compute.amazonaws.com/

Pipeline by ClouldFormation


https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codepipeline-pipeline.html

The overall deployment failed because too many individual instances failed deployment, too few healthy instances are available for deployment, or some instances in your deployment group are experiencing problems.

The deployment failed because a specified file already exists at this location: /var/www/html/index.html

At one stage, deploy by cloud formation didn't work. I had to create a manual pipeline using the same resource to test whether the problem is from resource itself or from cloudformation. It was from resouce itself. Then the two pipeline conflcted each other and made below error.



Pipeline by ClouldFormation (tutorial)

https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-cloudformation.html
You can get sample pipleline yaml file from above or here.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codepipeline-pipeline.html

Codepipeline + Beanstalk + Cloudformation

https://www.valuebound.com/resources/blog/build-your-cicd-pipeline-aws-elasticbeanstack-codepipeline-and-cloudformation

Create role by ClouldFormation



 
 4 users

 2 groups


 18 roles
 
xx customer managed policies
 

Created role by cloud formation given from here:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html




 19 roles


 It shows the new role created but never used.




AWS Terms

1Kings 18:44 The seventh time the servant reported, “A cloud as small as a man’s hand is rising from the sea.”


role - defines what you can do / cannot do. may have policy
An IAM role is an IAM identity that you can create in your account that has specific permissions

service role -  same as role. when role is doing something, you call it service role
service role is a role that an AWS service assumes to perform actions on your behalf

policy - a set of permissions
policy is an entity that, when attached to an identity or resource, defines their permissions. 




CloudFormation tutorial for Beanstalk+Pipeline

https://www.valuebound.com/resources/blog/build-your-cicd-pipeline-aws-elasticbeanstack-codepipeline-and-cloudformation

  • How did the author do this?
  • Our template will create a required IAM role for the code pipeline project.
  • stage1
  • Here, we have configured the pipeline to pull the specified repository name and branch.
  • stage2
  • The project manager can approve the changes to be deployed in the environment or deny the changes. We use SNS for sending a notification to the subscribers to approve the changes.
  • stage3
  • During the deploy stage, the code is deployed in all the application environments.

CloudFormation >> pipeline >> beanstalk


https://stackoverflow.com/questions/33038941/elastic-beanstalk-iam-developer-permissions


CloudFormation further restrictions.

Read from specific s3 buckets only by adding:
  • firstline: source bucket
  • 2nd line: pipeline artifact store bucket
  • 3rd line: elasticbeanstalk bucket holding deployed application
- Action:
- 's3:Get*'
Effect: Allow
Resource: [ 'arn:aws:s3:::sample-abc-bucket', 'arn:aws:s3:::sample-abc-bucket/*',
'arn:aws:s3:::abc-ap-southeast-1', 'arn:aws:s3:::abc-ap-southeast-1/*',
'arn:aws:s3:::elasticbeanstalk-*', 'arn:aws:s3:::elasticbeanstalk-*/*',
]

Access specific beanstalks only by adding:

- Action:
- 'elasticbeanstalk:*'
Effect: Allow
Resource: '*'
Condition:
StringEquals:
'elasticbeanstalk:InApplication': [ !Sub 'arn:aws:elasticbeanstalk:ap-southeast-1:${AWS::AccountId}:application/YOur Application Name' ]

Further reading
https://aws.amazon.com/blogs/devops/using-aws-codepipeline-to-perform-multi-region-deployments/

https://aws.amazon.com/blogs/devops/use-aws-cloudformation-to-automate-the-creation-of-an-s3-bucket-with-cross-region-replication-enabled/

https://github.com/symphoniacloud/multi-region-codepipeline

https://www.valuebound.com/resources/blog/build-your-cicd-pipeline-aws-elasticbeanstack-codepipeline-and-cloudformation

CloudFormation + shell script


https://github.com/symphoniacloud/multi-region-codepipeline/tree/master/deployment-pipeline

Wednesday 18 March 2020

Working from home

Ubuntu bootable disk on Mac

I had a few issues with my macbook pro (13 inch, Mac Catalina, 10.15.3, T2 chip)

1. booting is really hard
I had to remove all other USBs except the bootable disk to boot.
I had to go to recovery mode a few times to keep the setting (the lowest security + allow remote usb boot device).

1. Disconnect all usb except booting disc
2. Apple logo
3. Ubunt Purple screen with 3 menu
4. Black error screen (0000:06: HC died: cleaning up. ICM firmware is in wrong mode: 15)

2.3.4 repeats

5. Remove boot USB and put it into another port
2.3.4 repeats >> successful black screen

6. Ubuntu screen asking decrypt password.
7. Plug in all other usbs (Wireless dongle, Keyboard/mouse dongle)
8. LOgin




2. External monitor (connected with HDMI cable) resolution does not match with mac book monitor.
When I set external monitor correctly, mac screen becomes too small.

Goldstar Comapny Ltd 22"
Resolution: 1920*1080(16:10)
Scale: 100%

Built-in display:
Resolution: 2560x1600(16:10)
Scal: 100%


3. Sound not working
Ubuntu setting >> SOund >> output volume was disabled.

After following, below site, it was enabled but still not working.
https://www.unixmen.com/2012003-howto-resolve-nosound-problem-on-ubuntu/

Sound was actually going to HDMI. I connected with my TV and I could hear the sound.
Headset does not work either as the sound goes to HDMI.

The current sound setting shows:
Output volume: enabled
Out device: HDMI/DisplayPort-BUilt-in AUdio
Profile: Digital Stereo (HDMI) output.

Software installation
sudo mysql command didn't work at one stage. Had to reinstall mysql-server following site below.

https://stackoverflow.com/questions/43440534/mysql-doesnt-start-at-all

Github - keeps aksing my id/pass

$ git fetch
Username for 'https://github.com': ^C


1. ssh key generate
https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
(I found that the newly created id_rsa/id_rsa.pub have to sit on ~/.ssh folder. So if you have existing id_rsa/id_rsa.pub for other github site, backup them in a subfolder, eg, ~/.ssh/my_other_github)

2. $ cat .git/config

3. You need to replace the url part.

4. Go to git hub url >> green clone button >> USH ssh
copy the url, something like git@xxxxx.git

5. $ vim .git/config >> update the url part

6. Now, you need to paste the created id_rsa.pub to github.
Go to git hub >> Your profile photo >> Settings >> SSH and GPA Key >> add >> copy the id_rsa.pub part (cat .ssh/id_rsa.pub) and paste.

7. $ git fetch
$ git pull

First time, it asks the password you used in step1 if you entered passphrase (btw, this is not github site password).


Then NO password asking!!!


How to connect to a specific repo

1. go to github >> settings >> Developer settings >> Persona access token >> Gnerate new. >> tick 'repo' and 'gist' >> Ok >> copy this token on notepad temporarily.

NOte that 'token' is per device, and per github credential

2. open PhpStorm >> file >> settings >> Github >> Use token (not credential) >> paste the token you created from github website. >> Apply >> ok.

3. Phpstorm >> VCS >> Get from version control >> Github >> search for 'scripts' >> the menu will emerge >> Clone button.


Now, it is cloned.




Monday 16 March 2020

Ember table css

Ember styling follows below rule.

https://cli.emberjs.com/release/advanced-use/stylesheets/

2. You need below line essentially.

let app = new EmberApp(defaults, {
    minifyCSS: {
      options: { processImport: true }
    }
  });

3. add all you custom css into styles >> app.css

4. create a file in styles >> app.scss

5. add ember table css in there.

@import '@addepar/style-toolbox';
@import '@addepar/style-toolbox/onyx/elements/inputs/button/index';

6. edit ember-cli-build.js as below following the website.

https://github.com/Addepar/addepar-style-toolbox

let app = new EmberApp(defaults, {
// Add options here
sassOptions: {
extension: 'scss'
},
minifyCSS: {
options: { processImport: true }
}
});

Note that public >> assets >> sydney-camera-repair.css should not exist.
All css will be combined (compiled) into dist >> assets >> sydney-camera-repair.css

You will see the css applied ember table!!!



Sunday 15 March 2020

Git commands

what is the best way to connect local folder to existing github repo?

 https://stackoverflow.com/questions/50025872/how-do-i-connect-a-local-folder-to-an-existing-github-repo

# Initialize the local directory as a Git repository.
git init

# Add files
git add .

# Commit your changes
git commit -m "First commit"

# Add remote origin
git remote add origin remote repository URL
# Remote URL look like this https://github.com/user/repo.git

# Verifies the new remote URL
git remote -v

# Push your changes
git push origin master

 

 Create github repository


1. rm -rf .git

2. create a git repository on website.

3.
echo "# SydneyCameraRepair" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin 
git push -u origin master

To use Github destkop


Git commands

change branch (will show error if branch does not exist)
git checkout CE-1234

current branch name
 git branch | grep \*

Find all branch like CE-1234
git branch | grep CE-1234


check who is my origin
git remote -v

remote git commands?
Git remote …
https://help.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line

who am I?
git config –list


history
git log

git log with file changes
git log --name-only

Revert to previous code
git log
git log –oneline
git checkout 27d2991486a742a16bc2d317b6d29d96a02b210c
git checkout -b CE-1234-kkk

//delete a remote commit 
https://ncona.com/2011/07/how-to-delete-a-commit-in-git-local-and-remote/
git reset --hard  44780335d2c5790917e5908cbdd18b283b650e41
git push origin +CE-1234


quit?
q

//----------------------
Git Frequent
//----------------------

//rename local branch
git branch -m <new_name>
//delete local branch
git branch -d master

//get remote master
git checkout --track origin/master

//create local branch
git branch CE-1234
git checkout CE-1234 or ...
git checkout -b CE-1234

//create local branch from the remote master branch
git checkout -b CE-1234 origin/master

//git push local
git commit -a -m "first commit"

//git push remote
git push -u origin CE-1234


git stash
git stash pop
git stash clear

//Discard all local changes to all files permanently:
git reset –hard
or 
git stash

git reset vs revert
https://stackoverflow.com/questions/8358035/whats-the-difference-between-git-revert-checkout-and-reset

https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting

https://stackoverflow.com/questions/22620393/various-ways-to-remove-local-git-changes

https://docs.gitlab.com/ee/topics/git/numerous_undo_possibilities_in_git/

git fetch
get pull

Saturday 14 March 2020

The very first ember table

The very easy ember table didn't show.

https://opensource.addepar.com/ember-table/docs/quickstart

Make sure after installing ember-table, restart the ember server
ember s


Then it shows.


work-order-table.hbs
{{this.isLarge}}
{{columns.firstObject.name}}


<EmberTable as |t|>
<t.head @columns={{columns}} />
<t.body @rows={{rows}} />
</EmberTable>



work-order-table.js
import Component from '@glimmer/component';

export default class WorkOrderTableComponent extends Component {
constructor(...args) {
super(...args);
this.isLarge = true;

this.columns = [
{
name: `First Name`,
valuePath: `firstName`
},
{
name: `Last Name`,
valuePath: `lastName`
}
];
this.rows = [
{
firstName: 'Tony',
lastName: 'Stark',
},
{
firstName: 'Tom',
lastName: 'Dale',
}
];
}
}






Ember data read from json file

Search for 'json file' from Ember tutorial page



It talks about putting json file public >> api >> workorder.json
Main route file, workorder.js file will read the json file as below.


export default class WorkordersRoute extends Route {

async model() {
let response = await fetch('/api/workorders.json');
let parsed = await response.json();
console.log("parsed", parsed);
return parsed;

}
}

You can add css into public >> assets >> scr.css
and include it from index.html file.

<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/sydney-camera-repair.css">


API working, route is working. good



{{#each @model as |wo|}}
<span class="mybold">{{wo.id}}</span>
<WorkOrderListing @workorder={{wo}} />
{{/each}}



Create Workorders api on Lumen



1. Create controller
Http >> Controllers >> WorkOrderController.php

2. Create Model

WorkOrder.php
Make sure class name is WorkOrder not Author.

3. Add routes
routes >> web.php
$router->get('workorders', ['uses' => 'WorkOrderController@showAllWorkOrders']);
$router->get('workorders/{id}', ['uses' => 'WorkOrderController@showOneWorkOrder']);
$router->post('workorders', ['uses' => 'WorkOrderController@create']);
$router->delete('workorders/{id}', ['uses' => 'WorkOrderController@delete']);
$router->put('workorders/{id}', ['uses' => 'WorkOrderController@update']);



4. Make sure your database (matthew_schema according to .env file) has 'work_orders' table. If model name is WorkOrder, system looks for work_orders. If model name is Author it looks for authors table.


5. Copy 1200 rows from browser to ember project /api/json file.
/Users/inheeoh/work/sydney-camera-repair/public/api/workorders.json

6. Ember routes will filter only this year's tasks.


7. it shows on website.







Tuesday 10 March 2020

Let's install Lumen on LAMP in AWS

I had an error while running the first lumen command.
ubuntu@ip-172-31-26-11:~$ composer create-project --prefer-dist laravel/lumen authors


Problem 1
    - phpunit/phpunit 8.5.x-dev requires ext-dom * -> the requested PHP extension dom is missing from your system.

resolution:
https://stackoverflow.com/questions/43408604/php7-install-ext-dom-issue

In above link, both below commands failed and takes long.
composer update
composer require cviebrock/eloquent-sluggable

For above memory exception, below link has a solution.

https://github.com/geerlingguy/drupal-vm/issues/547


sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Above seems working. Failed to download....Now trying to download from source ...INstalling... continue.

composer update is finished.
Below takes forever. have a coffee.
composer require cviebrock/eloquent-sluggable
I also had bunch of below error. which could be resolved by below url. I think I should have installed these first.
https://stackoverflow.com/questions/41274829/php-error-the-zip-extension-and-unzip-command-are-both-missing-skipping
The zip extension and unzip command are both missing,
NOw, let's create the lumen project again.
composer create-project --prefer-dist laravel/lumen authors
Beautiful, project created on LAMP! It was not working on XAMPP.
Before running sql part, migration, you have to 
(1) create schema manually by running mysql
(2) edit .env with root userid/password
Deploy
This url saved me!
https://laracasts.com/discuss/channels/lumen/how-to-deploy-lumen-on-web-hosting
and this looks helpful as well.
https://stackoverflow.com/questions/55629307/how-to-deploy-lumen-framework-on-shared-hosting-subdomain
lumen deploy The requested URL was not found on this server.'
The error fixed by below
https://stackoverflow.com/questions/28242495/laravel-the-requested-url-was-not-found-on-this-server

ubuntu@ip-172-31-26-11:/etc/apache2/mods-enabled$ sudo vim /etc/apache2/apache2.conf 
ubuntu@ip-172-31-26-11:/etc/apache2/mods-enabled$ sudo systemctl restart apache2

Following the godaddy url, my lumen api structure look as below.