Useful Commands - bcgov/common-service-showcase GitHub Wiki

Useful Commands

This page will list useful commands that are not frequently used.

Git

Generic Rebase Instructions

git fetch --all;git remote prune $(git remote)
git add .
git stash
git rebase bcgov/master
# follow rebase instructions in case of conflicts
git stash pop

If your current "working" branch is only on local machine, you're done and can proceed. If your fork already has some WIP changes and previous commits, you need to force push.

git push <yourforkremotename> <yourbranchname> --force

Double check this is exactly what you want to do before you force anything!!

Checking your Git Lineage

If you rebased correctly, you can run the following command to see the commit topology:

git log --pretty=oneline --graph --date=short

You should ideally see bcgov/master and then a string of your own branch contents in a line above that point.

Openshift

get into pod's container

oc exec -ti -n <namespace id eg: abcdef-dev> <pod name> <container_name> -- sh

copy file from pod to local

ref: stackoverflow

oc cp <namespace_name>/<pod_name>:<remote_file_path> <local_file_path> -c <container_name>

Copy FROM local machine to pod

oc cp <local_file_path> <namespace_name>/<pod_name>:<remote_file_path> -c <container_name>

List all pods you have access to, which node they are on, and group them by namespace

oc projects -q | xargs -I {} sh -c 'echo -e "\n{}:" && oc get -n {} pod -o wide 2>/dev/null | grep Running' | awk '{print $1","$7}' | column -t -s ,

Remove all pull request image stream tags from a namespace

export $NAMESPACE=<NAMESPACE>

oc get imagestreamtag -n $NAMESPACE -o name | grep ':pr-' | sort | sed 's|imagestreamtag.image.openshift.io/||' | xargs oc tag -n $NAMESPACE -d

Generate a Github Actions Service Account

export NAMESPACE=<YOURNAMESPACE>

# Create and bind roles to service account
oc create -n $NAMESPACE sa github-actions
oc policy -n $NAMESPACE add-role-to-user admin -z github-actions
oc policy -n $NAMESPACE add-role-to-user edit -z github-actions

# Get secret token (put this into OPENSHIFT_TOKEN environment secret)
oc get -n $NAMESPACE secret $(oc get -n $NAMESPACE sa github-actions -o json | jq '.secrets[].name | select(test(.|"token"))' -r) -o json | jq '.data.token' -r | base64 -di

Grant Openshift Access to DockerHub

oc create -n $NAMESPACE secret docker-registry dockerhub-registry --docker-server=docker.io --docker-username=bcgovcommonservices --docker-password=REDACTED [email protected]

oc -n $NAMESPACE secrets link default dockerhub-registry --for=pull
oc -n $NAMESPACE secrets link builder dockerhub-registry

Grant Openshift Access to Artifactory

oc create -n $NAMESPACE secret docker-registry artifactory-registry --docker-server=artifacts.developer.gov.bc.ca --docker-username=default-abc123-xyz456 --docker-password=REDACTED --docker-email=default-abc123-xyz456@$NAMESPACE.local

oc -n $NAMESPACE secrets link default artifactory-registry --for=pull
oc -n $NAMESPACE secrets link builder artifactory-registry

Force a pod container to reset

oc exec -n $NAMESPACE -it ches-app-master-61-9fkv8 -c app -- /bin/sh -c "kill 1"

For each namespace, creates empty file .yaml, writes all the secrets in there and outputs to current local directory.

oc projects -q | xargs -i sh -c 'type NUL > {}.yaml; oc get -n {} secrets -o yaml > {}.yaml'

For each namespace, give user a role (where is 'admin','edit' or 'view' and user is azure email address.

oc projects -q | xargs -i sh -c 'echo -e "\n{}:" && oc adm policy add-role-to-user <role> <user> -n {}'

For each namespace, give remove role from a user

oc projects -q | xargs -i sh -c 'echo -e "\n{}:" && oc adm policy remove-role-from-user <role> <user> -n {}'

For more details see: https://docs.developer.gov.bc.ca/grant-user-access-openshift/

Patroni

Reinitializes Patroni cluster node (interactive)

patronictl reinit

List all Postgres database files in order of size

du -ah /home/postgres/pgdata/ | grep -v "/$" | sort -rh

read patroni config

cat /home/postgres/pgdata/pgroot/data/pg_hba.conf

open postgres auth config file:

from inside a patroni pod: cat /home/postgres/pgdata/pgroot/data/pg_hba.conf

Helm

  • Add the Patroni chart repository: helm repo add <repo name> <repo url>
  • search versions in repo: helm search repo <repo name> -l
  • update repo with new versions helm repo update <repo name>
  • Install a chart: helm install -n abcdef-dev <release name> <repo name>/<chart name> --version 0.0.1
  • lists all of the releases helm list --all
  • Uninstall a release helm uninstall -n abcdef-dev <release name>

General

unzip tar file

tar -xvzf .\a.tgz -C .

⚠️ **GitHub.com Fallback** ⚠️