Skip to content

Instantly share code, notes, and snippets.

@flenter
Last active December 25, 2015 14:39
Show Gist options
  • Save flenter/6992234 to your computer and use it in GitHub Desktop.
Save flenter/6992234 to your computer and use it in GitHub Desktop.
wercker.yml for php with a yui compressor step
box: wercker/php
# Build definition
build:
# The steps that will be executed on build
steps:
# A custom script s tep, name value is used in the UI
# and the code value contains the command that get executed
- script:
name: echo php information
code: |
echo "php version $(php --version) running"
echo "from location $(which php)"
# Add more steps here:
#- script:
# name: run unit tests
# code: phpunit
after-steps:
- hipchat-notify:
token: $HIPCHAT_TOKEN
room-id: 199099
from-name: Wercker
deploy:
steps:
- script:
name: simple ls step
code: |
ls -la
after-steps:
- hipchat-notify:
token: $HIPCHAT_TOKEN
room-id: 199099
from-name: Wercker
@flenter
Copy link
Author

flenter commented Oct 15, 2013

We can add sftp upload support by changing the deploy steps content from:

    - script:
        name: simple ls step
        code: |
          ls -la

To

      - install-packages:
          packages: sshpass
      - add-to-known_hosts:
          hostname: yourdomain.com
      - script:
          name: simple ls step
          code: |
            sshpass -p $MY_PASSWORD scp -r * yourlogin@yourdomain.com:/var/local/sites/

You have to add the password for your sftp to wercker. Which you can do in the settings tab of your application (go to pipeline and click add environment variable) Name it MY_PASSWORD and make it protected (so it won't show up in logs) and you're done.

note: I've only tested this script with one file though and it probably will not copy hidden files (or dot files).
note 2: It would be better to use ssh keys instead of using sshpass. Wercker can generate an ssh key pair for you, it is however slightly more work to implement.

edit: location of -r parameter for scp

@flenter
Copy link
Author

flenter commented Oct 15, 2013

Making the code available as a zip file can be done like this. Add before your after-steps for the build phase the following code:

      - script:
          name: make available as download
          code: |
            cp -r * $WERCKER_REPORT_ARTIFACTS_DIR 

If you go to the make available as download step in wercker and you'll find a artifacts tab (if the total code code is less than 50MB). You can see in the log of the step if there's more than 50MB of data.

@flenter
Copy link
Author

flenter commented Oct 15, 2013

Ok. And for ftp, we can change the deploy steps content into:

    - install-packages:
        packages: python-pip
    - script:
        name: install pyftpsync
        code: |
          sudo pip install pyftpsync
    - script:
        name: sync with remote
        code: |
          pyftpsync  upload . ftp://username:$MY_PASSWORD@example.com/target/folder -x

You can see some of the options for the ftp command here:
https://github.com/mar10/pyftpsync/wiki

note: you may want to run the command first without -x . It just tries to see if it can upload files without changing anything (dry run)
edit: ftpsync corrected to: pyftpsync
edit: switched : and @

@flenter
Copy link
Author

flenter commented Oct 15, 2013

Alternatively we could use this:

    - install-packages:
        packages: lftp
    - script: 
        name: prepare lftp settings
        code: |
          mkdir -p $HOME/.lftp
          echo "set ssl:verify-certificate no" > $HOME/.lftp/rc
    - script:
        name: sync with remote
        code: |
          lftp -e "mirror -R . /;bye" -u username,$MY_PASSWORD example.com

note: mkdir -p added, use of tilde replaced with $HOME

@flenter
Copy link
Author

flenter commented Oct 16, 2013

For minifying we can do the following changing the build steps from

    # A custom script s tep, name value is used in the UI
    # and the code value contains the command that get executed
    - script:
        name: echo php information
        code: |
          echo "php version $(php --version) running"
          echo "from location $(which php)"
    # Add more steps here:
    #- script:
    #    name: run unit tests
    #    code: phpunit

to:

    - install-packages:
        packages: yui-compressor
    - script:
        name: move code to output dir
        code: |
          mkdir -p $WERCKER_OUTPUT_DIR/views
          cp -r * $WERCKER_OUTPUT_DIR/views
    - script:
        name: run yui compressor for js
        code: |
          cd $WERCKER_OUTPUT_DIR
          for file in `find . -name "*.js"`; do java -jar /usr/share/yui-compressor/yui-compressor.jar --type js -v -o $file $file; done
    - script:
        name: run yui compressor for css
        code: |
          cd $WERCKER_OUTPUT_DIR
          for file in `find . -name "*.css"`; do java -jar /usr/share/yui-compressor/yui-compressor.jar --type css -v -o $file $file; done

edit: Yui compressor doesn't like more than 1 layer of directories. compress step split into two steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment