How can I avoid repetition across projects for deployment?


#1

I have started using Circle CI for testing and deploying projects to Rancher environments. After writing the third circle.yml file, I noticed a pattern. This is the deployment section of one of my project’s circle.yml files, with the common bits replaced by variables:

deployment:
    hub:
        branch: master
        commands:
            - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
            - docker push $DOCKER_USER/$DOMAIN-$SITE
            - git clone $CONFIG_REPO_URL
            - wget https://github.com/rancher/rancher-compose/releases/download/$RC_VERSION/rancher-compose-linu
x-amd64-$RC_VERSION.tar.gz
            - tar zxf rancher-compose-linux-amd64-$RC_VERSION.tar.gz
            - (cd $CONFIG_REPO/$DOMAIN && ../../rancher-compose-$RC_VERSION/rancher-compose up -d -u -c $SITE)

Is there an elegant way that I can somehow build a personal module with these commands so I can reference it with one word? It would be nice to not have to cut and paste this into each circle.yml file.


#2

That’s a very good question. One thing that comes to mind is having a deploy script available on GitHub that you pull down with wget and then run it with passing in some arguments specific to that circle.yml.

For example:

curl -s https://raw.githubusercontent.com/<user>/deployment-scripts/master/main-deply.sh | bash -s $DOMAIN

Then that script just exists in one place.


#3

The deploy script is a great idea, if only because I can debug it from outside Circle and avoid 37 commits to a test branch and 37 CI runs just to make sure I have no typos in the deployment section. :slight_smile:
I will give that a try. Thank you for the useful suggestion!


#4

I ended up writing a deploy script which uses the stack configuration files. It still took a lot of test commits, because I tried a few different approaches, but this one looks best. Thank you again!


#5

I’m glad you found a solution :slight_smile:


#6