Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement continuous deployment for a web service

I have a Java application, which runs inside web container (Jetty at the moment) and responds to requests via web services.

Now I want to create a mechanism, which allows to deploy (transfer the WAR file to the server, install the new version there) a new version of the application to Amazon EC2 instance as easily as possible (ideally - by running some Maven command).

I'm using Beanstalk for my version control and they offer deployment support, but I couldn't figure out how to apply it to my scenario.

Are there any tutorials on how to deploy web applications to Amazon EC2 with Maven (with or without Beanstalk) ?

Update 1 (10.04.2013): Beanstalk staff has recommended me to use SSH deployments.

Update 2 (11.04.2013 23:17 MSK):

In my first attempt to use Maven Cargo plugin, I added following stuff to my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    [...]
    <build>
    [...]    
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>Heaven7</containerId>
                        <type>remote</type>
                    </container>
                    <configuration>
                        <type>runtime</type>
                        <properties>
                            <cargo.remote.username>myusername</cargo.remote.username>
                            <cargo.remote.password>mypassword</cargo.remote.password>
                        </properties>
                    </configuration>

                    <!-- Deployer configuration -->
                    <deployer>
                        <type>remote</type>
                    </deployer>

                    <deployables>
                        <deployable>
                            <groupId>ru.mycompany</groupId>
                            <artifactId>my-product</artifactId>
                            <type>war</type>
                        </deployable>
                    </deployables>
                </configuration>
            </plugin>
        </plugins>
    </build>
    [...]
</project>

Then I ran mvn cargo:deploy and got following output:

[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.3.3:dep
oy (default-cli) on project [...]: Execution default-cli of goal org.codeh
us.cargo:cargo-maven2-plugin:1.3.3:deploy failed: Cannot create configuration.
here's no registered configuration for the parameters (container [id = [Heaven7
, type = [remote]], configuration type [runtime]). Actually there are no valid
ypes registered for this configuration. Maybe you've made a mistake spelling it

2 questions:

  1. How can I fix it?
  2. Where can I specify the address my Tomcat container?

Update 3 (12.04.2013 22:36 MSK):

I changed the section related to Cargo plugin like this:

    <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.3.3</version>
        <configuration>
            <container>
                <containerId>tomcat7</containerId>
                <type>remote</type>
            </container>
            <configuration>
                <type>runtime</type>
                <properties>
                    <cargo.remote.username>myuser</cargo.remote.username>
                    <cargo.remote.password>mypassword</cargo.remote.password>
                    <cargo.hostname>ec2-NN-NNN-NN-NN.compute-1.amazonaws.com</cargo.hostname>
                    <cargo.protocol>http</cargo.protocol>
                    <cargo.servlet.port>8080</cargo.servlet.port>
                </properties>
            </configuration>

            <!-- Deployer configuration -->
            <deployer>
                <type>remote</type>
            </deployer>
            <deployables>
                <deployable>
                    <groupId>ru.mycompany</groupId>
                    <artifactId>myproduct</artifactId>
                    <type>war</type>
                </deployable>
            </deployables>

        </configuration>
    </plugin>
</plugins>

Then I executed mvn cargo:deploy and got this output:

[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.3.3:depl
oyer-deploy (default-cli) on project ccp-server: Execution default-cli of goal o
rg.codehaus.cargo:cargo-maven2-plugin:1.3.3:deployer-deploy failed: Cannot creat
e configuration. There's no registered configuration for the parameters (contain
er [id = [tomcat7], type = [remote]], configuration type [runtime]). Actually th
ere are no valid types registered for this configuration. Maybe you've made a mi
stake spelling it? -> [Help 1]

Update 4 (12.04.2013 23:12):

I changed pom.xml once again to:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.3.3</version>
    <configuration>
        <container>
            <containerId>tomcat7x</containerId>
            <type>remote</type>
        </container>
        <configuration>
            <type>runtime</type>
            <properties>
                <cargo.remote.username>myuser</cargo.remote.username>
                <cargo.remote.password>mypassword</cargo.remote.password>
                <cargo.hostname>ec2-NN-NNN-NN-NN.compute-1.amazonaws.com</cargo.hostname>
                <cargo.protocol>http</cargo.protocol>
                <cargo.servlet.port>8080</cargo.servlet.port>
            </properties>
        </configuration>

        <!-- Deployer configuration -->
        <deployer>
            <type>remote</type>
        </deployer>
        <deployables>
            <deployable>
                <groupId>ru.mycompany</groupId>
                <artifactId>myproduct</artifactId>
                <type>war</type>
            </deployable>
        </deployables>

    </configuration>
</plugin>

Then, I used following commands to deploy my application to the server:

  1. mvn clean
  2. mvn install
  3. mvn cargo:deploy

Please note that <packaging> must be set to war in order for this sequence to work (otherwise you may get strange error messages).

like image 208
Dmitrii Pisarenko Avatar asked Oct 22 '22 12:10

Dmitrii Pisarenko


1 Answers

You could use the cargo maven plugin to deploy on a remote server. See this example for a remote deployment on a Tomcat server : Maven: How do I deploy my WAR file to a remote Tomcat server?

like image 72
willome Avatar answered Oct 24 '22 03:10

willome