Slow symlink upload

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

bash
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:

bash
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 alongside the 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 create-links.sh with instructions that will reproduce the symlinks on the target server:

bash
# !/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 the grab-links.sh file and execute:

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

This will generate create-links.sh that you can upload and run on the target server to reproduce your symlinks:

bash
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. Here's what you need to do:

  1. Upload the script grab-links.sh to the repository.
  2. Add a new pipeline and set the trigger mode to run on every push.
  3. Add a Local Shell action and enter the commands that will run the script in the Buddy’s infrastructure:
bash
chmod +x grab-links.sh ./grab-links.sh$$
  1. Add an SFTP action that will upload the newly generated script create-links.sh.
  2. Add an SSH action and enter these commands to run the script on the target server:
bash
chmod +x create-links.sh ./create-links.sh$$

Image loading...Reproducing symlinks on the server

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

bash
git clone$

Automation

With Buddy you can execute git clone automatically on every push the repository. A good practice is to add unit tests to make sure your code is free of errors before it’s pulled.

  1. Add a new pipeline and set the trigger mode to run on every push.
  2. Add a Local Shell action.
  3. Add an SSH action that will execute git clone on the external repository.

Image loading...Running tests and pulling the symlinks on the server

Last modified on Sep 23, 2024