GIT – setup a new private repo and pull,push code

This is suitable for GITLAB, but with a little modification would work with other GITs.

Install git on Ubuntu

apt-get install -y git

How to setup git

git config --global user.name "name"
git config --global user.email "email@example.com"
git remote add origin http://IP/path/to/repository

How to create new PRIVATE repo (for GITLAB)

This needs to be done via the GITLAB API.  Grab your Personal Token from GITLAB Account Settings and use this bash script.

Get it here https://gitlab.com/shallawell/git-init-remote-project.git

#!/bin/bash
# @shallawell
# Program Name: git-init-remote-project.sh
# Version = 0.0.2
# if the remote repo does not exist, use this script before you attempt to
# git push
# Can create a simple Gitlab repo
# start ===============================
#
#set vars
REPO_NAME=$1
TOKEN=YOURTOKENHERE
REMOTE_GIT=https://gitlab.com
#Public or Private repo, set to true for PUBLIC REPO
PUBLIC=true

# test var
if [ $TOKEN == YOURTOKENHERE ]; then
 echo "Error : update the git TOKEN variable."
 exit 0
fi

#usage
if [ ${#@} == 0 ]; then
 echo "Error : Repo name required."
 echo "Usage: $0 REPO_NAME"
 echo "You need to provider the repostiory/project name to create on the remote server."
 echo "Ensure $TOKEN has been set."
else
# main command
 curl -H "Content-Type:application/json" $REMOTE_GIT/api/v3/projects?private_token=$TOKEN -d \
 "{ \"name\": \"$REPO_NAME\", \"public\": $PUBLIC }"
fi
# end ===============================

How to Pull, Checkout and Push

git pull <repo-link>
git checkout -b master
<make your code changes>
<make changes to .gitignore to exclude files>
git add .
git commit -m "updated the code to/for ..."
git show
git push origin master

Other GIT handy commands

git fetch <repo-name>       # get changes, rather than pull whole code base
git init                    # initialize new local dir
git status                  # print status
git remote get-url origin   # check the origin

Containers – Docker on Ubuntu 14.04

Update – February 11, 2017 – Added Cleaning up docker section.

Pre-reqs:

  • OS: Ubuntu 14.04
  • sudo access to root
  • internet access

Install Docker

Update package manager, install the docker.io package & create a symlink from docker.io to docker, fix bash auto complete to add ‘docker’

sudo apt-get update
sudo apt-get -y install docker.io
sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker

Start Docker on system start-up

update-rc.d docker.io defaults

Download a Docker container

sudo docker pull ubuntu

Run Docker container

Setup a basic ubuntu container with a bash shell, we just run one command.  docker run will run a command in a new container, -i attaches stdin and stdout, -t allocates a tty, -h allocates a hostname, and we’re using the standard ubuntu container.

sudo docker run -i -t ubuntu /bin/bash

That’s it! You’re now using a bash shell inside of a ubuntu docker container.

To disconnect, or detach, from the shell/container without exiting/shutting down use the escape sequence Ctrl-p + Ctrl-q.

To shutdown the container, run exit, but remember that container storage is ephemeral, meaning data isn’t saved. You’ll need to use docker volumes.

To search for other community docker containers

sudo docker search aws
or
sudo docker search google

List containers

sudo docker ps
sudo docker ps -a
sudo docker ps -l
sudo docker ps -a --filter "status=running"

docker ps will list running container, -a list all containers, -l list latest created containers including non-running containers, a –filter “status=running” list all running containers

Attach to a container

sudo docker attach <container-id>
sudo docker attach d8894b58ecb6

Committing changes to your container

sudo docker commit <container-id> <new-container-name>
sudo docker commit d8894b58ecb6 new-docker-v1

To create a new image from changes to a container, it’s a simple as running just one command, docker commit.

View container logs

sudo docker logs <container-id>
sudo docker logs d8894b58ecb6

To view the logs for a container it’s as simple as running just one command, docker logs. If you don’t have any logs listed then no changes have been made to the container.

Restart a running container 

sudo docker stop <container-id>
sudo docker stop d8894b58ecb6
sudo docker stop d8894b58ecb6

To restart a running container, it’s a simple as running just one command, docker restart.

Stop a running container (or multiple containers)

sudo docker stop <container-id>
sudo docker stop d8894b58ecb6
sudo docker stop d8894b58ecb6 bafb4b2fc70f

To stop a running container, it’s a simple as running just one command, docker stop.

List all images/containers on this server

sudo docker images

 

To view docker usage stats – CPU, MEM & Network

sudo docker stats <container-id>
sudo docker stats d8894b58ecb6

Keeping persistent data – docker storage volumes

There’s no way to directly create a “data volume” in Docker, so instead we create a data volume container with a volume attached to it. For any other containers that you then want to connect to this data volume container, use the Docker’s --volumes-from option to grab the volume from this container and apply them to the current container.

sudo docker create -v /data1 --name datacontainer ubuntu

This created a container named datacontainer based off of the ubuntu image and in the directory /data1.

Now, if we run a new Ubuntu container with the --volumes-from flag anything we write to the /data1 directory will get saved

docker run -t -i --volumes-from datacontainer ubuntu /bin/bash
cd /data1
touch thisisapersistentfile.txt
exit

The file ‘thisisapersistentfile.txt’ we created will now be persistent on a container named datacontainer and in the directory /data1.

Cleaning up docker

After starting and stop all of those containers, stuuff get left behind (so you might inspect it later if you desire). But, if you are running out of disk space because of docker, give this script a try.

#!/bin/bash
# hosted at https://gitlab.com/shallawell/clean-up-docker/blob/master/cleanup-docker.sh
#from https://lebkowski.name/docker-volumes/

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root"
   exit 1
fi

echo " current disk space"
df -h

# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v

# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi

# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
  docker ps -aq | xargs docker inspect | jq -r '.[] | .Mounts | .[] | .Name | select(.)'
) | xargs -r rm -fr

echo "new disk space"
df -h

Docker help

sudo docker –help

https://docs.docker.com

 

 

 

How to display a static Google Map

 

If you have ever needed a static Google Maps image, here is the URL to use:

The bold values can be changed to suit your requirements.

https://maps.googleapis.com/maps/api/staticmap?center=180,lonsdale,st,melbourne,%20Australia&zoom=15&size=800×600&format=gif&sensor=false

Handy if you need a simple version to print and take with you.

You can do much more than described above like add markers and routes, just visit the Google Developers site https://developers.google.com/maps/documentation/static-maps/intro?hl=en