Tuesday, 16 July 2019

Merging git repositories - preserving history

Repository A:

File1
File2
File3

Repository B

Filea
DirB

We want to import Repository A into B as a sub directory

First move all the files in Repository A into a subdirectory:

Repository A:

mkdir imported
git add imported
git mv File1 imported/
git mv File2 imported/
git mv File3 imported/
gt commit -m"moved fiels into subdir"
git push

Repository B

git add origin repb
git fetch
git merge --allow-unrelated-histories repb
git push

Hopefully now RepA appears in RepB in directory imported  !

Wednesday, 26 June 2019

Installing Visual Studio Code on linux - non-root user


Based on a stack overflow answer:

  1. Download Visual Studio Code for Linux
  2. Copy it somewhere you are happy to extract it into and keep eg ~/bin
  3. Extract it: tar -xvf VSCode-linux-x64.tar.gz
  4. Add the executable to the system path eg export PATH=$HOME/bin/VSCode-linux-x64
  5. Run the code executable to open Visual Studio Code
  6. (Optional) add the export statement into your ~/.bashrc

Monday, 24 June 2019

Installing node.js on a linux machine as non-root user

Follow these instructions to install node on a linux machine; no root privileges required.


We will install nvm (Node Version Manager) to allow us to install several versions of node onto the same machine:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash

This currently produces output as the following:

Resolving deltas: 100% (4737/4737), done.
* (HEAD detached at v0.33.1)
  master
=> Compressing and cleaning up git repository
Counting objects: 7495, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (7440/7440), done.
Writing objects: 100% (7495/7495), done.
Total 7495 (delta 5009), reused 2259 (delta 0)
=> Appending nvm source string to /homes/sms67/.bashrc
=> bash_completion source string already in /homes/sms67/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

Now add the following to your ~/.bashrc file (last two lines of the output above):

echo "export NVM_DIR=\"\$HOME/.nvm\"" >> ~/.bashrc
echo "[ -s \"\$NVM_DIR/nvm.sh\" ] && \. \"\$NVM_DIR/nvm.sh\"  # This loads nvm" >> ~/.bashrc

Then source your .bashrc

myhost: source ~/.bashrc

The help page for nvm can now be found by:

myhost: nvm --version
The command above hopefully returned soem output (how to page).  If so great we can now install a version of node:

myhost: nvm install node

Then to use our installed version:

myhost: nvm use node
Check your installed versions of node and npm using:

myhost: node -v
myhost: npm --version 
You should now be able to create your first node application, or write some protractor tests!

Monday, 10 December 2018

Git - configuring files with execute permissions

To configure files so that they are executable when cloned/checked out from git, (saving you to chmod after a checkout):

git add
git update-index --chmod=+x
git commit 

There may also be a method you can use via a .gitattributes file?!

Tuesday, 2 January 2018

Docker compose 'tricks'

Access a compose container in interactive mode

see: solution on docker forum

Having started docker-compose using a compose file similar to:

version: "2"
services:
  selenium:
      restart: always
      image: stesho/selenium-remote
      ports:
        - "4444:4444"
  centaurtestservers:
      restart: "no"
      image: stesho/centaur-testservers
      ports:
        - "4004:4004"
        - "4005:4005"
        - "4006:4006"
        - "4007:4007"
        - "4008:4008"
      volumes:
        - B:\docker-mount\centaur-build:/tmp/centaur-build
      command: bash -c "echo 'hello world'"
  centaurtests:
      depends_on:
        - "selenium"
        - "centaurtestservers"
      restart: "no"
      image: stesho/centaur-tests

I can run docker ps to list the container now running:


P:\>docker ps

CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS                          PORTS                                             NAMES
5b32cca41c49        stesho/selenium-remote       "echo 'hello world'"     2 minutes ago       Restarting (0) 38 seconds ago                                                     centaurtests_selenium_run_1
c046fd91bc9f        stesho/centaur-testservers   "/bin/sh -c '/bin/..."   4 weeks ago         Up 4 weeks                      3004-3008/tcp, 0.0.0.0:4004-4008->4004-4008/tcp   centaurtests_centaurtestservers_1
71fccaf3fabf        stesho/selenium-remote       "sh /opt/selenium/..."   4 weeks ago         Up 4 weeks                      0.0.0.0:4444->4444/tcp                            centaurtests_selenium_1
3b61025ad614        0700d505656c                 "/bin/sh -c 'sourc..."   4 weeks ago         Up 4 weeks                                                                        silly_shirley
5244fdf06b74        stesho/centaur               "/bin/sh -c 'sourc..."   4 weeks ago         Up 4 weeks                      0.0.0.0:3004-3008->3004-3008/tcp                  objective_bassi
92f4b101ad6a        stesho/eprints3              "/bin/bash"              7 weeks ago         Up 7 weeks                      0.0.0.0:8098->8098/tcp                            eprints_pubs

After which I can login to my chosen container in an interactive shell for example:

P:\>docker exec -it objective_bassi bash


Monday, 22 May 2017

Remove Docker overlays and images

To remove all the images and their overlays:

sudo docker rmi `docker images -aq`


If there are any remaining overlays in /var/lib/docker/overlay can we just delete these?

Try to prune docker:

 sudo docker system prune -a -f


Allowing docker write access to volumes mounted on NFS

My development machine (mydev) mounts several directories which are on an NFS mounted filesystem

When I run docker I wish to be able to access and write to the NFS filesystem.

The following is a brief technique:

Inside the dockerfile:


RUN useradd -m -d /home/mydocker mydocker; echo 'usermod -u $HOST_UID mydocker' >> ~/.bash_profile

# what order does this run in?
ENTRYPOINT source /root/.bash_profile && su - mydocker && /bin/bash


If I we to run docker with:

[me@mydev]$ sudo docker -i run -e"HOST_UID=`id -u`" -v /some/nfs/drive:/var/local/drive -t /bin/bash

Then mydocker will have the same uid as the user I ran the sudo with and should be able to access the NFS drive in the same was as the native user (me).