Friday, November 5, 2021

 

How to put Multiple Ingress/Egress Rules in SecurityGroup -  AWS::EC2::SecurityGroup

If you have to include multiple rules for a SecurityGroup then just add the required IpProtocol, see below example

SourceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref VpcId
GroupDescription: SG to allow SSH access via port 22, 443, 1500
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: '0.0.0.0/0'
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: '0.0.0.0/0'
- IpProtocol: tcp
FromPort: '1500'
ToPort: '1500'
CidrIp: '0.0.0.0/0'
Tags:
- Key: Name
Value: SG-SSHnADS-Ports-anyIP


If you have queries, do drop in your queries below.

...HaPpY CoDiNg
Partha 

Sunday, September 12, 2021

 GitHub - Branching - time now 


Branching makes sure the code that is being delivered is in the best state possible. This feature can be utilised for isolating the development and testing of new features from working code that is running on a production environment. New applicaiton features should be build in a brach, test and then merged.

There should be

  1. Main branch (having the production code)
  2. Development Branch (latest code from main brach for developers)
    1. Feature Brach - Create new features taking the development brach code. Conventionally, new features are to be created in feature branches from the develop branch, and, once the feature has been developed, the code can be reviewed by a peer in a Pull Request and deployed to a test environment for Integration or User Acceptance Testing.

If all testing and reviews pass, the Pull Request can be approved and merged into the develop branch.

Releases : When there is a release approaching, a release candidate branch can be made. On this new branch, further testing of all the new features working together can take place, and more candidates can be made on this branch to amend any issues. Once merged into the master branch, the code can be tagged or marked as a release on the Git service that you are using. Changes must also be merged back into the develop branch, so that any changes that were made to the release candidate will also be included in future releases.

Commands for creating and deleting Branches
git branch

To create a new branch, the command is:

# git branch [NEW_BRANCH_NAME]
git branch develop

If you want to work on a new branch straight away, you can create a branch and checkout to it at the same time:

# git checkout -b [NEW_BRANCH_NAME]
git checkout -b develop

When you have finished working on your branch, and your code has been merged to main, it is good practice to delete the branch:

# git branch -d [BRANCH_NAME]
git branch -d feature-123

You can do this during Pull Request and if you aren't closing a Pull Request but still need to close a branch, delete a branch on your remote repository (again, likely on GitHub):

# git push --delete origin [BRANCH_NAME]
git push --delete origin feature-123
The key commands are summarised below:
git branch (check branches)
git branch [name] (create a branch with the name supplied)
git checkout -b [branch name] (checkout th branch)
git branch -d [branch name] (delete the branch - after your merge or work is finished)
git push --delete origin [branch name] (while completing pull request complete the delete branch too)

If you have queries, do drop in your queries below.

...HaPpY CoDiNg
Partha 

 GitHub - Forking - time now 

In simple languate, forking is creating a copy of an existing repository under your own account. Forking a repository allows you to freely experiment with a copy of the existing code base (if public), without the fear of breaking the original code base, and all this happens in your account. Forking also gives you the ability to contribute to a project, by adding additional functionality.

The steps would be:

  1. Fork the repository - In the origin repository you get this option (right corner of the page)
  2. Create a new branch - Command 
  3. Submit a pull request to the owner of the original project - If the owner approves your fix, your work should then be merged into the original repository.

Forking Steps

Fork a remote repository, configure upstream, (to get updates from the original repository) and propose a change to the owner

  1. While you are logged into your account, go to a public repository available.
  2. Click on "Fork", in the top right of this page. This will create a copy of the repository under your account. This will copy files in your account. 
  3. Now we will clone in "local". Copy the url and  will be redirected to your account's version of the repository, run command git clone [URL]
  4. CD to your folder. Run command git remote -v to confirm that you have cloned the correct repository. The output should show fetch and push, but the URL will be pointing to your repository.

Updating forked repository from original

Now that we have the local copy of the code, we will link to the source to keep getting updates when files chanages in source.  

  1. Run command git remote -v to make sure that the upstream to the original repository is not set up yet.
  2. In your browser, go to the original git repository and copy the repository URL (the one used for cloning).
  3. Execute the following comma git remote add upstream [URL] . Next check that this has worked, execute command git remote -v and check the fetch and push
  4. Now you will pull the changes from the original repository into yours, which you can do by executing the git fetch upstream command 
  5. You will want to update the main branch, so will merge the upstream/main into the local origin/main by executing the git merge upstream/main command and then git push
    origin/main branch.
The key commands are summarised below:
git clone [url] (after you have forked on the browser - url of from your account)
git status (keep checking the status)
git remote - v (check the which remote and source fork is being referred)
git remote add upstream [url] (url of the source - this will ensure updates are received)
git fetch upstream (get updated files from upstream)
git merge upstream/mail (merg local files from upstream main branch)
git push (update the local with your remote)

If you have queries, do drop in your queries below.

...HaPpY CoDiNg
Partha 

Thursday, August 26, 2021

 More about Git & GitHub

Git is used for tracking changes in source code during software development.

Basic Flow

The basic workflow for using Git includes staging, committing and pushing changes.
Before a change can be committed it must be staged and to apply changes for everyone else, the changes must be pushed to the remote repository.

Basic Commands

Some commands that are likely to be used very often. 

Cloning a Repository (git clone)

To download a remote repository you can use the git clone command and provide the URL of the remote repository. The clone command is very useful because it configures the local repository.

# git clone [REPOSITORY_URL]
git clone https://github.com/apartha77/PSD-AWS-CNF.git

Staging a Change (git add)

Staging is the step that you must take before commiting a change. This enables to choose what changes are actually going to get committed. There is a few ways you stage files:

# stage all files
git add --all

# stage all files (only if you are at the root of your project)
git add .

# stage selected files: git add [FILES]
git add test1.txt test2.txt
git add *.txt

Username and Email in Git Config (git config)

Before you can commit changes to the repository you need to have your username and email configured. This can either be set in the scope of the repository you downloaded or set globally, to avoid repeating everytime you commit. 

Setting Config Globally

# git config --global user.name "[USERNAME]"
git config --global user.name "apartha77"
# git config --global user.email "[EMAIL]"
git config --global user.email "apartha77@email.com"

Setting Config Locally

# git config user.name "[USERNAME]"
git config user.name "apartha77"
# git config user.email "[EMAIL]"
git config user.email "apartha77@email.com"

Local Repository Status (git status)

This provides information about the current state of your local repository. It is very useful, how can you know what files have been staged and not staged?

git status

Commiting a Change (git commit)

When you make a commit to a Git repository, you are effectively “saving” the changes that you have staged to the repository. Commit with a message, which helps to identify the changes. 

# git commit -m "[COMMIT_MESSAGE]"
git commit -m "my initial commit"

Pushing Changes (git push)

To apply the changes made in a remote repository have to push them to that remote repository.
Only changes that have been committed will be pushed to the remote repository. We can use git push and provide the remote repository (default is origin) and remote branch to push our changes.

# git push -u [REMOTE] [REMOTE_BRANCH]
git push -u origin main

Retrieving Remote Changes

Because Git is a collaborative tool, other people could have made changes to code in the remote repository, these changes will need to be pulled down to avoid conflicts in the code.

# git pull [REMOTE] [REMOTE_BRANCH]
git pull origin main

Ignoring Files

Git segregates all files in your local repository into "tracked" (files which have been staged or committed), "untracked" (files which have not been staged) or "ignored" (files which will be ignored).
In order to make sure that Git does not track files which we don't wan to push, we need to create a .gitignore file in our repository. This file is a list of intentionally untracked files that Git should ignore.
We can use an asterisk "*" to specify which type of files should be ignored (an asterisk matches anything except a slash). If we use ".txt", Git will ignore all files that end in ".txt". A leading "*/" means match in all directories.
For example, if we use "**/test", Git will ignore a file or directory "venv" anywhere in our repository. If you have queries, do drop in your queries below.


**/test
*.txt
.settings/
target/
bin/
Other common commands are:

These are common Git commands used in various situations:


start a working area (see also: git help tutorial)

   clone             Clone a repository into a new directory

   init              Create an empty Git repository or reinitialize an existing one


work on the current change (see also: git help everyday)

   add               Add file contents to the index

   mv                Move or rename a file, a directory, or a symlink

   restore           Restore working tree files

   rm                Remove files from the working tree and from the index

   sparse-checkout   Initialize and modify the sparse-checkout


examine the history and state (see also: git help revisions)

   bisect            Use binary search to find the commit that introduced a bug

   diff              Show changes between commits, commit and working tree, etc

   grep              Print lines matching a pattern

   log               Show commit logs

   show              Show various types of objects

   status            Show the working tree status


grow, mark and tweak your common history

   branch            List, create, or delete branches

   commit            Record changes to the repository

   merge             Join two or more development histories together

   rebase            Reapply commits on top of another base tip

   reset             Reset current HEAD to the specified state

   switch            Switch branches

   tag               Create, list, delete or verify a tag object signed with GPG


collaborate (see also: git help workflows)

   fetch             Download objects and refs from another repository

   pull              Fetch from and integrate with another repository or a local branch

   push              Update remote refs along with associated objects



If you have queries, do drop in your queries below.

...HaPpY CoDiNg
Partha     

Saturday, June 26, 2021

How to add files in GitHub?

 This is further to my previous post. Now, you have created a repository in GitHub, but the question is how would you associate your online repository to your laptop and add files. 

We can definitely do this over the browser by uploading files, but let us see how do we do it by using command line. 


We will use the following git commands.

Step 1: We need to first install GitHub in your machine from the below url

https://git-scm.com/downloads

Step 2: Use command promt or Terminal and go to the folder where you want the repository. use the below command to clone the repository.



Before that copy the https url from github, refer to the image to find where you will get the url of your repository. 


git clone https://github.com/apartha77/PSD-AWS-CNF.git


If this first time then you will not have any file, but in the following steps we will add files from your machine. 





Step 3: Now first we will do a git pull, although we know there is no file in our repository to be downloaded locally. But wanted to cover the command here.


git pull


Step 4: Now chek status of our repository


git status 



Step 5: Now that we have created few files which we want to push/upload to github. We can use add . and then commit or we can put both in one command. We can add comments of what we are committing in this push. 


git add .


git commit -a -m "first add"


Step 6: Now chek status of our repository


git status


Step 7: You can check the files over the browser reflecting in your repository. 


If you have queries, do drop in your queries below.

...HaPpY CoDiNg
Partha 


Thursday, June 24, 2021

First Repository in GitHub - Getting Started

First Repository in GitHub - Getting Started

When I started with Git & GitHub, I faced few minor challenges. Hence, thought to create a small write up to help people like me :).

Go to https://github.com and create your account

Once you have logged in, click on the + sign to create your 1st repository. 


Give a name to your reporistory and remember to select the README File. This will allow you to write something about the repository, purspose etc. 


Now, you are good to start - creating or uploading your files, documents whatever you want manage on GitHub. 

In the next blog, I will show you how you can install GitHub in your laptop and manage files - pull, push, commit etc.



If you have queries, do drop in your queries below.
...HaPpY CoDiNg
Partha