The following is a collection of my favorite Puppet, Docker, Git, and npm commands and code snippets.
Puppet
############################################################################### | |
# Helpful Puppet commands and code snippets | |
############################################################################### | |
sudo puppet module list # different paths w/ or w/o sudo | |
puppet config print | |
puppet config print | grep <search_term> | |
sudo cat /etc/puppet/puppet.conf | grep <search_term> | |
sudo vi /etc/puppet/puppet.conf | |
sudo puppet module install <author>/<module_name> | |
sudo puppet module install <author>-<module_name>-<version>.tar.gz # Geppetto Export Module to File System | |
sudo puppet module install -i /etc/puppet/environments/production/modules <author>/<module_name> | |
sudo puppet module uninstall <module_name> | |
sudo rm -rf /etc/puppet/environments/production/module/<module_name> # use remove vs. uninstall when in env. path | |
sudo puppet apply <manifest>.pp | |
# Install Modules from GitHub onto Foreman node: | |
# Apache Config Example | |
wget -N https://github.com/garystafford/garystafford-apache_example_config/archive/v0.1.0.tar.gz && \ | |
sudo puppet module install -i /etc/puppet/environments/production/modules ~/v0.1.0.tar.gz --force | |
# HAProxy Config Example | |
wget -N https://github.com/garystafford/garystafford-haproxy_node_config/archive/v0.1.0.tar.gz && \ | |
sudo puppet module install -i /etc/puppet/environments/production/modules ~/v0.1.0.tar.gz --force |
Docker
############################################################################### | |
# Helpful Docker commands and code snippets | |
############################################################################### | |
### CONTAINERS ### | |
docker stop $(docker ps -a -q) #stop ALL containers | |
docker rm -f $(docker ps -a -q) # remove ALL containers | |
docker rm -f $(sudo docker ps --before="container_id_here" -q) # can also filter | |
# exec into container | |
docker exec -it $(docker container ls | grep '<seach_term>' | awk '{print $1}') sh | |
# exec into container on windows with Git Bash | |
winpty docker exec -it $(docker container ls | grep '<seach_term>' | awk '{print $1}') sh | |
# helps with error: 'unexpected end of JSON input' | |
docker rm -f $(docker ps -a -q) # Remove all in one command with --force | |
docker exec -i -t "container_name_here" /bin/bash # Go to container command line | |
# to exit above use 'ctrl p', 'ctrl q' (don't exit or it will be in exited state) | |
docker rm $(docker ps -q -f status=exited) # remove all exited containers | |
### IMAGES ### | |
# list images and containers | |
docker images | grep "search_term_here" | |
# remove image(s) (must remove associated containers first) | |
docker rmi -f image_id_here # remove image(s) | |
docker rmi -f $(docker images -q) # remove ALL images!!! | |
docker rmi -f $(docker images | grep "^<none>" | awk '{print $3}') # remove all <none> images | |
docker rmi -f $(docker images | grep 'search_term_here' | awk '{print $1}') # i.e. 2 days ago | |
docker rmi -f $(docker images | grep 'search_1\|search_2' | awk '{print $1}') | |
### DELETE BOTH IMAGES AND CONTAINERS ### | |
docker images && docker ps -a | |
# stop and remove containers and associated images with common grep search term | |
docker ps -a --no-trunc | grep "search_term_here" | awk "{print $1}" | xargs -r --no-run-if-empty docker stop && \ | |
docker ps -a --no-trunc | grep "search_term_here" | awk "{print $1}" | xargs -r --no-run-if-empty docker rm && \ | |
docker images --no-trunc | grep "search_term_here" | awk "{print $3}" | xargs -r --no-run-if-empty docker rmi | |
# stops only exited containers and delete only non-tagged images | |
docker ps --filter 'status=Exited' -a | xargs docker stop docker images --filter "dangling=true" -q | xargs docker rmi | |
### DELETE NETWORKS AND VOLUMES ### | |
# clean up orphaned volumes | |
docker volume rm $(docker volume ls -qf dangling=true) | |
# clean up orphaned networks | |
docker network rm $(docker network ls -q) | |
### NEW IMAGES/CONTAINERS ### | |
# create new docker container, ie. ubuntu | |
docker pull ubuntu:latest # 1x pull down image | |
docker run -i -t ubuntu /bin/bash # drops you into new container as root | |
### OTHER ### | |
# install docker first using directions for installing latest version | |
# https://docs.docker.com/installation/ubuntulinux/#ubuntu-trusty-1404-lts-64-bit | |
# other great tips: http://www.centurylinklabs.com/15-quick-docker-tips/ | |
# fix fig / docker config: https://gist.github.com/RuslanHamidullin/94d95328a7360d843e52 |
Git
############################################################################### | |
# Helpful Git/GitHub commands and code snippets | |
############################################################################### | |
#### Remove/Squash All History on Master - CAUTION! #### | |
# https://stackoverflow.com/a/26000395/580268 | |
git checkout --orphan latest_branch \ | |
&& git add -A \\ | |
&& git commit -am "Remove/squash all project history" \ | |
&& git branch -D master \ | |
&& git branch -m master \ | |
&& git push -f origin master | |
#### List all committed files being tracked by git | |
git ls-tree --full-tree -r HEAD | |
### Display remote origin ### | |
git remote --verbose | |
### Clone single branch from repo | |
git clone -b --single-branch <branch> <remote_repo> | |
### Get all branches from a repo | |
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done | |
git fetch --all | |
git pull --all | |
### Delete a single remote branch | |
git push origin --delete <branch> | |
### Change commit message ### | |
git commit --amend -m "Revised message here..." | |
git push -f # if already pushed | |
### Undo an Add File(s) | |
git reset <filename> | |
### Removing files from GitHub ### | |
# that should have been in .gitignore | |
git ls-tree -r master --name-only # list tracked files | |
git rm --cached <file> or git rm -r --cached <folder> #ie. git rm -r --cached .idea/ | |
git add -A && git commit -m "Removing cached files from GitHub" && git push | |
# works even better! | |
git rm --cached -r . && git add . | |
### Tagging repos ### | |
# http://git-scm.com/book/en/v2/Git-Basics-Tagging | |
git tag -a v0.1.0 -m "version 0.1.0" | |
git push --tags | |
git tag # list all tags | |
# Finding and tagging old commit points | |
git log --pretty=oneline # find hash of commit | |
git tag -a v0.1.0 -m 'version 0.1.0' <partial_commit_hash_here> | |
git push --tags #origin master | |
git tag # list all tags | |
git checkout tags/v0.1.0 # check out that tagged point in commit history | |
# Chaning a tag to a new commit | |
git push origin :refs/tags/<tagname> | |
git tag -fa <tagname> | |
git push origin master --tags | |
# Remove a tag both locally and remote | |
git tag -d <tagname>; # local | |
git push origin ::refs/tags/<tagname> # remote | |
### Committing changes to GitHub ### | |
git add -A # add all | |
git commit -m "my changes..." | |
git push | |
# Combined | |
git add . && git commit -am "Initial commit of project" && git push | |
### Adding an existing project to GitHub ### | |
# Create repo in GitHub first | |
git add -A # add all | |
git commit -m "Initial commit of project" | |
git remote add origin <https://github.com/username/repo.git> | |
git remote -v # verify new remote | |
git pull origin master # pull down license and .gitignore | |
# might get message like to merge manually: 'Error reading...Press Enter to continue starting nano.' | |
git push --set-upstream origin master | |
git status # check if add/commit/push required? | |
### Branching GitHub repos ### | |
# https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches | |
# Run from within local repo | |
NEW_BRANCH=<new_branch_here> | |
git checkout -b ${NEW_BRANCH} | |
git push origin ${NEW_BRANCH} | |
git branch # list branches | |
git add -A # add all | |
git commit -m "my changes..." | |
git push --set-upstream origin ${NEW_BRANCH} | |
git checkout master # switch back to master | |
# Merge in the <new_branch_here> branch to master | |
# https://www.atlassian.com/git/tutorials/using-branches/git-merge | |
git checkout master | |
git merge ${NEW_BRANCH} | |
# deletes branch!! | |
git branch -d ${NEW_BRANCH} # deletes branch!! | |
# show pretty history | |
git log --graph --oneline --all --decorate --topo-order | |
# Rollback commit | |
git log # find commit hash | |
git revert <commit_hash> |
npm
############################################################################### | |
# Helpful npm commands and code snippets | |
############################################################################### | |
# list top level packages w/o dependencies | |
npm list --depth=0 | |
npm list --depth=0 -g | |
# list top level packages that are outdated w/o dependencies | |
npm outdated | sort | |
npm outdated -g | sort | |
# install packages | |
npm install -g <pkg>@<x.x.x> | |
npm install -g <pkg>@latest | |
# update packages | |
npm update --save | |
npm update --save-dev | |
npm update -g <pkg1> <pkg2> <pkg3> | |
# Update to latest dependencies, ignore and update package.json! | |
npm install -g npm-check-updates | |
npm-check-updates | |
npm-check-updates -u | |
npm update # verify new versions work with project | |
# prune and rebuild | |
npm prune | |
npm rebuild | |
npm rebuild -g | |
# find package dependencies | |
npm ls <pkg> | |
# alternate tool to check and update dependencies | |
npm install -g david | |
david -g | |
david update -g | |
bower list | sort | |
bower update | |
bower prune # uninstalls local extraneous packages | |
# lists available tasks | |
grunt --help |