0

I found this answer https://serverfault.com/a/822596/123651

I need to include a random file \.ebextensions\nginx\conf.d\elasticbeanstalk\force-https.conf in my WAR to be deployed on the AWS ElasticBeanstalk console. How do I include this file in the mvn package command? How will ElasticBeanstalk read this file inside of the WAR?

I tried to use this guide and added to my pom.xml

<build>
  ...
    <resources>
      <resource>
        <directory>.ebextensions/nginx/conf.d/elasticbeanstalk/</directory>
        <includes>
            <include>force-https.conf</include>
        </includes>
      </resource>
    </resources>
</build>

Then ran mvn package -DskipTests and tar tvf target\app-0.0.3-SNAPSHOT.war | less but it put the file in the wrong place!

-rw-rw-r--  0 0      0          94 Nov 14 12:40 WEB-INF/classes/force-https.conf
Chloe
  • 25,162
  • 40
  • 190
  • 357
  • 1
    Where should the file be placed? Based on the ServerFault answer, it should be in a ZIP container, but outside the WAR/JAR file. – Compass Nov 14 '18 at 18:13
  • @Compass Yes that appears to work. I manually created a zip file containing the WAR and `.conf` and it did work. So how do I create a zip file with Maven? Looking that up now... – Chloe Nov 14 '18 at 20:57

1 Answers1

0

This worked. It seems excessively verbose for just making a ZIP of 2 files.

pom.xml
        <plugin> <!-- To add .ebextensions/ Nginx config for ElasticBeanstalk -->
          <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <descriptors>
              <descriptor>assembly.xml</descriptor>
            </descriptors>
          </configuration>
          <executions>
            <execution>
              <id>make-assembly</id>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
            </execution>
          </executions>
        </plugin>           
assembly.xml
<assembly 
  xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  <id>bin</id>
  <baseDirectory>/</baseDirectory>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.build.directory}</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>*-SNAPSHOT.war</include>
      </includes>
    </fileSet>
    <fileSet>
      <directory>${project.basedir}</directory>
      <outputDirectory>/.ebextensions/nginx/conf.d/elasticbeanstalk/</outputDirectory>
      <includes>
        <include>force-https.conf</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>

And the configuration file is just in the project root. I didn't know where else to put it - it's not source code.

force-ssl.conf
if ($http_x_forwarded_proto = 'http') {
    return 301 https://$host$request_uri;
}

http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

Community
  • 1
  • 1
Chloe
  • 25,162
  • 40
  • 190
  • 357