Continuous Deployment of Database Backed Microservices Using Developer Cloud, Application Container Cloud and Database Cloud
Abishek Gupta wrote a nice article on Integrating Oracle Application Container & Database Cloud using 'Service Bindings'. Here I'm going to show how the delivery of that application can be automated using the Developer Cloud Service.
- Oracle Application Container Cloud Service
- Oracle Database Cloud Service
- A GitHub account.
- You have Git installed.
- Fork the https://github.com/wbleonard/accs-dbcs-devcs to your GitHub account.
- Clone the https://github.com/{your-github-id}/accs-dbcs-devcs to your local workstation:
As a departure from Abishek's article, we will fetch the Oracle JDBC driver from the Oracle Maven Repository.
Access to the Oracle Maven Repository requires your Oracle Account credentials, so your Maven settings.xml file needs to be configured to provide this information. Add the following <server>
element to the <servers>
section of the settings.xml, replacing the Oracle Account username and password with your credentials:
<servers>
<server>
<id>maven.oracle.com</id>
<username>{Oracle Account username}</username>
<password>{Oracle Account password}</password>
<configuration>
<basicAuthScope>
<host>ANY</host>
<port>ANY</port>
<realm>OAM 11g</realm>
</basicAuthScope>
<httpConfiguration>
<all>
<params>
<property>
<name>http.protocol.allow-circular-redirects</name>
<value>%b,true</value>
</property>
</params>
</all>
</httpConfiguration>
</configuration>
</server>
</servers>
For additional details, see Configuring the HTTP Wagon.
The Oracle Maven repository definition needs to be added to your project POM. For local builds, you can add this definition to your settings.xml, but for Developer Cloud builds, the repository must be specified in your project POM. There are a couple of reasons for this:
- The order in which repositories are specified in the POM dictates the search order, and therefore where the artifact is fetched from. This is best left to user to control.
- When we get into more complex inherited POM files, the Developer Cloud Service cannot tell without building an effective pom if the maven id is already used or if it will be overridden.
You will find the following in the projects pom.xml:
<repositories>
<repository>
<id>maven.oracle.com</id>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://maven.oracle.com</url>
<layout>default</layout>
</repository>
</repositories>
Let's ensure our Maven configuration properly pulls the Oracle ODBJ jar from the Oracle Maven repository:
{ accs-dbcs-devcs } master » mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building accs-dbcs-service-binding-sample 1.0
[INFO] ------------------------------------------------------------------------
Downloading: https://maven.oracle.com/com/oracle/jdbc/ojdbc7/12.1.0.2/ojdbc7-12.1.0.2.pom
Downloaded: https://maven.oracle.com/com/oracle/jdbc/ojdbc7/12.1.0.2/ojdbc7-12.1.0.2.pom (6 KB at 0.7 KB/sec)
...
[INFO] Building zip: C:\ProjectsGit\Database\accs-dbcs-devcs\target\accs-dbcs-service-binding-sample-1.0-ACCS.zip
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 47.503 s
[INFO] Finished at: 2017-04-19T15:42:48-04:00
[INFO] Final Memory: 36M/433M
[INFO] ------------------------------------------------------------------------
You will also notice that the package command builds the zip artifact that required by ACCS for deployment (accs-dbcs-service-binding-sample-1.0-ACCS.zip). This was achieved by the addition of the Maven Assembly Plugin to the POM.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptor>src/assembly/accs.xml</descriptor>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
-
In either a new or existing Developer Cloud Service project, select Administration > Repositories
-
Create a New External Repository and set the URL to https://github.com/{your-github-id}/accs-dbcs-devcs.git. Optionally set the Description to something like A repository to demonstrate continuous integration and deployment of a Java microservice that includes a database tier.
-
Create a New free-style Build Job named Database DevOps
-
Under Main, set the JDK to JDK 8:
-
Under Source Control, select the accs-dbcs-devcs.git repository:
-
Under Triggers select Based on SCM polling schedule and set the Schedule to
*****
: -
Under Environment select Connect Oracle Maven Repository and enter your OTN credentials:
-
Under Build Steps add an Invoke Maven 3 Build Step:
-
Under Post Build, select Archive the Artifacts and set the Files to Archive to
**/target/*.zip
: -
Save and click Build Now to validate the build configuration:
-
-
Create a new Deployment Configuration named Database DevOps
-
Save and Start the Database DevOps Deployment Configuration
In either a new or existing Database Cloud Service instance, let's create a new schema for this exercise:
```
SQL> CREATE USER DEVOPS IDENTIFIED BY DEVOPS;
User created.
SQL> GRANT CONNECT, RESOURCE, UNLIMITED TABLESPACE TO DEVOPS;
Grant succeeded.
```
Now we need to bind the DatabaseDevOps Application Container Cloud instance to our Oracle Database Cloud instance.
-
Navigate to the DatabaseDevOps Application Container Cloud instance and select the Deployments tab. Then Add a Service Binding to the Database Cloud Service, selecting the name of the Service in which you created the DEVOPS user:
-
We also need to add a couple of Environment Variables to store the Oracle database username and password:
-
Click Apply Edits which will apply the changes and restart the microservice:
Append /appdev/products to the end of the Application Container Cloud URL. For example:
https://databasedevops-gse00001975.apaas.em2.oraclecloud.com/appdev/products
Now that our base application is set up, let's make a change that includes the database. For this example I will add a description field to the results.