Update git cloned files timestamp with git timestamp

tjain152
Participant II

Hello,

Not sure if its been addressed earlier. We have a bunch of proxies under a single Git branch and would like to deploy only the changed proxies to Apigee. We use bamboo as CI.

The problem is git cloned code on bamboo agent always takes the local time stamp. The deploy plugin compares the deployed proxy time stamp with the cloned code time stamp and if its latest it does the deployment. We need a way to update the time stamp of cloned code with Git last commit So that the deployment to only changed proxy is made.

Has anyone encountered the similar issues. May be a script to update git time stamp would work. Any suggestions to address would be highly appreciated.

Regards

Tarun J.

1 7 4,237
7 REPLIES 7

I'll defer to other apigeeks to provide guidance on the plugin. But a suggestion: Maybe a checksum approach would work. If the checksum is changed, then re-deploy. I don't know if it is possible to teach the deploy plugin new tricks like this.

When the Description element is absent in the bundle xml file the plugin fills in with the git commit-id. This could be exploited for this scenario, but it is a mutable field in the UI and will work in a no-human-touch environment.

Not applicable
@Dino

you're absolutely correct, trying to change git cloned file's timestamps was heavily discouraged by Linus https://web.archive.org/web/20120518150852/http://kerneltrap.org/mailarchive/git/2007/3/5/240536

The checksum approach will work easily by asking git:

#!/bin/bash


# grab the commit hash for the root directory
sha=`git shortlog -1 ./ --format="%p"`


for foldername in `ls -d ./sharedflows/*/`; do
        # grab the commit hash for the root directory
        folderSha=$(git shortlog -1 $foldername --format="%p")
        # if the folder commit hash matches the root directory commit hash, then you found recent changes
        if [ "$sha" = "$folderSha" ]; then
                echo $foldername
                # Do Work On This Directory
        fi
done


I believe that was on a different context and was 10 years old. Almost all build systems today are based on time stamp. Found several post on this:

https://stackoverflow.com/questions/9789446/git-checkout-how-can-i-maintain-timestamps-when-switchin...

https://gist.github.com/tstone2077/86529356dd120eb0e51f

IMHO I see no need to check time stamps if you can just ask git which folders were updated in the last commit.

**This is only relevant if you have multiple proxies or shared flows under different folders next to each other in the same repository, and the goal is to determine which proxy/sharedflow changed in the latest commit and requires deployment

Relevant repository layout:

└── sharedflows
    ├── SharedFlow-Number1
    ├── SharedFlow-Number2

└── apiproxies
    ├── Proxy-Number1
    ├── Proxy-Number2

The plugin does not use deployed proxy time stamp to optionally skip deployment of a new bundle. The scenario you describe is one of the reasons timestamps are not reliable.

tjain152
Participant II

Thanks everyone. Are you saying that the "apigee maven deploy plugin" deploys code based on checksum? Is this the way all apigee clients are doing deployment?

We have around 140 proxies and more than 3000 developer apps. We do not want everything to get deployed everything we run maven deploy.

I however have another view to this. Apigee stores the time stamp for every change to a developer app/proxy and we can retrieve that using

https://api.enterprise.apigee.com/v1/organizations/org-name/keyvaluemaps/env-UpdateDataKVM

Now we know when a particular app was last deployed on Apigee. After this if someone has changed the JSON file of app and we want it to get deployed and nothing else.

Once we clone the code on a machine from git, cloned code takes the time stamp of local linux. Updating time stamp of cloned files with mtime of git, does not cause any harm. And we can then compare if the file is latest, do the deployment.

why can't we compare the time stamp returned by above call with the time stamp of file on git?

Regards