Pages

Saturday, 4 December 2021

Git

 

git remote -v # get remote details


Git edit author of last commit

git commit --amend --author="Kiran Menon <kiran@domain.org>"


From <https://www.git-tower.com/learn/git/faq/change-author-name-email/> 


Remove untracked files

 git clean -fd


Adding change to an old commit 

git commit --fixup <commit-id> //the change to make

git rebase -i --autosquash <position/commit-id> //old commit where to make the change eg: HEAD~4

Maven

 Basic commands

mvn compile     # compile the project
mvn deploy     # validate--> compile--> test--> package -->verify --> install -->deploy

mvn clean package  -Dmaven.test.skip=true # clean the build files and do package but skip test file compilation


Run integration test

mvn failsafe:integration-test

Skip Nexus deploy plugin

You can use the Nexus Staging Plugin's property skipNexusStagingDeployMojo to achieve this:

mvn clean package deploy:deploy -DskipNexusStagingDeployMojo=true 
-DaltDeploymentRepository=snapshots::default::https://my.nexus.host/content/repositories/snapshots-local

It is important to explicitly invoke package and then deploy:deploy, as otherwise (when only invoking mvn deploy) the default execution of the maven-deploy-plugin is suppressed by the Nexus Staging Plugin (even with the skip set to true).


fail at end


-fae,--fail-at-end Only fail the build afterwards; allow all non-impacted builds to continue
-fn,--fail-never NEVER fail the build, regardless of project result


Create src archive explicitly

org.apache.maven.plugins:maven-source-plugin:3.2.0:jar




Maven deploy locally

mvn deploy -DaltDeploymentRepository=local::file:./target/staging-deploy






Kubectl

Create docker credentials as K8s secret

 kubectl create secret docker-registry secretname --docker-server=my.docker-registry.com --docker-username='my-username' --docker-password='mypassword' --docker-email='myemail@domain.com' -n mynamespace



Scale a deployment

kubectl -n my-ns scale --replicas 0 deployment my-deployment

kubectl -n my-ns scale --replicas 1 deployment my-deployment


Dependency check pom plugin

A mvn plugin to generate a report on dependencies:

mvn   site:stage  -DskipTests=true

https://maven.apache.org/plugins/maven-site-plugin/



Pom.xml


<distributionManagement>

<site>

      <id>mojo.website</id>

      <name>Mojo Website</name>

      <url>scp://localhost/scratch/kpokkana/workdir/simple-http-server-py/index-root/kpokkana/target2/</url>

    </site>

</distributionManagement>



<build>

        <plugins>

        <plugin>

        <groupId>org.owasp</groupId>

        <artifactId>dependency-check-maven</artifactId>

        <version>6.0.2</version>

        <executions>

        <execution>

        <goals>

        <goal>check</goal>

        </goals>

        </execution>

        </executions>

        </plugin>


<plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-site-plugin</artifactId>

    <version>3.7.1</version>

 </plugin>


        </plugins>

        </build>


Docker

Basic commands

$ docker login -u username -p mypassword this-is-my-docker-registry.com # Log in to a docker repo

$ docker images # list images

$ docker ps # list all running docker containers

$ docker ps -a # list all containers, including stopped.

$ docker rmi image-name #remove an image

$ docker pull image:tag #pulls an image 

$ docker build -t image:tag --build-arg arg1=value --build-arg arg2=value -f myDockerFile.alpine context-dir/ #build image from DockerFile

$ docker save -o image.tar image:tag  # save the image as a tar file

$ docker load -i /image-tar-file.tar.gz # loads the image from tar file

docker ps --size # get size of container

$ docker system prune $ prune dangling images/containers

$ docker image prune -a $ pruner all dangling images

$ docker system df #The docker system df command displays information regarding the amount of disk space used by the docker daemon.


Change docker root dir

vi /etc/docker/daemon.json

From <https://stackoverflow.com/questions/32070113/how-do-i-change-the-default-docker-container-location/50726177> 
 
{
  "data-root":"/scratch1/docker"
}

Kafka: listing consumer groups

List  the consumer groups:

#kubectl -n kafka exec -ti my-cluster-kafka-0 -- bin/kafka-consumer-groups.sh --bootstrap-server my-cluster-kafka-bootstrap.kafka:9092 --list


Delete a consumer group:

Bring down dispatcher and controller, if any.

#kubectl -n knative-eventing scale deployment kafka-ch-dispatcher --replicas=0

#kubectl -n knative-eventing scale deployment kafka-ch-controller --replicas=0

Now remove the group by name:

 kubectl -n kafka exec -ti my-cluster-kafka-0 -- bin/kafka-consumer-groups.sh --bootstrap-server my-cluster-kafka-bootstrap.kafka:9092 --delete --group kafka.dx-test.default-kne-trigger.05719b03-3117-4633-b504-dc4020423ce0

Delete all consumer groups:

kubectl -n kafka exec -ti my-cluster-kafka-0 -- bin/kafka-consumer-groups.sh --bootstrap-server my-cluster-kafka-bootstrap.kafka:9092 --delete --all-groups

Describe a consumer group:

#kubectl -n kafka exec -ti my-cluster-kafka-0 -- bin/kafka-consumer-groups.sh --bootstrap-server my-cluster-kafka-bootstrap.kafka:9092 --describe --group kafka.dx-test.default-kne-trigger.3a796074-afb6-4862-a5f3-0db6c76b41d0


#xargs -0 -n 1 kubectl -n kafka exec -ti my-cluster-kafka-0 -- bin/kafka-consumer-groups.sh --bootstrap-server my-cluster-kafka-bootstrap.kafka:9092 --describe --group < <(tr \\n \\0 <consumer-grps-dangling-2.txt)



Find the ISTIO Ingress port and Gateway URL

export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')

export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}')

export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT

echo $GATEWAY_URL


HTTP proxy

In our work place, the internet traffic is accessible only via the org's HTTP proxy.

To set the proxy env var in a Linux VM use the eg:


export http_proxy=http://www-our-proxy.company.com:80

export HTTPS_PROXY=$http_proxy

export HTTP_PROXY=$http_proxy

export https_proxy=$http_proxy

export NO_PROXY=.us.domain1.com,.companyvcn.com,localhost,.companycorp.com


Here it is an HTTP proxy. So to establish an HTTPS connection also its using the HTTP proxy here.

Whenever an HTTPS connection is requested to the HTTP proxy by the user, the proxy creates a TCP tunnel between the destination and the user host. And thus the user make the HTTPS calls via this TCP tunnel.



Gradle

Gradle commands

you could specify a single test with: 

gradle clean test --tests "org.gradle.MyFirstTest.testA"

Or all tests in a class: 
gradle clean test --tests "org.gradle.MyFirstTest" 

Or all tests in a package: 

gradle clean test --tests "org.gradle.*"

Golang dep

sample commands


install : #curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
#dep init
#dep ensure -add github.com/foo/bar github.com/baz/quux
#dep status
#dep ensure
#dep ensure -update github.com/foo/bar
#dep check

Markdown syntax

Text   

It's very easy to make some words **bold** and other words *italic* with Markdown. You can even [link to Google!](http://google.com)
It's very easy to make some words bold and other words italic with Markdown. You can even link to Google!

Syntax guide

Here’s an overview of Markdown syntax.

Headers

# This is an <h1> tag
## This is an <h2> tag
###### This is an <h6> tag

Emphasis

*This text will be italic*
_This will also be italic_

**This text will be bold**
__This will also be bold__

_You **can** combine them_

Lists

Unordered

* Item 1
* Item 2
  * Item 2a
  * Item 2b

Ordered

1. Item 1
1. Item 2
1. Item 3
   1. Item 3a
   1. Item 3b

Images

![GitHub Logo](/images/logo.png)
Format: ![Alt Text](url)

Links

http://github.com - automatic!
[GitHub](http://github.com)

Blockquotes

As Kanye West said:

> We're living the future so
> the present is our past.

Inline code

I think you should use an
`<addr>` element here instead.

GitHub Flavored Markdown

GitHub.com uses its own version of the Markdown syntax that provides an additional set of useful features, many of which make it easier to work with content on GitHub.com.
Note that some features of GitHub Flavored Markdown are only available in the descriptions and comments of Issues and Pull Requests. These include @mentions as well as references to SHA-1 hashes, Issues, and Pull Requests. Task Lists are also available in Gist comments and in Gist Markdown files.

Syntax highlighting

Here’s an example of how you can use syntax highlighting with GitHub Flavored Markdown:
```javascript
function fancyAlert(arg) {
  if(arg) {
    $.facebox({div:'#foo'})
  }
}
```
You can also simply indent your code by four spaces:
    function fancyAlert(arg) {
      if(arg) {
        $.facebox({div:'#foo'})
      }
    }
Here’s an example of Python code without syntax highlighting:
def foo():
    if not bar:
        return True

Task Lists

- [x] @mentions, #refs, [links](), **formatting**, and <del>tags</del> supported
- [x] list syntax required (any unordered or ordered list supported)
- [x] this is a complete item
- [ ] this is an incomplete item
If you include a task list in the first comment of an Issue, you will get a handy progress indicator in your issue list. It also works in Pull Requests!

Tables

You can create tables by assembling a list of words and dividing them with hyphens - (for the first row), and then separating each column with a pipe |:
First Header | Second Header
------------ | -------------
Content from cell 1 | Content from cell 2
Content in the first column | Content in the second column
Would become:
First HeaderSecond Header
Content from cell 1Content from cell 2
Content in the first columnContent in the second column 

Declarative Jenkinsfile

Some snippets:

steps:

------

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'echo "Hello World"'
                sh '''
                    echo "Multiline shell steps"
                    ls –lah
                '''
            }
        }
    }
}

timeouts:

----------

pipeline {
    agent any
    stages {
        stage('Deploy') {
            steps {
                timeout(time: 3, unit: 'MINUTES') {
                    retry(5) {
                        powershell '.\flakey-deploy.ps1'
                    }
                }
            }
        }
    }
}

stages:

-------
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Building'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying'
            }
        }
    }
}

when

-----
pipeline {
    agent any
        stages {
            stage('Build') {
                when {
                    expression {
                        "foo" == "bar"
                    }
                }
                steps {
                    echo 'Building'
                }
            }
        stage('Test') {
            when {
                environment name: 'JOB_NAME', value: 'foo'
            }
            steps {
                echo 'Testing'
            }
        }
        stage('Deploy') {
            when {
                branch 'master'
            }
            steps {
                echo 'Deploying'
            }
        }
    }
}

when allOf:

----------
pipeline {
    agent any
    stages {
        stage('Build') {
            when {
                allOf {
                    not { branch 'master' }
                    environment name: 'JOB_NAME', value: 'Foo'
                }
            }
            steps {
                echo 'Building'
            }
        }
    }
}


parallel stages:

------------------
pipeline {
    agent any
    stages {
        stage('Browser Tests') {
            parallel {
                stage('Chrome') {
                    steps {
                        echo "Chrome Tests"
                    }
                }
                stage('Firefox') {
                    steps {
                        echo "Firefox Tests"
                    }
                }
            }
        }
    }
}

Docker

--------
pipeline {
    agent {
        docker {
            label 'docker'
            image 'maven:3.5.0-jdk-8'
        }
    }
}

One of the advantages of using containers is creating an immutable environment that defines only the tools required in a consistent manner.
Rather than creating one large image with every tool needed by the Pipeline, it is possible to use different containers in each stage and
reuse the workspace, keeping all of your files in one place.

pipeline {
    agent {
        node { label 'my-docker' }
    }
    stages {
        stage("Build") {
            agent {
                docker {
                reuseNode true
                image 'maven:3.5.0-jdk-8'
                }
            }
            steps {
                sh 'mvn install'
            }
        }
    }
}


Envs:

-----
pipeline {
    agent any
    environment {
        DISABLE_AUTH = 'true'
        DB_ENGINE        = 'sqlite'
    }
    stages {
        stage('Build') {
            steps {
                sh 'printenv’
            }
        }
    }
}

Credentials envs:

------------------
environment {
    AWS_ACCESS = credentials('AWS_ KEY')
    AWS_SECRET = credentials('AWS_SECRET')
}

post-actions:

------------
pipeline {
    agent any
    stages {
        stage('No-op') {
            steps {
                sh 'ls'
            }
        }
    }
    post {
        always {
            echo 'I have finished'
            deleteDir() // clean up workspace
        }
        success {
            echo 'I succeeded!'
        }
        unstable {
            echo 'I am unstable :/'
        }
        failure {
            echo 'I failed :('
        }
        changed {
            echo 'Things are different...'
        }
    }
}

Notify post actions:

-----------------
post {
    failure {
        mail to: 'team@example.com',
            subject: 'Failed Pipeline',
            body: "Something is wrong"
    }
}

slack:

------
post {
    success {
        slackSend channel:'#ops-room',
            color: 'good',
            message: 'Completed successfully.'
    }
}

Python

setups and commands


pipenv


pip install --user pipenv
python -m site --user-base //add 'bin' to that and append to PATH.
pipenv install <module-name>
pipenv shell

pip


pip freeze
pip list

venv

python -mvenv  myvenv
source myvenv/bin/activate  # Activate the venv
deactivate # Command to deactivate the venv


Vim

To comment out blocks in vim:

Press Esc (to leave editing or other modes)
hit ctrl + v (visual block mode)
use the up/down arrow keys to select lines you want (it won't highlight everything)
Shift + i (capital I)
insert the text you want, i.e. %
press Esc Esc.