How can I publish static web resources to Amazon S3 using Hudson/Jenkins and Maven? How can I publish static web resources to Amazon S3 using Hudson/Jenkins and Maven? jenkins jenkins

How can I publish static web resources to Amazon S3 using Hudson/Jenkins and Maven?


This is how I do it: Use an external program, such as s3cmd to do the job. You would simply specify a shell script build step like this

#!/bin/shs3cmd --guess-mime-type -P sync $WORKSPACE/src/main/resources s3://your-bucket-name/some/path

You can probably integrate this in your pom.xml and call it from there (so this part of your deployment process is under version control).


Turned out I didn't need to do this. We were always planning on using CloudFront for distribution, and recently AWS have allowed you to specify a 'custom origin' for CloudFront distributions. This means that static assets can be deployed along with the rest of the .war contents, and then a CloudFront distribution pointed at that application.


I created a s3-webcache-maven-plugin, that uploads images, javascript, css and any other static resources from src/main/webapp to a given S3 Bucket, and the sources are available at https://github.com/aro1976/aws-parent.

In addition, it creates a manifest called WEB-INF/s3-webcache.xml, that could be used by a servlet filter to redirect requests from your Web Server to S3 or CloudForge.

You need to place the following configuration into <build><plugins>:

<plugin>  <groupId>br.com.dynamicflow.aws</groupId>  <artifactId>s3-webcache-maven-plugin</artifactId>  <version>0.0.2-SNAPSHOT</version>  <configuration>    <accessKey>${s3.accessKey}</accessKey>    <secretKey>${s3.secretKey}</secretKey>    <bucketName>${s3.bucketName}</bucketName>    <hostName>${cloudForge.cname}</hostName><!-- hostName is optional -->    <includes>      <include>**/*.gif</include>      <include>**/*.jpg</include>      <include>**/*.tif</include>      <include>**/*.png</include>      <include>**/*.pdf</include>      <include>**/*.swf</include>      <include>**/*.eps</include>      <include>**/*.js</include>      <include>**/*.css</include>    </includes>    <excludes>      <exclude>WEB-INF/**</exclude>    </excludes>    </configuration>    <executions>    <execution>      <goals>          <goal>upload</goal>      </goals>      <phase>prepare-package</phase>    </execution>    </executions></plugin>

The configuration parameters such as includes and excludes are required at this time, and you can use traditional maven regex.

The file names stored at S3 are replaced by their SHA-256 digest, in order to allow very long cache-headers and multi war otimization, that's why I created the WebCacheFilter, which is very simple and translates the traditional file names with the SHA-256 digest counterpart.

Check the Example Project at https://github.com/aro1976/aws-parent/tree/aws-parent-0.0.1/aws-examples/s3-webcache-example, specially the files pom.xml (with the plugin configuration) and web.xml (with the filter configuration).