caktus / margarita

A collection of delicious Salt states for Django project deployments.
BSD 3-Clause "New" or "Revised" License
34 stars 8 forks source link

Manually reset letsencrypt git checkout #134

Closed vkurup closed 8 years ago

vkurup commented 8 years ago

I haven't had a chance to test this yet.

I'm hoping that on a first run, the onlyif test would return false, so the git reset would NOT get run, and only install_letsencrypt would get run. Every subsequent run, the onlyif test would return true, so the git reset would run before the install_letsencrypt

This is another attempt at fixing #133 since it seems the salt version didn't work. (per testing on edxpass)

kmtracey commented 8 years ago

This worked for me on a project where letsencrypt was already there, but failed when I removed letsencrypt and tried deploying. The onlyif doesn't seem to be having the desired effect:

 ----------
           ID: really_reset_letsencrypt
     Function: cmd.run
         Name: git reset --hard HEAD
       Result: False
      Comment: Desired working directory "/var/www/edxpass/letsencrypt" is not available
      Started: 21:01:01.900810
     Duration: 1.102 ms
      Changes:   
 ----------
vkurup commented 8 years ago

I just pushed a version that removes the cwd param because salt tries to apply that before running the onlyif clause.

I tested it in a minimal fashion by creating a test file named /srv/salt/vinod.sls with these contents:

reset_repo
  cmd.run:
    - name: cd /fakedir && git reset --hard HEAD
    - onlyif: test -e /fakedir/.git

install_letsencrypt:
    git.latest:
      - name: https://github.com/letsencrypt/letsencrypt/
      - target: /fakedir
      - require:
          - cmd: reset_repo

I then ran: sudo salt '*' state.apply vinod

It seems to work as expected. If /fakedir is not there, the reset is skipped and the repo is cloned. If /fakedir/.git is there, then the reset occurs and the repo is updated.

jbradberry commented 8 years ago

This seems reasonable-ish according to the standards of Salt. :+1:

vkurup commented 8 years ago

I upgraded epicallies staging to use this PR (1.7.2) and it was successful. I deleted the directory and redeployed and that was also successful.