More Git Fun For Compiled Code

Following up on my previous post, Git Deploy For The Win, there are times at which the code you write isn't ready-to-go html and css and needs to be compiled. Grunt/Gulp tasks, Angular Builds, or Koa js backends. 

Nothing too crazy here. For an angular project, here is an example of the post-receive hook script for an angular app. You push your project to the server and it builds your app for you. Check out my previous post Git Deploy For The Win, for general instructions on how to get set up. Really the only thing that changes here is the post-receive script and serving your files from webroot/dist. 




while read oldrev newrev ref
        # only checking out the master (or whatever branch you would like to deploy)
        if [[ $ref = refs/heads/"$BRANCH" ]];
                echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
                git --work-tree="$TARGET" --git-dir="$GIT_DIR" checkout -f
                echo "--> Installing libraries..."
                cd "$TARGET"
            npm install
        echo "--> Rebuild dist"
        ng build --prod
            echo "--> Restarting..."
                echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."

Make sure it is executable :

chmod +x

Now, you can develop locally using ng serve and when you're ready for something to go on the server, you push to production. 

Written by Mark on Friday March 30, 2018
Permalink -

« Minolta Rokkor-X - Double Exposure with the Olympus iS-1 »