Slow symlink upload

Symlinks can be uploaded from the command line by running scp in recursive mode:

scp -r
$

However, enabling the mode will also copy the content to which the symlink is pointing to. This is troublesome if we only want the symlinks to be copied, and it’s not possible to do it differently with SCP.

This is usually solved by using rsync:

rsync -avz -e ssh /scr-dir user@host:/dst-dir
$

Unfortunately, rsync is very time-consuming.

Solution 1: Local Script + Server Upload + Host Script

The first solution employs some simple scripts and a deployment action. First we need a script grab-links.sh that will list all symlinks in the folder. The script will search the folder in recursive mode and create a file with instructions that will reproduce the symlinks on the target server:

# !/bin/sh

echo "#!/bin/sh\n" > create-links.sh
for file in $(find . -type l); do
            link=$(readlink $file);
            echo "if [ ! -L $file ]; then ln -s $link $file; fi" >> create-links.sh;
done

Now, we need to save the script to a grab-links.sh file and execute:

chmod +x grab-links.sh
./grab-links.sh
$$

The command will generate create-links.sh that you can run on the server to reproduce your symlinks:

chmod +x create-links.sh
./create-links.sh
$$

Automation

In Buddy, you can create a pipeline that will automatically perform all these steps on every push to the repository:

  1. Upload the script grab-links.sh to the repository.
  2. Add a new pipeline and set the trigger event to 'Git push'.
  3. Add the Docker Container action and enter these commands:

     chmod +x grab-links.sh
     ./grab-links.sh
    $$

This action generates create-links.sh in the pipeline filesystem.

  1. Add the SFTP action to upload the new script to the server together with repository files.
  2. Add the SSH and enter these commands to run the script on the server:
 chmod +x create-links.sh
 ./create-links.sh
$$

Solution 2: Git Clone

Git handles symlinks exactly the way one could expect: if you push a symlink to the repository and somebody else clones this repository, the symlink will be reproduced in their local repo. So, basically, all that you need to do is install Git on the production server and run:

git clone
$

Automation

In this case, you configure Buddy to automatically pull the repository to the server upon every update to the selected branch.

  1. Add a new pipeline and set the trigger event to 'Git push'.
  2. Add the SSH action and set it to clone your repo:
git clone REPOSITORY_URL
$