REBELinBLUE / deployer

Deployer is a free and open source deployment tool.
http://phpdeployment.org
MIT License
911 stars 185 forks source link

Templates improvement #286

Open axeloz opened 7 years ago

axeloz commented 7 years ago

Hello,

Just some feature requests concerning the templates :

Thanks

Axel

REBELinBLUE commented 7 years ago

First one definitely makes a lot of sense and shouldn't be that complicated

Second seems reasonable, and I guess wouldn't be much work after doing the first part

Third one is slightly tricky, I was thinking of templates more like templates for say Microsoft Word, when you change a template file it doesn't change any existing word document using it. The reason for this is that the place I was working at when I originally wrote had a slight difference in the steps so each project so although they were set up from a template if the template changed we didn't want to existing projects to change.

I guess I can understand how it would be useful though as several people have asked for it, maybe I could add an option to "link" and/or "unlink" from the template when creating a project

axeloz commented 7 years ago

Actually, I'm rethinking about this issue and I might have some changes to offer. Instead of having a unique template, including all related objects of a project in the template, it could be convenient to have templates for each object.

For example : we work with Wordpress but we don't commit any Wordpress files in the repo. Instead we have a /theme and a /plugin folders. Then we use a Gulp task who will process everything (sass, minify, images...) and will copy the plugin and the theme folder into the wp-content.

So this kind of project, I have created a script for the deployer. The script will fetch two project variables named WORDPRESS_VERSION and WORDPRESS_LOCALE. According to this settings, the script will download the asked version of Wordpress in the right locale, then create the symlinks and move what needs to be moved.

There is the script if anyone interested :

# Checking whether Wordpress already installed
if [ ! -d {{ project_path }}/shared/wp ]
then
    echo "Now installing Wordpress"

    # Wordpress is not installed
    mkdir {{ project_path }}/shared/wp
    if [ $? -ne 0 ]
    then
        echo "Cannot create wp dir"
        exit 1
    fi

    cd {{ project_path }}/shared/wp

    # Searching the WP_Cli binary (http://wp-cli.org/)
    wp=`which wp`

    # Binary does not exist or is not executable
    if [ ! -x $wp ]
    then
        echo "WP_Cli executable could not be found"
        exit 1
    fi

    echo "We found the WP_Cli binary"

    # Downloading Wordpress
    $wp core download --locale=$WORDPRESS_LOCALE --version=$WORDPRESS_VERSION

    if [ $? -ne 0 ]
    then
        echo "Unable to download Wordpress"
        exit 1
    fi

    echo "Wordpress was downloaded"

    # Making sure the upload dir does not exist
    if [ -d ./wp-content/uploads ]
    then
        rm -Rf ./wp-content/uploads
        if [ $? -ne 0 ]
        then
            echo "Unable to remove the uploads folder"
        fi
        echo "Deleted uploads folder"
    fi

    # Making sure the plugin dir does not exist
    if [ -d ./wp-content/plugins ]
    then
        rm -Rf ./wp-content/plugins
        if [ $? -ne 0 ]
        then
            echo "Unable to remove the plugins folder"
        fi
        echo "Deleted plugins folder"
    fi

    # Making sure the wp-config.php file does not exist
    if [ -f ./wp-config.php ]
    then
        rm -f ./wp-config.php
        if [ $? -ne 0 ]
        then
            echo "Unable to remove the wp-config.php file"
        fi
        echo "Deleted wp-config.php file"
    fi

    # Making sure the theme dir does not exist
    if [ -d ./wp-content/themes ]
    then
        rm -Rf ./wp-content/themes
        if [ $? -ne 0 ]
        then
            echo "Unable to remove the themes folder"
        fi
        echo "Deleted themes folder"
    fi
fi

# Copying Wordpress into the release

cp -Rf {{ project_path }}/shared/wp/* {{ release_path }}
if [ $? -ne 0 ]
then
    echo "Unable to copy Wordpress to release"
    exit 1
fi

echo "Done"
exit 0

Well, I think this script could be a template itself. Meaning that when you add a step, you can choose this script as a template.

Just an idea...

Thanks

uLow commented 7 years ago

@REBELinBLUE don't want to argue about default steps, but it would be great to have templates for custom commands. One-type projects with big amount of post-install scripts are b-hurt when creating them one-by-one.