From 0421e228b168f04dfddb605cc38d14b467c32326 Mon Sep 17 00:00:00 2001 From: Emmanuel Hugonnet Date: Mon, 6 Nov 2023 17:50:38 +0100 Subject: [PATCH 1/2] WFLY-18512: todo-backend Quickstart Common Enhancements CY2023Q3 * Updating charts to fix conflict with cli script * Updating the pom to reflect the new properties * Removing the bootable-jar bits * Removing arquillian and upgrading to JUnit to 5 * Adding postgresql Signed-off-by: Emmanuel Hugonnet --- .../scripts/qs-overrides/todo-backend/ci.yaml | 16 ++ .../todo-backend/overridable-functions.sh | 7 +- .../workflows/quickstart_todo-backend_ci.yml | 16 ++ .../quickstart_todo-backend_ci_before.sh | 2 + .../.helmignore | 0 .../{todo-backend-chart => charts}/Chart.yaml | 5 +- todo-backend/charts/values.yaml | 46 +++++ todo-backend/pom.xml | 170 ++++-------------- .../quickstarts/todos/AbstractToDoIT.java | 68 ------- .../todos/ProvisionedManagedToDoIT.java | 67 ------- .../quickstarts/todos/RemoteToDoIT.java | 37 +++- todo-backend/todo-backend-chart/values.yaml | 93 ---------- 12 files changed, 156 insertions(+), 371 deletions(-) create mode 100644 .ci/openshift-ci/build-root/scripts/qs-overrides/todo-backend/ci.yaml create mode 100644 .github/workflows/quickstart_todo-backend_ci.yml create mode 100644 .github/workflows/quickstart_todo-backend_ci_before.sh rename todo-backend/{todo-backend-chart => charts}/.helmignore (100%) rename todo-backend/{todo-backend-chart => charts}/Chart.yaml (95%) create mode 100644 todo-backend/charts/values.yaml delete mode 100644 todo-backend/src/test/java/org/wildfly/quickstarts/todos/AbstractToDoIT.java delete mode 100644 todo-backend/src/test/java/org/wildfly/quickstarts/todos/ProvisionedManagedToDoIT.java delete mode 100644 todo-backend/todo-backend-chart/values.yaml diff --git a/.ci/openshift-ci/build-root/scripts/qs-overrides/todo-backend/ci.yaml b/.ci/openshift-ci/build-root/scripts/qs-overrides/todo-backend/ci.yaml new file mode 100644 index 0000000000..533c91fde1 --- /dev/null +++ b/.ci/openshift-ci/build-root/scripts/qs-overrides/todo-backend/ci.yaml @@ -0,0 +1,16 @@ +postgresql: + primary: + podSecurityContext: + enabled: true + fsGroup: 1001 + containerSecurityContext: + enabled: true + runAsUser: 1001 + runAsGroup: 0 + runAsNonRoot: true + allowPrivilegeEscalation: false + seccompProfile: + type: RuntimeDefault + capabilities: + drop: + - ALL \ No newline at end of file diff --git a/.ci/openshift-ci/build-root/scripts/qs-overrides/todo-backend/overridable-functions.sh b/.ci/openshift-ci/build-root/scripts/qs-overrides/todo-backend/overridable-functions.sh index 9b69f5098c..67ee2fd070 100644 --- a/.ci/openshift-ci/build-root/scripts/qs-overrides/todo-backend/overridable-functions.sh +++ b/.ci/openshift-ci/build-root/scripts/qs-overrides/todo-backend/overridable-functions.sh @@ -3,7 +3,7 @@ function installPrerequisites() echo "Adding bitnami repository" helm repo add bitnami https://charts.bitnami.com/bitnami - helm dependency update todo-backend-chart/ + helm dependency update charts/ } function helmInstall() { @@ -11,7 +11,7 @@ function helmInstall() { helm_set_arguments="$2" # TODO https://issues.redhat.com/browse/WFLY-18574 remove this when persistence is working - helm_set_arguments="${helm_set_arguments} --set postgresql.primary.persistence.enabled=false" + helm_set_arguments="${helm_set_arguments} -f .ci/openshift-ci/build-root/scripts/qs-overrides/todo-backend/ci.yaml" # Don't quote ${helm_set_arguments} as it breaks the command when empty, and seems to work without helm install "${application}" todo-backend-chart/ --wait --timeout="${helm_install_timeout}" ${helm_set_arguments} @@ -22,8 +22,7 @@ function helmInstall() { function cleanPrerequisites() { - oc delete all -l template=postgresql-ephemeral-template - oc delete secret todo-backend-db + helm uninstall "${application}" helm repo remove bitnami } diff --git a/.github/workflows/quickstart_todo-backend_ci.yml b/.github/workflows/quickstart_todo-backend_ci.yml new file mode 100644 index 0000000000..e7c41c5d35 --- /dev/null +++ b/.github/workflows/quickstart_todo-backend_ci.yml @@ -0,0 +1,16 @@ +name: WildFly Todo Backend Quickstart CI + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths: + - 'todo-backend/**' + - '.github/workflows/quickstart_ci.yml' +jobs: + call-quickstart_ci: + uses: ./.github/workflows/quickstart_ci.yml + with: + QUICKSTART_PATH: todo-backend + TEST_PROVISIONED_SERVER: true + TEST_OPENSHIFT: true + MATRIX_OS: "ubuntu-latest" \ No newline at end of file diff --git a/.github/workflows/quickstart_todo-backend_ci_before.sh b/.github/workflows/quickstart_todo-backend_ci_before.sh new file mode 100644 index 0000000000..0f39b829e4 --- /dev/null +++ b/.github/workflows/quickstart_todo-backend_ci_before.sh @@ -0,0 +1,2 @@ +#!/bin/sh +docker run --name todo-backend-db -e POSTGRES_USER=todos -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 postgres diff --git a/todo-backend/todo-backend-chart/.helmignore b/todo-backend/charts/.helmignore similarity index 100% rename from todo-backend/todo-backend-chart/.helmignore rename to todo-backend/charts/.helmignore diff --git a/todo-backend/todo-backend-chart/Chart.yaml b/todo-backend/charts/Chart.yaml similarity index 95% rename from todo-backend/todo-backend-chart/Chart.yaml rename to todo-backend/charts/Chart.yaml index 24bf941072..9dc0b43ca8 100644 --- a/todo-backend/todo-backend-chart/Chart.yaml +++ b/todo-backend/charts/Chart.yaml @@ -21,11 +21,12 @@ version: 1.0.0 # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "0.0.2" +appVersion: "0.0.3" dependencies: - name: postgresql repository: https://charts.bitnami.com/bitnami - version: 12.9.0 + version: 13.1.5 + #version: 12.9.0 - name: wildfly repository: http://docs.wildfly.org/wildfly-charts/ version: 2.3.2 \ No newline at end of file diff --git a/todo-backend/charts/values.yaml b/todo-backend/charts/values.yaml new file mode 100644 index 0000000000..c469db1371 --- /dev/null +++ b/todo-backend/charts/values.yaml @@ -0,0 +1,46 @@ +# Default values for todo-backend-chart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +postgresql: + auth: + username: todos-db + password: todos-db + database: todos-db + architecture: "standalone" + primary: + podSecurityContext: + enabled: false + fsGroup: "auto" + containerSecurityContext: + enabled: false + runAsUser: "auto" + runAsGroup: "" + + +wildfly: + build: + uri: https://github.com/wildfly/quickstart.git + ref: main + contextDir: todo-backend + deploy: + replicas: 1 + env: + # Env vars to connect to PostgreSQL DB + - name: POSTGRESQL_DATABASE + value: todos-db + - name: POSTGRESQL_USER + value: todos-db + - name: POSTGRESQL_PASSWORD + value: todos-db + - name: POSTGRESQL_DATASOURCE + value: ToDos + - name: POSTGRESQL_SERVICE_HOST + value: todo-backend-postgresql + - name: POSTGRESQL_SERVICE_PORT + value: "5432" + # Env to avoid OOME + - name: GC_MAX_METASPACE_SIZE + value: "256" + - name: GC_METASPACE_SIZE + value: "96" diff --git a/todo-backend/pom.xml b/todo-backend/pom.xml index 8180f97069..7638b4725f 100644 --- a/todo-backend/pom.xml +++ b/todo-backend/pom.xml @@ -44,14 +44,13 @@ - - 30.0.0.Final - 10.0.0.Final - 6.0.0.Final - 30.0.0.Final + 30.0.0.Final - 4.2.0.Final - 5.0.0.Final + + ${version.server} + 5.0.0.Final + 6.0.0.Final + 4.2.0.Final @@ -115,12 +114,23 @@ org.wildfly.bom wildfly-ee-with-tools - ${version.server.bom} + ${version.bom.ee} pom import + + + + + org.wildfly.plugins + wildfly-maven-plugin + ${version.plugin.wildfly} + + + + @@ -149,18 +159,9 @@ provided - junit - junit - test - - - org.jboss.arquillian.junit - arquillian-junit-container - test - - - org.jboss.arquillian.protocol - arquillian-protocol-servlet-jakarta + org.junit.jupiter + junit-jupiter-engine + 5.10.0 test @@ -178,115 +179,35 @@ provisioned-server - - - org.wildfly.arquillian - wildfly-arquillian-container-managed - test - - org.wildfly.plugins wildfly-maven-plugin - ${version.wildfly.maven.plugin} org.wildfly:wildfly-galleon-pack:${version.server} - org.wildfly - wildfly-datasources-galleon-pack - ${version.wildfly-datasources-galleon-pack} - - - - cloud-server - postgresql-datasource - - - - - - package - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - ${version.failsafe.plugin} - - - - integration-test - verify - - - - ${project.build.directory}/server - todos - localhost - 5432 - todos - mysecretpassword - ToDos - - - **/ProvisionedManagedToDoIT - - - **/RemoteToDoIT - - - - - - - - - - bootable-jar-openshift - - - ${project.artifactId} - - - org.wildfly.plugins - wildfly-jar-maven-plugin - ${version.wildfly-jar.maven.plugin} - - - - wildfly@maven(org.jboss.universe:community-universe)#${version.server.bootable-jar} - - - org.wildfly - wildfly-datasources-galleon-pack - ${version.wildfly-datasources-galleon-pack} + org.wildfly:wildfly-datasources-galleon-pack:${version.pack.datasources} - cloud-server postgresql-datasource - - - - - false - + + ROOT.war + + + - - - - - true - + + + false + + @@ -306,16 +227,16 @@ org.wildfly.plugins wildfly-maven-plugin - ${version.wildfly.maven.plugin} org.wildfly:wildfly-galleon-pack:${version.server} - org.wildfly - wildfly-datasources-galleon-pack - ${version.wildfly-datasources-galleon-pack} + org.wildfly:wildfly-datasources-galleon-pack:${version.pack.datasources} + + + org.wildfly.cloud:wildfly-cloud-galleon-pack:${version.pack.cloud} @@ -345,16 +266,7 @@ - - arq-remote - - - org.wildfly.arquillian - wildfly-arquillian-container-remote - test - - + integration-testing @@ -369,14 +281,6 @@ - - - **/RemoteToDoIT - - - **/ProvisionedManagedToDoIT - - diff --git a/todo-backend/src/test/java/org/wildfly/quickstarts/todos/AbstractToDoIT.java b/todo-backend/src/test/java/org/wildfly/quickstarts/todos/AbstractToDoIT.java deleted file mode 100644 index 76ed3dd64a..0000000000 --- a/todo-backend/src/test/java/org/wildfly/quickstarts/todos/AbstractToDoIT.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2022 Red Hat, Inc. - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.wildfly.quickstarts.todos; - -import jakarta.ws.rs.client.ClientBuilder; -import jakarta.ws.rs.client.Entity; -import jakarta.ws.rs.client.WebTarget; -import jakarta.ws.rs.core.GenericType; -import jakarta.ws.rs.core.MediaType; -import java.net.URL; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; - -/** - * - * @author Emmanuel Hugonnet (c) 2022 Red Hat, Inc. - */ -public abstract class AbstractToDoIT { - - abstract URL getRequestUrl(); - - public void internalCRUDTest() throws Exception { - WebTarget client = ((ResteasyClientBuilder) ClientBuilder.newBuilder()).setFollowRedirects(true).build().target(getRequestUrl().toURI()); - - GenericType> todosListType = new GenericType>() { - }; - List allTodos = client.request().get(todosListType); - assertEquals(0, allTodos.size()); - - ToDo toDo = new ToDo(); - toDo.setTitle("My First ToDo"); - toDo.setOrder(1); - ToDo persistedTodo = client.request().post(Entity.entity(toDo, MediaType.APPLICATION_JSON_TYPE), ToDo.class); - assertNotNull(persistedTodo.getId()); - - allTodos = client.request().get(todosListType); - assertEquals(1, allTodos.size()); - ToDo fetchedToDo = allTodos.get(0); - assertEquals(toDo.getTitle(), fetchedToDo.getTitle()); - - client.request().delete(); - - allTodos = client.request().get(todosListType); - assertEquals(0, allTodos.size()); - } -} diff --git a/todo-backend/src/test/java/org/wildfly/quickstarts/todos/ProvisionedManagedToDoIT.java b/todo-backend/src/test/java/org/wildfly/quickstarts/todos/ProvisionedManagedToDoIT.java deleted file mode 100644 index b0c48a7329..0000000000 --- a/todo-backend/src/test/java/org/wildfly/quickstarts/todos/ProvisionedManagedToDoIT.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2022 Red Hat, Inc. - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.wildfly.quickstarts.todos; - -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.junit.Arquillian; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * - * @author Emmanuel Hugonnet (c) 2022 Red Hat, Inc. - */ -@RunWith(Arquillian.class) -@RunAsClient -public class ProvisionedManagedToDoIT extends AbstractToDoIT { - - private static final String REST_TARGET_URL = "http://localhost:8080/todo-backend"; - - private String getServerHost() { - String host = System.getenv("SERVER_HOST"); - if (host == null) { - host = System.getProperty("server.host"); - } - return host; - } - - @Override - URL getRequestUrl() { - String host = getServerHost(); - if (host == null) { - host = REST_TARGET_URL; - } - try { - return new URI(host).toURL(); - } catch (URISyntaxException | MalformedURLException ex) { - throw new RuntimeException(ex); - } - } - - @Test - public void testCRUD() throws Exception { - super.internalCRUDTest(); - } -} diff --git a/todo-backend/src/test/java/org/wildfly/quickstarts/todos/RemoteToDoIT.java b/todo-backend/src/test/java/org/wildfly/quickstarts/todos/RemoteToDoIT.java index b223cb78e7..7d615f3bce 100644 --- a/todo-backend/src/test/java/org/wildfly/quickstarts/todos/RemoteToDoIT.java +++ b/todo-backend/src/test/java/org/wildfly/quickstarts/todos/RemoteToDoIT.java @@ -20,17 +20,26 @@ */ package org.wildfly.quickstarts.todos; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.MediaType; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import org.junit.Test; +import java.util.List; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import org.junit.jupiter.api.Test; /** * * @author Emmanuel Hugonnet (c) 2022 Red Hat, Inc. */ -public class RemoteToDoIT extends AbstractToDoIT { +public class RemoteToDoIT { private static final String REST_TARGET_URL = "http://localhost:8080/todo-backend"; @@ -42,7 +51,6 @@ private String getServerHost() { return host; } - @Override URL getRequestUrl() { String host = getServerHost(); if (host == null) { @@ -57,6 +65,27 @@ URL getRequestUrl() { @Test public void testCRUD() throws Exception { - super.internalCRUDTest(); + WebTarget client = ((ResteasyClientBuilder) ClientBuilder.newBuilder()).setFollowRedirects(true).build().target(getRequestUrl().toURI()); + + GenericType> todosListType = new GenericType>() { + }; + List allTodos = client.request().get(todosListType); + assertEquals(0, allTodos.size()); + + ToDo toDo = new ToDo(); + toDo.setTitle("My First ToDo"); + toDo.setOrder(1); + ToDo persistedTodo = client.request().post(Entity.entity(toDo, MediaType.APPLICATION_JSON_TYPE), ToDo.class); + assertNotNull(persistedTodo.getId()); + + allTodos = client.request().get(todosListType); + assertEquals(1, allTodos.size()); + ToDo fetchedToDo = allTodos.get(0); + assertEquals(toDo.getTitle(), fetchedToDo.getTitle()); + + client.request().delete(); + + allTodos = client.request().get(todosListType); + assertEquals(0, allTodos.size()); } } diff --git a/todo-backend/todo-backend-chart/values.yaml b/todo-backend/todo-backend-chart/values.yaml deleted file mode 100644 index 0ccdf6778e..0000000000 --- a/todo-backend/todo-backend-chart/values.yaml +++ /dev/null @@ -1,93 +0,0 @@ -# Default values for todo-backend-chart. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -postgresql: - auth: - username: todos-db - password: todos-db - database: todos-db - primary: - podSecurityContext: - enabled: false - fsGroup: "" - containerSecurityContext: - enabled: false - runAsUser: "auto" - persistence: - size: 2Gi - - readReplicas: - podSecurityContext: - enabled: false - fsGroup: "" - containerSecurityContext: - enabled: false - runAsUser: "auto" - persistence: - size: 2Gi - - volumePermissions: - enabled: false - securityContext: - runAsUser: "auto" - -wildfly: - build: - uri: https://github.com/wildfly/quickstart.git - ref: main - contextDir: todo-backend - deploy: - replicas: 1 - env: - # Env vars to connect to PostgreSQL DB - - name: POSTGRESQL_DATABASE - value: todos-db - - name: POSTGRESQL_USER - value: todos-db - - name: POSTGRESQL_PASSWORD - value: todos-db - - name: POSTGRESQL_DATASOURCE - value: ToDos - - name: POSTGRESQL_SERVICE_HOST - value: todo-backend-postgresql - - name: POSTGRESQL_SERVICE_PORT - value: "5432" - # Env vars to configure CORS filter - - name: FILTERS - value: acao, acam, acah, acac, acma - - name: acao_FILTER_RESPONSE_HEADER_NAME - value: Access-Control-Allow-Origin - - name: acao_FILTER_RESPONSE_HEADER_VALUE - value: "*" - - name: acao_FILTER_REF_NAME - value: Access-Control-Allow-Origin - - name: acam_FILTER_RESPONSE_HEADER_NAME - value: Access-Control-Allow-Methods - - name: acam_FILTER_RESPONSE_HEADER_VALUE - value: GET, POST, OPTION, PUT, DELETE, PATCH - - name: acam_FILTER_REF_NAME - value: Access-Control-Allow-Methods - - name: acah_FILTER_RESPONSE_HEADER_NAME - value: Access-Control-Allow-Headers - - name: acah_FILTER_RESPONSE_HEADER_VALUE - value: accept, authorization, content-type, x-requested-with - - name: acah_FILTER_REF_NAME - value: Access-Control-Allow-Headers - - name: acac_FILTER_RESPONSE_HEADER_NAME - value: Access-Control-Allow-Credentials - - name: acac_FILTER_RESPONSE_HEADER_VALUE - value: "true" - - name: acac_FILTER_REF_NAME - value: Access-Control-Allow-Credentials - - name: acma_FILTER_RESPONSE_HEADER_NAME - value: Access-Control-Max-Age - - name: acma_FILTER_RESPONSE_HEADER_VALUE - value: "1" - - name: acma_FILTER_REF_NAME - value: Access-Control-Max-Age - # Env to avoid OOME - - name: GC_MAX_METASPACE_SIZE - value: "256" - - name: GC_METASPACE_SIZE - value: "96" From fea3081ceecc0ab5d15c76d86c00d568c23dda00 Mon Sep 17 00:00:00 2001 From: Eduardo Martins Date: Mon, 27 Nov 2023 11:49:43 +0000 Subject: [PATCH 2/2] [WFLY-18512] todo-backend README fixes --- ...gration-tests-with-provisioned-server.adoc | 6 +- todo-backend/README.adoc | 363 ++---------------- todo-backend/pom.xml | 11 + .../quickstarts/todos/RemoteToDoIT.java | 6 +- .../src/test/resources/arquillian.xml | 36 -- 5 files changed, 45 insertions(+), 377 deletions(-) delete mode 100644 todo-backend/src/test/resources/arquillian.xml diff --git a/shared-doc/run-integration-tests-with-provisioned-server.adoc b/shared-doc/run-integration-tests-with-provisioned-server.adoc index d13d3bd69f..00d8e8565b 100644 --- a/shared-doc/run-integration-tests-with-provisioned-server.adoc +++ b/shared-doc/run-integration-tests-with-provisioned-server.adoc @@ -24,6 +24,8 @@ ifndef::server_provisioning_server_host[] :server_provisioning_server_host: http://localhost:8080 endif::server_provisioning_server_host[] +ifndef::extraStartParams[:extraStartParams: ] + The integration tests included with this quickstart, which verify that the quickstart runs correctly, may also be run with a provisioned server. Follow these steps to run the integration tests. @@ -62,13 +64,13 @@ endif::[] ifndef::deploymentDir[] [source,subs="attributes+",options="nowrap"] ---- -$ mvn wildfly:start -DjbossHome=target/server +$ mvn wildfly:start -DjbossHome=target/server {extraStartParams} ---- endif::[] ifdef::deploymentDir[] [source,subs="attributes+",options="nowrap"] ---- -$ mvn -f {deploymentDir}/pom.xml wildfly:start -DjbossHome={deploymentDir}/target/server +$ mvn -f {deploymentDir}/pom.xml wildfly:start -DjbossHome={deploymentDir}/target/server {extraStartParams} ---- endif::[] diff --git a/todo-backend/README.adoc b/todo-backend/README.adoc index ff42fe6381..c460ed6c3f 100644 --- a/todo-backend/README.adoc +++ b/todo-backend/README.adoc @@ -9,6 +9,7 @@ include::../shared-doc/attributes.adoc[] :level: Intermediate :technologies: JPA, JAX-RS, OpenShift, Galleon :openshift: true +:archiveType: war [abstract] The `todo-backend` quickstart demonstrates how to implement a backend that exposes a HTTP API with JAX-RS @@ -32,13 +33,13 @@ to manage a list of ToDo which are persisted in a database with `JPA`. * The backend exposes a HTTP API to manage a list of todos that complies with the specs defined at https://todobackend.com/specs/index.html[todobackend.com]. * It requires a connection to a PostgreSQL database to persist the todos. ifndef::ProductRelease[] -* It uses the Bootable Jar for local and cloud deployment +* It uses the Server Provisioning for local and cloud deployment endif::[] * It can be build with {productName} S2I images for cloud deployment -ifndef::ProductRelease,EAPXPRelease[] +ifndef::ProductRelease[] * It is deployed on OpenShift using the https://docs.wildfly.org/wildfly-charts/[Helm Chart for {productName}]. endif::[] -ifdef::ProductRelease,EAPXPRelease[] +ifdef::ProductRelease[] * It is deployed on OpenShift using the https://jbossas.github.io/eap-charts//[Helm Chart for {productName}]. endif::[] @@ -47,93 +48,11 @@ include::../shared-doc/system-requirements.adoc[leveloffset=+1] == Architecture -ifndef::ProductRelease,EAPXPRelease[] - -=== Architecture with Bootable Jar - -This backend is built and deployed as Bootable Jar that provisions the {productName} application server and all the feature packs it needs for its features. -The layers are defined in the `pom.xml` file in the `` section of the `org.wildfly.plugins:wildfly-jar-maven-plugin` plugin: - -[source,xml] ----- - - cloud-server - postgresql-datasource - ----- - -The `cloud-server` layer provides everything needed to run the backend on OpenShift. This also includes access to -Jakarta EE APIs such as CDI, JAX-RS, JPA, etc. These two layers comes from the {productName} feature pack provided by the Bootable Jar plugin: - -[source,xml] ----- - - wildfly@maven(org.jboss.universe:community-universe)#${version.server.bootable-jar} - ----- - -The `postgresql-datasource` layer provides a JDBC driver and DataSource to connect to a PostgreSQL database. It is not provided -by the {productName} feature pack but by an extra feature pack: - -[source,xml] ----- - - org.wildfly - wildfly-datasources-galleon-pack - ${version.wildfly-datasources-galleon-pack} - ----- - -The Git repository for this feature pack is hosted at https://github.com/wildfly-extras/wildfly-datasources-galleon-pack. -It provides JDBC drivers and datasources for different databases but for this quickstart, we will only need the `postgresql-datasource`. -endif::[] - -ifdef::EAPXPRelease[] - -=== Architecture with Bootable Jar - -This backend is built and deployed as Bootable Jar that provisions the {productName} application server and all the feature packs it needs for its features. -The layers are defined in the `pom.xml` file in the `` section of the `org.wildfly.plugins:wildfly-jar-maven-plugin` plugin: - -[source,xml] ----- - - cloud-server - postgresql-datasource - ----- - -The `cloud-server` layer provides everything needed to run the backend on OpenShift. This also includes access to -Jakarta EE APIs such as CDI, JAX-RS, JPA, etc. These two layers comes from the {productName} feature pack provided by the Bootable Jar plugin: - -[source,xml] ----- - - org.jboss.eap:wildfly-galleon-pack:${version.server.bootable-jar} - ----- - -The `postgresql-datasource` layer provides a JDBC driver and DataSource to connect to a PostgreSQL database. It is not provided -by the {productName} feature pack but by an extra feature pack: - -[source,xml] ----- - - org.jboss.eap - eap-datasources-galleon-pack - ${version.eap-datasources-galleon-pack} - ----- - -The Git repository for this feature pack is hosted at https://github.com/jbossas/eap-datasources-galleon-pack. -It provides JDBC drivers and datasources for different databases but for this quickstart, we will only need the `postgresql-datasource`. -endif::[] - === Architecture with S2I This backend is built using {productName} S2I Builder and Runtime images. -ifndef::ProductRelease,EAPXPRelease[] +ifndef::ProductRelease[] When the image is built, `org.wildfly.plugins:wildfly-maven-plugin` plugin provisions the {productName} application server and all the feature packs it needs for its features. The layers are defined in the `pom.xml` file in the `` section of the `org.wildfly.plugins:wildfly-maven-plugin` plugin: @@ -159,24 +78,11 @@ The layers are defined in the `pom.xml` file in the `` section of ---- endif::[] -ifdef::EAPXPRelease[] -When the image is built, it provisions the {productName} application server and all the feature packs it needs for its features: - -[source,yaml] ----- -build: - s2i: - galleonLayers: - - cloud-server - - postgresql-datasource ----- -endif::[] - The `cloud-server` layer provides everything needed to run the backend on OpenShift. This also includes access to Jakarta EE APIs such as CDI, JAX-RS, JPA, etc. These two layers comes from the {productName} feature pack provided in the {productName} S2I builder image. -ifndef::ProductRelease,EAPXPRelease[] +ifndef::ProductRelease[] The `postgresql-datasource` layer provides a JDBC driver and DataSource to connect to a PostgreSQL database. It is also provided by `org.wildfly:wildfly-datasources-galleon-pack` which is included in the WildFly S2I image. @@ -184,7 +90,7 @@ The Git repository for this feature pack is hosted at https://github.com/wildfly It provides JDBC drivers and datasources for different databases but for this quickstart, we will only need the `postgresql-datasource`. endif::[] -ifdef::ProductRelease,EAPXPRelease[] +ifdef::ProductRelease[] The `postgresql-datasource` layer provides a JDBC driver and DataSource to connect to a PostgreSQL database. It is also provided by the `org.jboss.eap:eap-datasources-galleon-pack` feature pack. @@ -192,14 +98,13 @@ The Git repository for this feature pack is hosted at https://github.com/jbossas It provides JDBC drivers and datasources for different databases but for this quickstart, we will only need the `postgresql-datasource`. endif::[] - === Connection to the PostgreSQL database -ifndef::ProductRelease,EAPXPRelease[] +ifndef::ProductRelease[] As mentioned, the JDBC drivers and datasource configuration that the backend uses to connect to the PostgreSQL database is provided by the `org.wildfly:wildfly-datasources-galleon-pack` feature pack. endif::[] -ifdef::ProductRelease,EAPXPRelease[] +ifdef::ProductRelease[] As mentioned, the JDBC drivers and datasource configuration that the backend uses to connect to the PostgreSQL database is provided by the `org.jboss.eap:eap-datasources-galleon-pack` feature pack. endif::[] @@ -228,12 +133,6 @@ The Web frontend for this quickstart uses JavaScript calls to query the backend' We must enable Cross-Origin Resource Sharing (CORS) filters in the `undertow` subsystem of {productName} to allow these HTTP requests to succeed. -ifndef::ProductRelease[] -==== Configuration with Bootable Jar - -As we use Bootable Jar to build the application, we provide a CLI script that contains all the commands to create and configure the CORS filters in Undertow. This script is located in the `src/scripts/cors_filters.cli`. -endif::[] - ifdef::ProductRelease[] ==== Configuration with {productName} S2I @@ -252,67 +151,6 @@ By default, the backend accepts requests from any origin (`*`). This is only sim the allowed origin using the environment variable `CORS_ORIGIN` at runtime. ifndef::ProductRelease[] -== Run the Backend Locally as a Bootable Jar - -=== Package the Backend as a Bootable Jar - -The backend is packaged as a Bootable Jar and configured to be deployable on OpenShift with the Maven Profile `bootable-jar-openshift`: - -[source,options="nowrap"] ----- -$ mvn clean package -P bootable-jar-openshift ----- - -=== Run a Local PostgreSQL Database - -Before running the backend locally, we need to have a local PostgreSQL database that we can connect to. -We use the `postgresql` docker image to create one: - -[source,options="nowrap"] ----- -$ docker run --name todo-backend-db \ - -e POSTGRES_USER=todos \ - -e POSTGRES_PASSWORD=mysecretpassword \ - -p 5432:5432 \ - postgres ----- - -This will create a database named `todos` that we can connect to on `localhost:5432` with the credentials `todos / mysecretpassword`. - -=== Run the Bootable Jar Application - -With the PostgreSQL database running, we can start the backend by passing the required environment variables to connect to the database: - -[source,options="nowrap"] ----- -$ POSTGRESQL_DATABASE=todos \ - POSTGRESQL_SERVICE_HOST=localhost \ - POSTGRESQL_SERVICE_PORT=5432 \ - POSTGRESQL_USER=todos \ - POSTGRESQL_PASSWORD=mysecretpassword \ - POSTGRESQL_DATASOURCE=ToDos \ - java -jar target/todo-backend-bootable.jar -... -14:41:58,111 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0010: Deployed "todo-backend.war" (runtime-name : "ROOT.war") -... ----- - -The backend is running, and we can use the HTTP API to manage a list of todos: - -[source,options="nowrap"] ----- -# get a list of todos -$ curl http://localhost:8080 -[] - -# create a todo with the title "This is my first todo item!" -$ curl -X POST -H "Content-Type: application/json" -d '{"title": "This is my first todo item!"}' http://localhost:8080/ -{"completed":false,"id":1,"order":0,"title":"This is my first todo item!","url":"https://localhost:8080/1"}% - -# get a list of todos with the one that was just created -$ curl http://localhost:8080 -[{"completed":false,"id":1,"order":0,"title":"This is my first todo item!","url":"https://localhost:8080/1"}] ----- == Run the Backend Locally @@ -325,17 +163,6 @@ The backend is packaged and deployed on a provisioned server: $ mvn clean package -Pprovisioned-server ---- -[NOTE] -==== -To execute the integration tests require *a running PostgreSQL server*. + -If you have already started the PostgreSQL server and want to run the tests you need to execute the following command: - -[source,options="nowrap"] ----- -$ mvn clean verify -Pprovisioned-server ----- -==== - === Run a Local PostgreSQL Database Before running the backend locally, we need to have a local PostgreSQL database that we can connect to. @@ -343,11 +170,7 @@ We use the `postgresql` docker image to create one: [source,options="nowrap"] ---- -$ docker run --name todo-backend-db \ - -e POSTGRES_USER=todos \ - -e POSTGRES_PASSWORD=mysecretpassword \ - -p 5432:5432 \ - postgres +$ docker run --name todo-backend-db -e POSTGRES_USER=todos -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 postgres ---- This will create a database named `todos` that we can connect to on `localhost:5432` with the credentials `todos / mysecretpassword`. @@ -358,17 +181,7 @@ With the PostgreSQL database running, we can start the backend by passing the re [source,options="nowrap"] ---- -$ JBOSS_HOME=./target/server \ - POSTGRESQL_DATABASE=todos \ - POSTGRESQL_SERVICE_HOST=localhost \ - POSTGRESQL_SERVICE_PORT=5432 \ - POSTGRESQL_USER=todos \ - POSTGRESQL_PASSWORD=mysecretpassword \ - POSTGRESQL_DATASOURCE=ToDos \ - ./target/server/bin/standalone.sh -... -14:41:58,111 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0010: Deployed "todo-backend.war" (runtime-name : "todo-backend.war") -... +$ ./target/server/bin/standalone.sh -Denv.POSTGRESQL_DATABASE=todos -Denv.POSTGRESQL_DATASOURCE=ToDos -Denv.POSTGRESQL_SERVICE_HOST=localhost -Denv.POSTGRESQL_SERVICE_PORT=5432 -Denv.POSTGRESQL_USER=todos -Denv.POSTGRESQL_PASSWORD=mysecretpassword ---- The backend is running, and we can use the HTTP API to manage a list of todos: @@ -376,26 +189,20 @@ The backend is running, and we can use the HTTP API to manage a list of todos: [source,options="nowrap"] ---- # get a list of todos -$ curl http://localhost:8080/todo-backend +$ curl http://localhost:8080 [] # create a todo with the title "This is my first todo item!" -$ curl -X POST -H "Content-Type: application/json" -d '{"title": "This is my first todo item!"}' http://localhost:8080/todo-backend -{"completed":false,"id":1,"order":0,"title":"This is my first todo item!","url":"https://localhost:8080/todo-backend/1"}% +$ curl -X POST -H "Content-Type: application/json" -d '{"title": "This is my first todo item!"}' http://localhost:8080 +{"completed":false,"id":1,"order":0,"title":"This is my first todo item!","url":"https://localhost:8080/1"}% # get a list of todos with the one that was just created -$ curl http://localhost:8080/todo-backend -[{"completed":false,"id":1,"order":0,"title":"This is my first todo item!","url":"https://localhost:8080/todo-backend/1"}] +$ curl http://localhost:8080 +[{"completed":false,"id":1,"order":0,"title":"This is my first todo item!","url":"https://localhost:8080/1"}] ---- -// Run the Arquillian Tests -include::../shared-doc/run-arquillian-functional-tests-remote.adoc[leveloffset=+1] - -[NOTE] -==== -You may also execute those tests against a running bootable jar application, but you will need to add `-Dserver.host=http://localhost:8080` to the command. -==== -endif::[] +:extraStartParams: -DPOSTGRESQL_DATABASE=todos -DPOSTGRESQL_SERVICE_HOST=localhost -DPOSTGRESQL_SERVICE_PORT=5432 -DPOSTGRESQL_USER=todos -DPOSTGRESQL_PASSWORD=mysecretpassword -DPOSTGRESQL_DATASOURCE=ToDos +include::../shared-doc/run-integration-tests-with-provisioned-server.adoc[leveloffset=+1] == Run the Backend on OpenShift @@ -408,7 +215,7 @@ include::../shared-doc/build-the-quickstart-for-openshift.adoc[leveloffset=+1] Once you have installed Helm, you need to add the repository that provides Helm Charts for {productName}: -ifndef::ProductRelease,EAPXPRelease[] +ifndef::ProductRelease[] [source,options="nowrap"] ---- $ helm repo add wildfly https://docs.wildfly.org/wildfly-charts/ @@ -419,7 +226,7 @@ wildfly/wildfly ... ... Build and Deploy WildFly wildfly/wildfly-common ... ... A library chart for WildFly-based applications ---- endif::[] -ifdef::ProductRelease,EAPXPRelease[] +ifdef::ProductRelease[] [source,options="nowrap",subs="+attributes"]] ---- $ helm repo add jboss-eap https://jbossas.github.io/eap-charts/ @@ -430,113 +237,13 @@ NAME CHART VERSION APP VERSION DESCRIPTION ---- endif::[] -ifndef::ProductRelease[] -=== Build and Deploy the Backend on OpenShift with Bootable Jar -endif::[] - -==== Deploy a PostgreSQL Database on OpenShift - -[source,options="nowrap"] ----- -$ oc new-app postgresql-ephemeral \ - -p DATABASE_SERVICE_NAME=todo-backend-db \ - -p POSTGRESQL_DATABASE=todos ----- - -This will create a PostgreSQL database named `todos` on OpenShift that can be accessed on the port `5432` on the service `todo-backend-db`. -We don't need to copy the credentials to connect to the database as we will retrieve them later using the `todo-backend-db` secret that was created -when the database is deployed. - -ifndef::ProductRelease,EAPXPRelease[] -==== Build and Deploy the Backend on OpenShift with Bootable Jar using the Helm Chart - -The backend will be built and deployed on OpenShift with a Helm Chart for {productName}. - -[source,options="nowrap",subs="+attributes"] ----- -$ helm install todo-backend --set build.ref={WildFlyQuickStartRepoTag} -f https://raw.githubusercontent.com/wildfly/wildfly-charts/main/examples/todo-backend/todo-backend-bootable-jar.yaml {helmChartName} -NAME: todo-backend -... -STATUS: deployed -REVISION: 1 ----- - -The Helm Chart for this quickstart contains all the information to build an image from the source code using Bootable Jar: - -[source,options="nowrap"] ----- -build: - uri: https://github.com/wildfly/quickstart.git - mode: bootable-jar ----- -endif::[] - -ifdef::EAPXPRelease[] -The backend will be built and deployed on OpenShift with a Helm Chart for {productName}. - -[source,options="nowrap",subs="+attributes"] ----- -$ helm install todo-backend --set build.ref={EAPQuickstartRepoTag} -f https://raw.githubusercontent.com/jbossas/eap-charts/main/examples/eap-xp3/todo-backend/todo-backend-bootable-jar.yaml {helmChartName} -NAME: todo-backend -... -STATUS: deployed -REVISION: 1 ----- - -The Helm Chart for this quickstart contains all the information to build an image from the source code using Bootable Jar: - -[source,options="nowrap"] ----- -build: - uri: https://github.com/jboss-developer/jboss-eap-quickstarts.git - mode: bootable-jar ----- -endif::[] - -ifndef::ProductRelease[] - -This will create a new deployment on OpenShift and deploy the application. - -If you want to see all the configuration elements to customize your deployment you can use the following command: -[source,options="nowrap",subs="+attributes"] ----- -$ helm show readme {helmChartName} ----- - -Let’s wait for the application to be built and deployed: -[source,options="nowrap",subs="+attributes"] ----- -$ oc get deployment {artifactId} -w -NAME READY UP-TO-DATE AVAILABLE AGE -{artifactId} 0/1 1 0 31s -... -{artifactId} 1/1 1 1 4m31s ----- - -endif::[] - ifndef::ProductRelease[] === Build and Deploy the Backend on OpenShift with {productName} S2I endif::[] The backend will be built and deployed on OpenShift with a Helm Chart for {productName}. -ifdef::EAPXPRelease[] -==== Deploy a PostgreSQL Database on OpenShift - -[source,options="nowrap"] ----- -$ oc new-app postgresql-ephemeral \ - -p DATABASE_SERVICE_NAME=todo-backend-db \ - -p POSTGRESQL_DATABASE=todos ----- - -This will create a PostgreSQL database named `todos` on OpenShift that can be accessed on the port `5432` on the service `todo-backend-db`. -We don't need to copy the credentials to connect to the database as we will retrieve them later using the `todo-backend-db` secret that was created -when the database is deployed. -endif::[] - -ifndef::ProductRelease,EAPXPRelease[] +ifndef::ProductRelease[] Add the bitnami repository which provides an helm chart for PostgreSQL: [source,options="nowrap"] ---- @@ -548,16 +255,14 @@ Install the full application (database + backend). [source,options="nowrap",subs="+attributes"] ---- -$ helm dependency update todo-backend-chart/ -$ helm install todo-backend todo-backend-chart/ +$ helm dependency update charts/ +$ helm install todo-backend charts/ NAME: todo-backend ... STATUS: deployed REVISION: 1 ---- -endif::[] -ifndef::ProductRelease,EAPXPRelease[] The Helm Chart for this quickstart contains all the information to build an image from the source code using S2I and install it with the database: [source,options="nowrap"] @@ -573,7 +278,7 @@ dependencies: endif::[] -ifndef::ProductRelease,EAPXPRelease[] +ifndef::ProductRelease[] Any configuration specified by this chart is described in its README that is displayed in OpenShift Dev console or using the command: @@ -595,7 +300,7 @@ NAME READY UP-TO-DATE AVAILABLE AGE endif::[] -ifdef::ProductRelease,EAPXPRelease[] +ifdef::ProductRelease[] //Prepare Helm for Quickstart Deployment include::../shared-doc/helm-deploy-project.adoc[leveloffset=+1] @@ -627,7 +332,7 @@ When the application is deployed, the value for the `POSTGRESQL_PASSWORD` will b in the secret `todo-backend-db`. // Testing on Openshift -include::../shared-doc/run-arquillian-integration-tests-with-openshift.adoc[leveloffset=+2] +include::../shared-doc/run-integration-tests-with-openshift.adoc[leveloffset=+1] === Use the todobackend Web Frontend @@ -671,26 +376,12 @@ $ helm uninstall todo-backend release "todo-backend" uninstalled ---- -==== Remove the Database - -The PostresSQL database can be deleted from OpenShift by running the commands: - -[source,options="nowrap"] ----- -$ oc delete all -l template=postgresql-ephemeral-template -replicationcontroller "todo-backend-db-1" deleted -service "todo-backend-db" deleted -deploymentconfig.apps.openshift.io "todo-backend-db" deleted -$ oc delete secret todo-backend-db -secret "todo-backend-db" deleted ----- - == Conclusion This quickstart shows how the datasource feature pack provided by {productName} simplifies the deployment of a {productName} Jakarta EE backend on OpenShift to connect to an external database and exposes an HTTP API. ifndef::ProductRelease[] -The use of a Bootable Jar deployment makes it seamless to move from a local deployment for development to a +The use of a Server Provisioned deployment makes it seamless to move from a local deployment for development to a deployment on OpenShift. endif::[] \ No newline at end of file diff --git a/todo-backend/pom.xml b/todo-backend/pom.xml index 7638b4725f..a1632939a1 100644 --- a/todo-backend/pom.xml +++ b/todo-backend/pom.xml @@ -127,6 +127,17 @@ org.wildfly.plugins wildfly-maven-plugin ${version.plugin.wildfly} + + + + ${POSTGRESQL_DATABASE} + ${POSTGRESQL_SERVICE_HOST} + ${POSTGRESQL_SERVICE_PORT} + ${POSTGRESQL_USER} + ${POSTGRESQL_PASSWORD} + ${POSTGRESQL_DATASOURCE} + + diff --git a/todo-backend/src/test/java/org/wildfly/quickstarts/todos/RemoteToDoIT.java b/todo-backend/src/test/java/org/wildfly/quickstarts/todos/RemoteToDoIT.java index 7d615f3bce..617683e7d6 100644 --- a/todo-backend/src/test/java/org/wildfly/quickstarts/todos/RemoteToDoIT.java +++ b/todo-backend/src/test/java/org/wildfly/quickstarts/todos/RemoteToDoIT.java @@ -70,7 +70,7 @@ public void testCRUD() throws Exception { GenericType> todosListType = new GenericType>() { }; List allTodos = client.request().get(todosListType); - assertEquals(0, allTodos.size()); + int initialSize = allTodos.size(); ToDo toDo = new ToDo(); toDo.setTitle("My First ToDo"); @@ -79,8 +79,8 @@ public void testCRUD() throws Exception { assertNotNull(persistedTodo.getId()); allTodos = client.request().get(todosListType); - assertEquals(1, allTodos.size()); - ToDo fetchedToDo = allTodos.get(0); + assertEquals(initialSize+1, allTodos.size()); + ToDo fetchedToDo = allTodos.get(initialSize); assertEquals(toDo.getTitle(), fetchedToDo.getTitle()); client.request().delete(); diff --git a/todo-backend/src/test/resources/arquillian.xml b/todo-backend/src/test/resources/arquillian.xml deleted file mode 100644 index fdeb809fee..0000000000 --- a/todo-backend/src/test/resources/arquillian.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file