Skip to content

Commit

Permalink
new profile for cloud sql connection
Browse files Browse the repository at this point in the history
- update quarkus
- update README
  • Loading branch information
David Dasenbrook committed May 24, 2023
1 parent 8e2cc16 commit ab36dde
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,24 @@ Push the image:
```bash
docker push europe-west3-docker.pkg.dev/pulumi-challenge/cloudland/quarkus-todo-app:1.0
```

## Profiles

The default settings configure the application for use with an in-memory H2 DB. Additionally, the application can be configured
to connect to a Postgres-DB running on Google Cloud SQL. This can be achieved by using the "cloudsql" profile at build time, e.g.
by using

```bash
quarkus build -Dquarkus.container-image.build=true -Dquarkus.profile=prod,cloudsql
```

to build the application / container image. Unfortunately, the cloudsql profile cannot be dynamically configured at run time,
as the property `quarkus.datasource.jdbc.driver` needs to be set and is one of the quarkus properties that need to be fixed
at build time.

In addition, when using the cloudsql profile, the following properties need to be set, e.g. by using environment variables:

- `quarkus.datasource.username` (set this to the configured db user name),
- `quarkus.datasource.password` (set this to the configured db user password),
- `quarkus.datasource.jdbc.url` (set this to `jdbc://postgresql:///<db-name>`, where `<db-name>` is the name of the database created on Cloud SQL)
- `quarkus.datasource.jdbc.additional-jdbc-properties.cloudSqlInstance` (set this to the "instance connection name" of the instance on Cloud SQL)
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<quarkus-plugin.version>2.6.3.Final</quarkus-plugin.version>
<quarkus-plugin.version>2.16.6.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>2.6.2.Final</quarkus.platform.version>
<quarkus.platform.version>2.16.6.Final</quarkus.platform.version>

<testcontainers.version>1.16.3</testcontainers.version>

Expand Down
6 changes: 3 additions & 3 deletions quarkus-todo/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ quarkus.rest-client.webhook.url=http://localhost:8080
%cloudsql.quarkus.datasource.db-kind=other
%cloudsql.quarkus.datasource.username=postgres
%cloudsql.quarkus.datasource.password=postgres
%cloudsql.quarkus.datasource.jdbc.url=jdbc:postgresql://mypostgres
%cloudsql.quarkus.datasource.jdbc.url=jdbc:postgresql:///mypostgres
%cloudsql.quarkus.datasource.jdbc.driver=org.postgresql.Driver
%cloudsql.quarkus.datasource.jdbc.additional-jdbc-properties.cloudSqlInstance=viadee-cloudland-pulumi-01:europe-west3:instance
%cloudsql.quarkus.datasource.jdbc.additional-jdbc-properties.socketFactory=com.google.cloud.sql.postgres.SocketFactory
%cloudsql.quarkus.datasource.jdbc.additional-jdbc-properties.cloudSqlInstance=viadee-cloudland-pulumi-01:europe-west3:instance
%cloudsql.quarkus.datasource.jdbc.additional-jdbc-properties.socketFactory=com.google.cloud.sql.postgres.SocketFactory
%cloudsql.quarkus.hibernate-orm.dialect=org.hibernate.dialect.PostgreSQL10Dialect
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.quarkus.sample;

import io.quarkus.test.junit.NativeImageTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.common.mapper.TypeRef;
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.MethodOrderer;
Expand All @@ -17,7 +17,7 @@
import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.core.Is.is;

@NativeImageTest
@QuarkusIntegrationTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TodoResourceIT {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.inject.Inject;

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

Expand All @@ -14,10 +15,11 @@
@QuarkusTest
public class WebHookServiceTest {
@Inject
private WebHookService webHookService;
WebHookService webHookService;

@InjectMock
private WebHookHttpService webHookHttpService;
@RestClient
WebHookHttpService webHookHttpService;

@Test
void testCallWebHook() {
Expand Down

0 comments on commit ab36dde

Please sign in to comment.