diff --git a/samples/quickstart/app/pom.xml b/samples/quickstart/app/pom.xml new file mode 100644 index 000000000..5492a3ea3 --- /dev/null +++ b/samples/quickstart/app/pom.xml @@ -0,0 +1,72 @@ + + + + + 4.0.0 + + com.oracle.weblogic.example + todo + 0.1-SNAPSHOT + war + todo + + + UTF-8 + 1.8 + 1.8 + + + + + javax.ws.rs + javax.ws.rs-api + 2.1.1 + provided + + + javax.json + javax.json-api + 1.1.4 + provided + + + + + todo + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.2.1 + + + enforce-build-environment + + enforce + + + + + 1.8.0 + You must use JDK 8 to build the project WebLogic 12.2.1.4 only supports JDK 8 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + + diff --git a/samples/quickstart/app/src/main/java/org/todo/services/TodoListApplication.java b/samples/quickstart/app/src/main/java/org/todo/services/TodoListApplication.java new file mode 100644 index 000000000..b46bc0c06 --- /dev/null +++ b/samples/quickstart/app/src/main/java/org/todo/services/TodoListApplication.java @@ -0,0 +1,22 @@ +// Copyright (c) 2020, 2023, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +package org.todo.services; + +import java.util.HashSet; +import java.util.Set; +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +import org.todo.services.resource.ItemResource; +import org.todo.services.resource.ItemsResource; + +@ApplicationPath("/rest") +public class TodoListApplication extends Application { + public Set> getClasses() { + Set> s = new HashSet<>(); + s.add(ItemsResource.class); + s.add(ItemResource.class); + return s; + } +} diff --git a/samples/quickstart/app/src/main/java/org/todo/services/entity/Item.java b/samples/quickstart/app/src/main/java/org/todo/services/entity/Item.java new file mode 100644 index 000000000..9c32658b8 --- /dev/null +++ b/samples/quickstart/app/src/main/java/org/todo/services/entity/Item.java @@ -0,0 +1,48 @@ +// Copyright (c) 2020, 2023, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +package org.todo.services.entity; + +import javax.json.Json; +import javax.json.JsonObject; + +public class Item { + private int key; + private String description; + private boolean complete; + + public Item(int id) { + key = id; + complete = false; + } + + public int id() { + return key; + } + + public String desc() { + return description; + } + + public Item desc(String value) { + description = value; + return this; + } + + public boolean done() { + return complete; + } + + public Item done(boolean value) { + complete = value; + return this; + } + + public JsonObject toJson() { + return Json.createObjectBuilder() + .add("id", id()) + .add( "description", desc()) + .add( "done", done()) + .build(); + } +} diff --git a/samples/quickstart/app/src/main/java/org/todo/services/resource/ItemResource.java b/samples/quickstart/app/src/main/java/org/todo/services/resource/ItemResource.java new file mode 100644 index 000000000..c1e09ccb8 --- /dev/null +++ b/samples/quickstart/app/src/main/java/org/todo/services/resource/ItemResource.java @@ -0,0 +1,77 @@ +// Copyright (c) 2020, 2023, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +package org.todo.services.resource; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import javax.json.JsonObject; +import javax.naming.NamingException; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.todo.services.entity.Item; + +@Path("/item") +public class ItemResource { + + public final static String selectSql = "select task, completed from ToDos where taskId = %s"; + public final static String deleteSql = "delete from ToDos where taskId = %s"; + public final static String insertSql = "insert into ToDos(task, completed) values('%s', false);"; + public final static String updateSql = "update ToDos set completed = %s where taskId = %s"; + + @GET + @Path("/{id}") + @Produces("application/json") + public JsonObject item(@PathParam("id") String id) { + Item result = null; + try (Connection conn = ItemsResource.datasource().getConnection()) { + Statement statement = conn.createStatement(); + String queryStr = String.format(selectSql, id); + System.out.println(queryStr); + ResultSet resultSet = statement.executeQuery(queryStr); + if (resultSet.next()) { + String task = resultSet.getString("task"); + boolean complete = resultSet.getBoolean("completed"); + result = new Item(Integer.parseInt(id)).desc(task).done(complete); + } + } catch (SQLException | NamingException ex) { + ex.printStackTrace(); + } + return result == null ? null : result.toJson(); + } + + @DELETE + @Path("/{id}") + public void delete(@PathParam("id") String id) { + runQuery(String.format(deleteSql, id)); + } + + @PUT + @Path("/{taskDescription}") + public void addNewItem(@PathParam("taskDescription") String description) { + runQuery(String.format(insertSql, description)); + } + + @PUT + @Path("/{id}/{status}") + public void updateStatus(@PathParam("id") String id, @PathParam("status") String status) { + runQuery(String.format(updateSql, id, status)); + } + + private void runQuery(String query) { + try (Connection conn = ItemsResource.datasource().getConnection()) { + Statement statement = conn.createStatement(); + System.out.println(query); + statement.executeUpdate(query); + } catch (SQLException | NamingException ex) { + ex.printStackTrace(); + } + } +} diff --git a/samples/quickstart/app/src/main/java/org/todo/services/resource/ItemsResource.java b/samples/quickstart/app/src/main/java/org/todo/services/resource/ItemsResource.java new file mode 100644 index 000000000..e8f7976cf --- /dev/null +++ b/samples/quickstart/app/src/main/java/org/todo/services/resource/ItemsResource.java @@ -0,0 +1,114 @@ +// Copyright (c) 2020, 2023, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +package org.todo.services.resource; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import javax.json.Json; +import javax.json.JsonArray; +import javax.json.JsonArrayBuilder; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.sql.DataSource; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.todo.services.entity.Item; + +/** + * REST service for the To-Do list application using MySQL DB. + * /items retrieves the full list of tasks + * /items/init drops the table, creates the table, and loads the table with some starting tasks + */ +@Path("/items/") +@Produces(MediaType.APPLICATION_JSON) +public class ItemsResource { + + public static DataSource datasource() throws NamingException { + InitialContext ctx = new InitialContext(); + return (DataSource) ctx.lookup("jdbc/ToDoDB"); + } + + public List items() { + List result = new ArrayList<>(); + + try (Connection conn = datasource().getConnection()){ + Statement statement = conn.createStatement(); + ResultSet resultSet = statement.executeQuery("select taskId, task, completed from ToDos"); + while (resultSet.next()) { + int id = resultSet.getInt("taskId"); + String task = resultSet.getString("task"); + boolean complete = resultSet.getBoolean("completed"); + result.add(new Item(id).desc(task).done(complete)); + } + } catch (SQLException | NamingException ex) { + ex.printStackTrace(); + } + return result; + } + + @GET + public JsonArray itemsJson() { + JsonArrayBuilder result = Json.createArrayBuilder(); + for (Item item : items()) { + result.add(item.toJson()); + } + return result.build(); + } + + @GET + @Path("/drop/") + @Produces(MediaType.TEXT_PLAIN) + public Response dropTable() { + try (Connection conn = datasource().getConnection()) { + Statement stmt = conn.createStatement(); + + String dropTable = "drop table ToDos;"; + System.out.println(dropTable); + stmt.executeUpdate(dropTable); + } catch (SQLException | NamingException ex) { + // ok to fail, table may not exist yet. + return Response.ok().entity(ex.getLocalizedMessage() + "\n").build(); + } + return Response.ok().entity("ToDos table dropped.\n").build(); + } + + @GET + @Path("/init/") + @Produces(MediaType.TEXT_PLAIN) + public Response initTable() { + dropTable(); + try (Connection conn = datasource().getConnection()){ + Statement stmt = conn.createStatement(); + + String createTable = "create table ToDos (" + + "taskId INT NOT NULL AUTO_INCREMENT, " + + "task VARCHAR(200) NOT NULL, " + + "completed BOOLEAN," + + "constraint todo_pk PRIMARY KEY (taskId));"; + + System.out.println(createTable); + stmt.executeUpdate(createTable); + + String[] tasks = {"Install Verrazzano", "Move ToDo List to the cloud", "Celebrate", "Clean off my desk"}; + for (String task : tasks) { + String insert = String.format(ItemResource.insertSql, task); + System.out.println(insert); + stmt.executeUpdate(insert); + } + + } catch (SQLException | NamingException ex) { + ex.printStackTrace(); + return Response.serverError().entity("ERROR: " + ex.getLocalizedMessage() + "\n").build(); + } + return Response.ok().entity("ToDos table initialized.\n").build(); + } +} diff --git a/samples/quickstart/app/src/main/webapp/WEB-INF/web.xml b/samples/quickstart/app/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..a18010ce9 --- /dev/null +++ b/samples/quickstart/app/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,13 @@ + + + + + + Derek's ToDo List + + index.html + + diff --git a/samples/quickstart/app/src/main/webapp/css/todo-style.css b/samples/quickstart/app/src/main/webapp/css/todo-style.css new file mode 100644 index 000000000..19089bcc6 --- /dev/null +++ b/samples/quickstart/app/src/main/webapp/css/todo-style.css @@ -0,0 +1,111 @@ +/* Copyright (c) 2020, 2023, Oracle and/or its affiliates. */ +/* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. */ + +* { + box-sizing: border-box; +} + +/* Remove margins and padding from the list */ +ul { + margin: 0; + padding: 0; +} + +ul li { + cursor: pointer; + position: relative; + padding: 12px 8px 12px 40px; + background: #eee; + font-size: 18px; + transition: 0.2s; + + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +/* Zebra stripes in the list */ +ul li:nth-child(odd) { + background: #f9f9f9; +} + +/* Darker background on hover */ +ul li:hover { + background: #ddd; +} + +/* strikethrough and color when checked status */ +ul li.checked { + background: #888; + color: #fff; + text-decoration: line-through; +} + +/* Add a check mark when clicked */ +ul li.checked::before { + content: ''; + position: absolute; + border-color: #fff; + border-style: solid; + border-width: 0 2px 2px 0; + top: 10px; + left: 16px; + transform: rotate(45deg); + height: 15px; + width: 7px; +} + +.close { + position: absolute; + right: 0; + top: 0; + padding: 12px 16px 12px 16px; +} + +.close:hover { + background-color: red; + color: white; +} + +.header { + background-color: #ff9223; + padding: 30px 40px; + color: white; + text-align: center; +} + +.header:after { + content: ""; + display: table; + clear: both; +} + +/* Style the task input field */ +input { + margin: 0; + border: none; + border-radius: 0; + width: 75%; + padding: 10px; + float: left; + font-size: 16px; +} + +/* Style the "Add" button */ +.addBtn { + padding: 10px; + width: 25%; + background: #d9d9d9; + color: #555; + float: left; + text-align: center; + font-size: 16px; + cursor: pointer; + transition: 0.3s; + border-radius: 0; +} + +.addBtn:hover { + background-color: #bbb; +} diff --git a/samples/quickstart/app/src/main/webapp/index.html b/samples/quickstart/app/src/main/webapp/index.html new file mode 100644 index 000000000..ff38f9b42 --- /dev/null +++ b/samples/quickstart/app/src/main/webapp/index.html @@ -0,0 +1,140 @@ + + + + + + Derek's To-Do List + + + + +
+

Derek's To-Do List

+ + Add +
+ +
    +
+ + + + diff --git a/samples/quickstart/app/target/todo.war b/samples/quickstart/app/target/todo.war new file mode 100644 index 000000000..bb98847a3 Binary files /dev/null and b/samples/quickstart/app/target/todo.war differ diff --git a/samples/quickstart/scripts/local-domain/archive.zip b/samples/quickstart/scripts/local-domain/archive.zip new file mode 100644 index 000000000..6ea7cbe14 Binary files /dev/null and b/samples/quickstart/scripts/local-domain/archive.zip differ diff --git a/samples/quickstart/scripts/local-domain/createToDoListDomain.sh b/samples/quickstart/scripts/local-domain/createToDoListDomain.sh new file mode 100755 index 000000000..c1cf81114 --- /dev/null +++ b/samples/quickstart/scripts/local-domain/createToDoListDomain.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env sh +# +# Copyright (c) 2023, Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +# +# This script is used to create a local WebLogic Server domain to use for +# discovering the model section of the WKTUI Quickstart. +# + +BASEDIR="$( cd "$( dirname "$0" )" && pwd )" +if [ -z "${WKTUI_QS_HOME}" ]; then + WKTUI_QS_HOME="$( cd "${BASEDIR}/../.." && pwd )"; export WKTUI_QS_HOME +fi + +if [ -z "${JAVA_HOME}" ]; then + echo "JAVA_HOME environment variable must be set. Please edit and source the ${WKTUI_QS_HOME}/setQuickstartEnv.sh file" >&2 + exit 1 +elif [ ! -d "${JAVA_HOME}" ]; then + echo "JAVA_HOME directory ${JAVA_HOME} does not exist...exiting" >&2 + exit 1 +fi + +if [ -z "${ORACLE_HOME}" ]; then + echo "ORACLE_HOME environment variable must be set. Please edit and source the ${WKTUI_QS_HOME}/setQuickstartEnv.sh file" >&2 + exit 1 +elif [ ! -d "${ORACLE_HOME}" ]; then + echo "ORACLE_HOME directory ${ORACLE_HOME} does not exist...exiting" >&2 + exit 1 +fi + +if [ -z "${WLSDEPLOY_HOME}" ]; then + echo "WLSDEPLOY_HOME environment variable must be set. Please edit and source the ${WKTUI_QS_HOME}/setQuickstartEnv.sh file" >&2 + exit 1 +elif [ ! -d "${WLSDEPLOY_HOME}" ]; then + echo "WLSDEPLOY_HOME directory ${WLSDEPLOY_HOME} does not exist...exiting" >&2 + exit 1 +fi + +if [ -d "${WKTUI_QS_HOME}/todolist_domain" ]; then + if ! rm -rf "${WKTUI_QS_HOME}/todolist_domain"; then + echo "Failed to delete existing domain directory ${WKTUI_QS_HOME}/todolist_domain...exiting" >&2 + exit 1 + fi +fi + +if ! "${WLSDEPLOY_HOME}/bin/createDomain.sh" -oracle_home "${ORACLE_HOME}" \ + -domain_parent "${WKTUI_QS_HOME}" \ + -model_file "${BASEDIR}/model.yaml" \ + -variable_file "${BASEDIR}/variables.properties" \ + -archive_file "${BASEDIR}/archive.zip"; then + echo "" >&2 + echo "Failed to create the domain at ${WKTUI_QS_HOME}/todolist_domain...exiting" >&2 + echo "" >&2 + exit 1 +else + echo "" + echo "Successfully created the domain at ${WKTUI_QS_HOME}/todolist_domain" + echo "" +fi diff --git a/samples/quickstart/scripts/local-domain/model.yaml b/samples/quickstart/scripts/local-domain/model.yaml new file mode 100644 index 000000000..d6f9551c9 --- /dev/null +++ b/samples/quickstart/scripts/local-domain/model.yaml @@ -0,0 +1,54 @@ +# +# Copyright (c) 2023, Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +# +domainInfo: + AdminUserName: '@@PROP:WebLogicAdminUserName@@' + AdminPassword: '@@PROP:WebLogicAdminPassword@@' +topology: + Name: todolist_domain + ProductionModeEnabled: true + AdminServerName: AdminServer + Server: + AdminServer: + Cluster: + mycluster: + DynamicServers: + ServerTemplate: todo-srv-template + ServerNamePrefix: 'ToDoServer-' + DynamicClusterSize: 10 + MaxDynamicClusterSize: 10 + CalculatedListenPorts: false + MinDynamicClusterSize: 0 + ServerTemplate: + 'todo-srv-template': + ListenPortEnabled: true + Cluster: mycluster +resources: + JDBCSystemResource: + myDataSource: + JdbcResource: + JDBCDriverParams: + Properties: + user: + Value: weblogic + DriverName: com.mysql.cj.jdbc.Driver + URL: 'jdbc:mysql://localhost:3306/tododb' + PasswordEncrypted: welcome1 + JDBCDataSourceParams: + JNDIName: [ + jdbc/ToDoDB + ] + + DatasourceType: GENERIC + Target: [ + mycluster + ] + +appDeployments: + Application: + todo: + Target: [ + mycluster + ] + SourcePath: wlsdeploy/applications/todo.war diff --git a/samples/quickstart/scripts/local-domain/startMySQL.sh b/samples/quickstart/scripts/local-domain/startMySQL.sh new file mode 100755 index 000000000..e02f9f0bc --- /dev/null +++ b/samples/quickstart/scripts/local-domain/startMySQL.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env sh +# +# Copyright (c) 2023, Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +# +# This script starts up a MySQL database in a container using the +# host's networking (to make it simpler). There is no persistence +# directory so any changes made to the data can be reset by simply +# restarting the container. +# + +BASEDIR="$( cd "$( dirname "$0" )" && pwd )" +if [ -z "${WKTUI_QS_HOME}" ]; then + WKTUI_QS_HOME="$( cd "${BASEDIR}/../.." && pwd )"; export WKTUI_QS_HOME +fi + +if [ -z "${IMAGE_BUILDER_NAME}" ]; then + echo "IMAGE_BUILDER_NAME environment variable must be set. Please edit and source the ${WKTUI_QS_HOME}/setQuickstartEnv.sh file" >&2 + exit 1 +elif [ -z "${IMAGE_BUILDER_EXE}" ]; then + echo "IMAGE_BUILDER_EXE environment variable must be set. Please edit and source the ${WKTUI_QS_HOME}/setQuickstartEnv.sh file" >&2 + exit 1 +fi + +if [ -z "${ORCL_SSO_USER}" ]; then + printf "Please enter your Oracle SSO account username: " + read -r ORCL_SSO_USER + if [ -z "${ORCL_SSO_USER}" ]; then + echo "No Oracle SSO account username provided...exiting" >&2 + exit 1 + fi +fi + +if [ -z "${ORCL_SSO_PASS}" ]; then + stty -echo + printf "Please enter your Oracle SSO account password: " + read -r ORCL_SSO_USER + stty echo + if [ -z "${ORCL_SSO_PASS}" ]; then + echo "No Oracle SSO account password provided...exiting" >&2 + exit 1 + fi +fi + +if ! echo "${ORCL_SSO_PASS}" | "${IMAGE_BUILDER_EXE}" login container-registry.oracle.com \ + -u "${ORCL_SSO_USER}" --password-stdin; then + echo "Failed to ${IMAGE_BUILDER_NAME} login to container-registry.oracle.com...exiting" >&2 + exit 1 +fi + +if ! "${IMAGE_BUILDER_EXE}" run \ + --name=mysql \ + --network=host \ + -e MYSQL_ROOT_PASSWORD=manager1 \ + -e MYSQL_USER=weblogic \ + -e MYSQL_PASSWORD=welcome1 \ + -e MYSQL_DATABASE=tododb \ + --mount type=bind,src="${WKTUI_QS_HOME}/sql/",dst=/docker-entrypoint-initdb.d/ \ + -d container-registry.oracle.com/mysql/community-server:8.0.32; then + echo "Failed to start MySQL database container...exiting" >&2 + exit 1 +fi diff --git a/samples/quickstart/scripts/local-domain/variables.properties b/samples/quickstart/scripts/local-domain/variables.properties new file mode 100644 index 000000000..7b1584c0f --- /dev/null +++ b/samples/quickstart/scripts/local-domain/variables.properties @@ -0,0 +1,6 @@ +# +# Copyright (c) 2023, Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +# +WebLogicAdminUserName=weblogic +WebLogicAdminPassword=welcome1 diff --git a/samples/quickstart/scripts/vzDeployMySQL.ps1 b/samples/quickstart/scripts/vzDeployMySQL.ps1 new file mode 100755 index 000000000..e74f246b7 --- /dev/null +++ b/samples/quickstart/scripts/vzDeployMySQL.ps1 @@ -0,0 +1,257 @@ +<# + Copyright (c) 2023, Oracle and/or its affiliates. + Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +#> +$BASEDIR = $PSScriptRoot +if (-not $env:WKTUI_QS_HOME) { + $env:WKTUI_QS_HOME = (get-item $BASEDIR).parent.FullName +} + +$MYSQL_NAMESPACE = "todolist-domain-ns" +$SECRET_NAME = "ocr" +$MYSQL_SECRET_NAME = "mysql" +$MYSQL_ROOT_PASS_NAME = "rootPass" +$MYSQL_WL_USER_NAME = "username" +$MYSQL_WL_USER_PASS = "password" +$CONFIG_MAP_NAME = "todolist-mysql-cm" +$KUBECTL_EXE = (get-command kubectl.exe).Path + +if (-not $env:ORCL_SSO_USER) { + $env:ORCL_SSO_USER = Read-Host "Please enter your Oracle SSO account username: " + if (-not $env:ORCL_SSO_USER) { + Write-Error "No Oracle SSO account username provided...exiting" + exit 1 + } +} + +if (-not $env:ORCL_SSO_PASS) { + $ORCL_SSO_PASS = Read-Host "Please enter your Oracle SSO account password: " -AsSecureString + if (-not $ORCL_SSO_PASS) { + Write-Error "No Oracle SSO account password provided...exiting" + exit 1 + } + $env:ORCL_SSO_PASS = [Runtime.InteropServices.Marshal]::PtrToStringAuto( + [Runtime.InteropServices.Marshal]::SecureStringToBSTR($ORCL_SSO_PASS)) +} + +# +# Create namespace if it doesn't already exist +# + +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "get namespace $MYSQL_NAMESPACE" ` + -PassThru -RedirectStandardError "NUL" -RedirectStandardOutput "$env:TEMP\stdout" +Wait-Process -InputObject $proc +if ($proc.ExitCode -ne 0) { + Write-Output "MySQL image pull secret namespace $MYSQL_NAMESPACE does not exist...creating" + $proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList ` + "create namespace $MYSQL_NAMESPACE" -PassThru + Wait-Process -InputObject $proc + if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create MySQL image pull secret namespace $MYSQL_NAMESPACE...exiting" + exit 1 + } +} + +# +# Create the ocr image pull secret if it doesn't already exist +# + +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList ` + "get secret $SECRET_NAME -n $MYSQL_NAMESPACE" -PassThru -RedirectStandardError "NUL" ` + -RedirectStandardOutput "$env:TEMP\stdout" +Wait-Process -InputObject $proc +if ($proc.ExitCode -eq 0) { + Write-Output "MySQL image pull secret $SECRET_NAME already exists in namespace $MYSQL_NAMESPACE...skipping" +} else { + $argList = "create secret docker-registry $SECRET_NAME -n $MYSQL_NAMESPACE " ` + + "--docker-server=container-registry.oracle.com " ` + + "--docker-username=`"$env:ORCL_SSO_USER`" " ` + + "--docker-password=`"$env:ORCL_SSO_PASS`" " ` + + "--docker-email=`"$env:ORCL_SSO_USER`" " + + $proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "$argList" -PassThru + Wait-Process -InputObject $proc + if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create MySQL image pull secret $SECRET_NAME in namespace $MYSQL_NAMESPACE...exiting" + exit 1 + } +} + +# +# Create MySQL Secret to initialize MySQL user and password +# + +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList ` + "get secret $MYSQL_SECRET_NAME -n $MYSQL_NAMESPACE" -PassThru ` + -RedirectStandardError "NUL" -RedirectStandardOutput "$env:TEMP\stdout" +Wait-Process -InputObject $proc +if ($proc.ExitCode -eq 0) { + Write-Output "MySQL secret $MYSQL_SECRET_NAME already exists in namespace $MYSQL_NAMESPACE...skipping" +} else { + $argList = "create secret generic $MYSQL_SECRET_NAME -n $MYSQL_NAMESPACE " ` + + "--from-literal=$MYSQL_ROOT_PASS_NAME=manager1 " ` + + "--from-literal=$MYSQL_WL_USER_NAME=weblogic " ` + + "--from-literal=$MYSQL_WL_USER_PASS=welcome1" + + $proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "$argList" -PassThru + Wait-Process -InputObject $proc + if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create MySQL secret $MYSQL_SECRET_NAME in namespace $MYSQL_NAMESPACE...exiting" + exit 1 + } +} + +# +# Create the MySQL config map component +# + +$tmp_file = Join-Path -Path "$env:TEMP" -ChildPath "\todolist-vz-mysql-configmap.yaml" +@" +apiVersion: core.oam.dev/v1alpha2 +kind: Component +metadata: + name: $CONFIG_MAP_NAME + namespace: $MYSQL_NAMESPACE +spec: + workload: + apiVersion: v1 + kind: ConfigMap + metadata: + name: $CONFIG_MAP_NAME + namespace: $MYSQL_NAMESPACE + data: + init-schema.sql: | + CREATE TABLE ToDos (taskId INT NOT NULL AUTO_INCREMENT, + task VARCHAR(200) NOT NULL, + completed BOOLEAN, + constraint todo_pk PRIMARY KEY (taskId)); + INSERT INTO ToDos (task, completed) + VALUES + ('Install WKTUI', FALSE), + ('Install Verrazzano', FALSE), + ('Move ToDo List to the the cloud', FALSE), + ('Celebrate', FALSE), + ('Clean off my desk', FALSE); +"@ > $tmp_file + +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "apply -f $tmp_file" -PassThru +Wait-Process -InputObject $proc +if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create Component $CONFIG_MAP_NAME in namespace $MYSQL_NAMESPACE...exiting" + exit 1 +} + +if (Test-Path "$tmp_file") { + Remove-Item -Path "$tmp_file" -Force +} + +# +# Create the MySQL deployment component +# + +$tmp_file = Join-Path -Path "$env:TEMP" -ChildPath "\todolist-vz-mysql-deployment.yaml" +@" +apiVersion: core.oam.dev/v1alpha2 +kind: Component +metadata: + name: todolist-mysql-deployment + namespace: $MYSQL_NAMESPACE +spec: + workload: + apiVersion: apps/v1 + kind: Deployment + metadata: + name: todolist-mysql-deployment + namespace: $MYSQL_NAMESPACE + labels: + app: todolist-mysql + spec: + replicas: 1 + selector: + matchLabels: + app: todolist-mysql + template: + metadata: + labels: + app: todolist-mysql + spec: + containers: + - name: todolist-mysql + image: container-registry.oracle.com/mysql/community-server:8.0.32 + ports: + - containerPort: 3306 + volumeMounts: + - name: init-sql + mountPath: /docker-entrypoint-initdb.d/ + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: $MYSQL_SECRET_NAME + key: $MYSQL_ROOT_PASS_NAME + - name: MYSQL_USER + valueFrom: + secretKeyRef: + name: $MYSQL_SECRET_NAME + key: $MYSQL_WL_USER_NAME + - name: MYSQL_PASSWORD + valueFrom: + secretKeyRef: + name: $MYSQL_SECRET_NAME + key: $MYSQL_WL_USER_PASS + - name: MYSQL_DATABASE + value: tododb + volumes: + - name: init-sql + configMap: + name: $CONFIG_MAP_NAME + imagePullSecrets: + - name: $SECRET_NAME +"@ > $tmp_file + +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "apply -f $tmp_file" -PassThru +Wait-Process -InputObject $proc +if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create Component todolist-mysql-deployment in namespace $MYSQL_NAMESPACE...exiting" + exit 1 +} + +if (Test-Path "$tmp_file") { + Remove-Item -Path "$tmp_file" -Force +} + +# +# Create the MySQL service component +# + +$tmp_file = Join-Path -Path "$env:TEMP" -ChildPath "\todolist-vz-mysql-deployment.yaml" +@" +apiVersion: core.oam.dev/v1alpha2 +kind: Component +metadata: + name: todolist-mysql-service + namespace: $MYSQL_NAMESPACE +spec: + workload: + apiVersion: v1 + kind: Service + metadata: + name: mysql + namespace: $MYSQL_NAMESPACE + spec: + selector: + app: todolist-mysql + ports: + - port: 3306 +"@ > $tmp_file + +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "apply -f $tmp_file" -PassThru +Wait-Process -InputObject $proc +if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create Component todolist-mysql-service in namespace $MYSQL_NAMESPACE...exiting" + exit 1 +} + +if (Test-Path "$tmp_file") { + Remove-Item -Path "$tmp_file" -Force +} diff --git a/samples/quickstart/scripts/vzDeployMySQL.sh b/samples/quickstart/scripts/vzDeployMySQL.sh new file mode 100755 index 000000000..567de552b --- /dev/null +++ b/samples/quickstart/scripts/vzDeployMySQL.sh @@ -0,0 +1,206 @@ +#!/usr/bin/env sh +# +# Copyright (c) 2023, Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +# +BASEDIR="$( cd "$( dirname "$0" )" && pwd )" +if [ -z "${WKTUI_QS_HOME}" ]; then + WKTUI_QS_HOME="$( cd "${BASEDIR}/.." && pwd )"; export WKTUI_QS_HOME +fi + +MYSQL_NAMESPACE=todolist-domain-ns +SECRET_NAME=ocr +MYSQL_SECRET_NAME=mysql +MYSQL_ROOT_PASS_NAME=rootPass +MYSQL_WL_USER_NAME=username +MYSQL_WL_USER_PASS=password +CONFIG_MAP_NAME=todolist-mysql-cm + +if [ -z "${ORCL_SSO_USER}" ]; then + printf "Please enter your Oracle SSO account username: " + read -r ORCL_SSO_USER + if [ -z "${ORCL_SSO_USER}" ]; then + echo "No Oracle SSO account username provided...exiting" >&2 + exit 1 + fi +fi + +if [ -z "${ORCL_SSO_PASS}" ]; then + stty -echo + printf "Please enter your Oracle SSO account password: " + read -r ORCL_SSO_USER + stty echo + if [ -z "${ORCL_SSO_PASS}" ]; then + echo "No Oracle SSO account password provided...exiting" >&2 + exit 1 + fi +fi + +# +# Create namespace if it doesn't already exist +# + +if ! kubectl get namespace "${MYSQL_NAMESPACE}" > /dev/null 2>&1; then + echo "MySQL image pull secret namespace ${MYSQL_NAMESPACE} does not exist...creating" + if ! kubectl create namespace "${MYSQL_NAMESPACE}"; then + echo "Failed to create MySQL image pull secret namespace ${MYSQL_NAMESPACE}...exiting" >&2 + exit 1 + fi +fi + +# +# Create the ocr image pull secret if it doesn't already exist +# + +if kubectl get secret "${SECRET_NAME}" -n "${MYSQL_NAMESPACE}" > /dev/null 2>&1; then + echo "MySQL image pull secret ${SECRET_NAME} already exists in namespace ${MYSQL_NAMESPACE}...skipping" +elif ! kubectl create secret docker-registry "${SECRET_NAME}" -n "${MYSQL_NAMESPACE}" \ + --docker-server=container-registry.oracle.com \ + --docker-username="${ORCL_SSO_USER}" \ + --docker-password="${ORCL_SSO_PASS}" \ + --docker-email="${ORCL_SSO_USER}"; then + echo "Failed to create MySQL image pull secret ${SECRET_NAME} in namespace ${MYSQL_NAMESPACE}...exiting" >&2 + exit 1 +fi + +# +# Create MySQL Secret to initialize MySQL user and password +# + +if kubectl get secret "${MYSQL_SECRET_NAME}" -n "${MYSQL_NAMESPACE}" > /dev/null 2>&1; then + echo "MySQL secret ${MYSQL_SECRET_NAME} already exists in namespace ${MYSQL_NAMESPACE}...skipping" +elif ! kubectl create secret generic "${MYSQL_SECRET_NAME}" -n "${MYSQL_NAMESPACE}" \ + --from-literal=${MYSQL_ROOT_PASS_NAME}=manager1 \ + --from-literal=${MYSQL_WL_USER_NAME}=weblogic \ + --from-literal=${MYSQL_WL_USER_PASS}=welcome1; then + echo "Failed to create MySQL secret ${MYSQL_SECRET_NAME} in namespace ${MYSQL_NAMESPACE}...exiting" >&2 + exit 1 +fi + +# +# Create the MySQL config map component +# + +if ! kubectl apply -f - <&2 + exit 1 +fi + +# +# Create the MySQL deployment component +# + +if ! kubectl apply -f - <&2 + exit 1 +fi + +# +# Create the MySQL service component +# + +if ! kubectl apply -f - <&2 + exit 1 +fi diff --git a/samples/quickstart/scripts/wkoDeployMySQL.ps1 b/samples/quickstart/scripts/wkoDeployMySQL.ps1 new file mode 100755 index 000000000..14f2b3dbe --- /dev/null +++ b/samples/quickstart/scripts/wkoDeployMySQL.ps1 @@ -0,0 +1,218 @@ +<# + Copyright (c) 2023, Oracle and/or its affiliates. + Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +#> +$BASEDIR = $PSScriptRoot +if (-not $env:WKTUI_QS_HOME) { + $env:WKTUI_QS_HOME = (get-item $BASEDIR).parent.FullName +} + +$MYSQL_NAMESPACE = "todolist-domain-ns" +$SECRET_NAME = "ocr" +$MYSQL_SECRET_NAME = "mysql" +$MYSQL_ROOT_PASS_NAME = "rootPass" +$MYSQL_WL_USER_NAME = "username" +$MYSQL_WL_USER_PASS = "password" +$CONFIG_MAP_NAME = "todolist-mysql-cm" +$KUBECTL_EXE = (get-command kubectl.exe).Path + +if (-not $env:ORCL_SSO_USER) { + $env:ORCL_SSO_USER = Read-Host "Please enter your Oracle SSO account username: " + if (-not $env:ORCL_SSO_USER) { + Write-Error "No Oracle SSO account username provided...exiting" + exit 1 + } +} + +if (-not $env:ORCL_SSO_PASS) { + $ORCL_SSO_PASS = Read-Host "Please enter your Oracle SSO account password: " -AsSecureString + if (-not $ORCL_SSO_PASS) { + Write-Error "No Oracle SSO account password provided...exiting" + exit 1 + } + $env:ORCL_SSO_PASS = [Runtime.InteropServices.Marshal]::PtrToStringAuto( + [Runtime.InteropServices.Marshal]::SecureStringToBSTR($ORCL_SSO_PASS)) +} + +# +# Create namespace if it doesn't already exist +# + +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "get namespace $MYSQL_NAMESPACE" ` + -PassThru -RedirectStandardError "NUL" -RedirectStandardOutput "$env:TEMP\stdout" +Wait-Process -InputObject $proc +if ($proc.ExitCode -ne 0) { + Write-Output "MySQL image pull secret namespace $MYSQL_NAMESPACE does not exist...creating" + $proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList ` + "create namespace $MYSQL_NAMESPACE" -PassThru + Wait-Process -InputObject $proc + if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create MySQL image pull secret namespace $MYSQL_NAMESPACE...exiting" + exit 1 + } +} + +# +# Create the ocr image pull secret if it doesn't already exist +# + +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "get secret $SECRET_NAME -n $MYSQL_NAMESPACE" ` + -PassThru -RedirectStandardError "NUL" -RedirectStandardOutput "$env:TEMP\stdout" +Wait-Process -InputObject $proc +if ($proc.ExitCode -eq 0) { + Write-Output "MySQL image pull secret $SECRET_NAME already exists in namespace $MYSQL_NAMESPACE...skipping" +} else { + $argList = "create secret docker-registry $SECRET_NAME -n $MYSQL_NAMESPACE " ` + + "--docker-server=container-registry.oracle.com " ` + + "--docker-username=`"$env:ORCL_SSO_USER`" " ` + + "--docker-password=`"$env:ORCL_SSO_PASS`" " ` + + "--docker-email=`"$env:ORCL_SSO_USER`" " + + $proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "$argList" -PassThru + Wait-Process -InputObject $proc + if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create MySQL image pull secret $SECRET_NAME in namespace $MYSQL_NAMESPACE...exiting" + exit 1 + } +} + +# +# Create MySQL Secret to initialize MySQL user and password +# + +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "get secret $MYSQL_SECRET_NAME -n $MYSQL_NAMESPACE" ` + -PassThru -RedirectStandardError "NUL" -RedirectStandardOutput "$env:TEMP\stdout" +Wait-Process -InputObject $proc +if ($proc.ExitCode -eq 0) { + Write-Output "MySQL secret $MYSQL_SECRET_NAME already exists in namespace $MYSQL_NAMESPACE...skipping" +} else { + $argList = "create secret generic $MYSQL_SECRET_NAME -n $MYSQL_NAMESPACE " ` + + "--from-literal=$MYSQL_ROOT_PASS_NAME=manager1 " ` + + "--from-literal=$MYSQL_WL_USER_NAME=weblogic " ` + + "--from-literal=$MYSQL_WL_USER_PASS=welcome1" + + $proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "$argList" -PassThru + Wait-Process -InputObject $proc + if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create MySQL secret $MYSQL_SECRET_NAME in namespace $MYSQL_NAMESPACE...exiting" + exit 1 + } +} + +# +# Create the MySQL config map that holds the initialization SQL script if it does not already exist +# + +$INIT_SCRIPT_DIR = Join-Path -Path "$env:WKTUI_QS_HOME" -ChildPath "\sql\" +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "get cm $CONFIG_MAP_NAME -n $MYSQL_NAMESPACE" ` + -PassThru -RedirectStandardError "NUL" -RedirectStandardOutput "$env:TEMP\stdout" +Wait-Process -InputObject $proc +if ($proc.ExitCode -eq 0) { + Write-Output "MySQL config map $CONFIG_MAP_NAME already exists in namespace $MYSQL_NAMESPACE...skipping" +} else { + $argList = "create cm $CONFIG_MAP_NAME -n $MYSQL_NAMESPACE --from-file=${INIT_SCRIPT_DIR}" + + $proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "$argList" -PassThru + Wait-Process -InputObject $proc + if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create MySQL config map $CONFIG_MAP_NAME in namespace $MYSQL_NAMESPACE...exiting" + exit 1 + } +} + +# +# Create the MySQL deployment +# + +$tmp_file = Join-Path -Path "$env:TEMP" -ChildPath "\todolist-mysql-deployment.yaml" +@" +apiVersion: apps/v1 +kind: Deployment +metadata: + name: todolist-mysql-deployment + namespace: $MYSQL_NAMESPACE + labels: + app: todolist-mysql +spec: + replicas: 1 + selector: + matchLabels: + app: todolist-mysql + template: + metadata: + namespace: $MYSQL_NAMESPACE + labels: + app: todolist-mysql + spec: + containers: + - name: todolist-mysql + image: container-registry.oracle.com/mysql/community-server:8.0.32 + ports: + - containerPort: 3306 + volumeMounts: + - name: init-sql + mountPath: /docker-entrypoint-initdb.d/ + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: $MYSQL_SECRET_NAME + key: $MYSQL_ROOT_PASS_NAME + - name: MYSQL_USER + valueFrom: + secretKeyRef: + name: $MYSQL_SECRET_NAME + key: $MYSQL_WL_USER_NAME + - name: MYSQL_PASSWORD + valueFrom: + secretKeyRef: + name: $MYSQL_SECRET_NAME + key: $MYSQL_WL_USER_PASS + - name: MYSQL_DATABASE + value: tododb + volumes: + - name: init-sql + configMap: + name: $CONFIG_MAP_NAME + imagePullSecrets: + - name: $SECRET_NAME +"@ > $tmp_file + +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "apply -f $tmp_file" -PassThru +Wait-Process -InputObject $proc +if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create MySQL deployment todolist-mysql-deployment in namespace $MYSQL_NAMESPACE...exiting" + exit 1 +} + +if (Test-Path "$tmp_file") { + Remove-Item -Path "$tmp_file" -Force +} + +# +# Create the MySQL service +# + +$tmp_file = Join-Path -Path "$env:TEMP" -ChildPath "\todolist-mysql-service.yaml" +@" +apiVersion: v1 +kind: Service +metadata: + name: mysql + namespace: ${MYSQL_NAMESPACE} +spec: + selector: + app: todolist-mysql + ports: + - port: 3306 +"@ > $tmp_file +$proc = Start-Process -NoNewWindow -FilePath "$KUBECTL_EXE" -ArgumentList "apply -f $tmp_file" -PassThru +Wait-Process -InputObject $proc +if ($proc.ExitCode -ne 0) { + Write-Error "Failed to create MySQL service mysql in namespace $MYSQL_NAMESPACE...exiting" + exit 1 +} + +if (Test-Path "$tmp_file") { + Remove-Item -Path "$tmp_file" -Force +} diff --git a/samples/quickstart/scripts/wkoDeployMySQL.sh b/samples/quickstart/scripts/wkoDeployMySQL.sh new file mode 100755 index 000000000..df75dfa9a --- /dev/null +++ b/samples/quickstart/scripts/wkoDeployMySQL.sh @@ -0,0 +1,170 @@ +#!/usr/bin/env sh +# +# Copyright (c) 2023, Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +# +BASEDIR="$( cd "$( dirname "$0" )" && pwd )" +if [ -z "${WKTUI_QS_HOME}" ]; then + WKTUI_QS_HOME="$( cd "${BASEDIR}/.." && pwd )"; export WKTUI_QS_HOME +fi + +MYSQL_NAMESPACE=todolist-domain-ns +SECRET_NAME=ocr +MYSQL_SECRET_NAME=mysql +MYSQL_ROOT_PASS_NAME=rootPass +MYSQL_WL_USER_NAME=username +MYSQL_WL_USER_PASS=password +CONFIG_MAP_NAME=todolist-mysql-cm + +if [ -z "${ORCL_SSO_USER}" ]; then + printf "Please enter your Oracle SSO account username: " + read -r ORCL_SSO_USER + if [ -z "${ORCL_SSO_USER}" ]; then + echo "No Oracle SSO account username provided...exiting" >&2 + exit 1 + fi +fi + +if [ -z "${ORCL_SSO_PASS}" ]; then + stty -echo + printf "Please enter your Oracle SSO account password: " + read -r ORCL_SSO_USER + stty echo + if [ -z "${ORCL_SSO_PASS}" ]; then + echo "No Oracle SSO account password provided...exiting" >&2 + exit 1 + fi +fi + +# +# Create namespace if it doesn't already exist +# + +if ! kubectl get namespace "${MYSQL_NAMESPACE}" > /dev/null 2>&1; then + echo "MySQL image pull secret namespace ${MYSQL_NAMESPACE} does not exist...creating" + if ! kubectl create namespace "${MYSQL_NAMESPACE}"; then + echo "Failed to create MySQL image pull secret namespace ${MYSQL_NAMESPACE}...exiting" >&2 + exit 1 + fi +fi + +# +# Create the ocr image pull secret if it doesn't already exist +# + +if kubectl get secret "${SECRET_NAME}" -n "${MYSQL_NAMESPACE}" > /dev/null 2>&1; then + echo "MySQL image pull secret ${SECRET_NAME} already exists in namespace ${MYSQL_NAMESPACE}...skipping" +elif ! kubectl create secret docker-registry "${SECRET_NAME}" -n "${MYSQL_NAMESPACE}" \ + --docker-server=container-registry.oracle.com \ + --docker-username="${ORCL_SSO_USER}" \ + --docker-password="${ORCL_SSO_PASS}" \ + --docker-email="${ORCL_SSO_USER}"; then + echo "Failed to create MySQL image pull secret ${SECRET_NAME} in namespace ${MYSQL_NAMESPACE}...exiting" >&2 + exit 1 +fi + +# +# Create MySQL Secret to initialize MySQL user and password +# + +if kubectl get secret "${MYSQL_SECRET_NAME}" -n "${MYSQL_NAMESPACE}" > /dev/null 2>&1; then + echo "MySQL secret ${MYSQL_SECRET_NAME} already exists in namespace ${MYSQL_NAMESPACE}...skipping" +elif ! kubectl create secret generic "${MYSQL_SECRET_NAME}" -n "${MYSQL_NAMESPACE}" \ + --from-literal=${MYSQL_ROOT_PASS_NAME}=manager1 \ + --from-literal=${MYSQL_WL_USER_NAME}=weblogic \ + --from-literal=${MYSQL_WL_USER_PASS}=welcome1; then + echo "Failed to create MySQL secret ${MYSQL_SECRET_NAME} in namespace ${MYSQL_NAMESPACE}...exiting" >&2 + exit 1 +fi + +# +# Create the MySQL config map that holds the initialization SQL script if it does not already exist +# + +INIT_SCRIPT_DIR="${WKTUI_QS_HOME}/sql/" + +if kubectl get cm "${CONFIG_MAP_NAME}" -n "${MYSQL_NAMESPACE}" 2> /dev/null; then + echo "MySQL config map ${CONFIG_MAP_NAME} already exists in namespace ${MYSQL_NAMESPACE}...skipping" +elif ! kubectl create cm "${CONFIG_MAP_NAME}" -n "${MYSQL_NAMESPACE}" --from-file="${INIT_SCRIPT_DIR}"; then + echo "Failed to create MySQL config map ${CONFIG_MAP_NAME} in namespace ${MYSQL_NAMESPACE}...exiting" >&2 + exit 1 +fi + +# +# Create the MySQL deployment +# + +if ! kubectl apply -f - <&2 + exit 1 +fi + +# +# Create the MySQL service +# + +if ! kubectl apply -f - <&2 + exit 1 +fi diff --git a/samples/quickstart/setQuickstartEnv.ps1 b/samples/quickstart/setQuickstartEnv.ps1 new file mode 100644 index 000000000..0627d543b --- /dev/null +++ b/samples/quickstart/setQuickstartEnv.ps1 @@ -0,0 +1,73 @@ +<# + Copyright (c) 2020, 2023, Oracle and/or its affiliates. + Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + + This script sets up the required environment for working with the + WebLogic Kubernetes Toolkit UI Quickstart scripts and application build. +#> + +############################################################# +# EDIT THIS SECTION TO MATCH YOUR ENVIRONMENT # +############################################################# + +# +# Set to the JDK 11 installation directory or delete +# if JAVA_HOME is already set in your environment +# +$env:JAVA_HOME = "c:\path\to\jdk\install\directory" + +# +# Set to the Apache Maven directory or delete +# if M2_HOME is already set in your environment or +# if you do not plan to recompile the sample application +# +$env:M2_HOME = "c:\path\to\apache\maven\install\directory" + +# +# Set to the location of the WebLogic Server installation or delete +# if the ORACLE_HOME is already set in to point to the correct +# location in your environment. +# +$env:ORACLE_HOME = "c:\path\to\wls_14.1.1\install\directory" + +# +# Set to directory where WKTUI is installed. +# +# On Windows, this will typically be: +# +# $env:WKTUI_HOME="c:\Program Files\WebLogic Kubernetes Toolkit UI" +# +$env:WKTUI_HOME = "c:\Program Files\WebLogic Kubernetes Toolkit UI" + +# +# Set to the username of your Oracle SSO account. This is +# used to pull images from https://container-registry.oracle.com. +# +# Feel free to delete this variable and the other scripts +# will prompt you for the username. +# +$env:ORCL_SSO_USER = "jim.smith@mycompany.com" + +# +# Set to the password of your Oracle SSO account. This is +# used to pull images from https://container-registry.oracle.com. +# +# Feel free to delete this variable and the other scripts +# will prompt you for the password. +# +$env:ORCL_SSO_PASS = 'welcome1' + +# +# Set to the name of the program you are using to create +# container images (i.e., docker or podman) +# +$env:IMAGE_BUILDER_EXE=docker + +############################################################# +# DO NOT EDIT BELOW HERE # +############################################################# + +if (-not $env:WKTUI_QS_HOME) { + $env:WKTUI_QS_HOME = (get-item $PSScriptRoot).FullName +} +$env:WLSDEPLOY_HOME = Join-Path -Path "$env:WKTUI_HOME" -ChildPath "\tools\weblogic-deploy" diff --git a/samples/quickstart/setQuickstartEnv.sh b/samples/quickstart/setQuickstartEnv.sh new file mode 100644 index 000000000..859088ed7 --- /dev/null +++ b/samples/quickstart/setQuickstartEnv.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env sh +# +# Copyright (c) 2020, 2023, Oracle and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +# +# This script sets up the required environment for working with the +# WebLogic Kubernetes Toolkit UI Quickstart scripts and application build. +# + +############################################################# +# EDIT THIS SECTION TO MATCH YOUR ENVIRONMENT # +############################################################# + +# +# Set to the JDK 11 installation directory or delete +# if JAVA_HOME is already set in your environment +# +JAVA_HOME=/path/to/jdk/install/directory +export JAVA_HOME + +# +# Set to the Apache Maven directory or delete +# if M2_HOME is already set in your environment or +# if you do not plan to recompile the sample application +# +M2_HOME=/path/to/apache/maven/install/directory +export M2_HOME + +# +# Set to the location of the WebLogic Server installation or delete +# if the ORACLE_HOME is already set in to point to the correct +# location in your environment. +# +ORACLE_HOME=/path/to/wls_14.1.1/install/directory +export ORACLE_HOME + +# +# Set to directory where WKTUI is installed. +# +# On macOS, this will typically be: +# +# WKTUI_HOME="/Applications/WebLogic Kubernetes Toolkit UI.app" +# +WKTUI_HOME=/path/to/wktui/install/directory +export WKTUI_HOME + +# +# Set to the username of your Oracle SSO account. This is +# used to pull images from https://container-registry.oracle.com. +# +# Feel free to delete this variable and the other scripts +# will prompt you for the username. +# +ORCL_SSO_USER=jim.smith@mycompany.com +export ORCL_SSO_USER + +# +# Set to the password of your Oracle SSO account. This is +# used to pull images from https://container-registry.oracle.com. +# +# Feel free to delete this variable and the other scripts +# will prompt you for the password. +# +ORCL_SSO_PASS='welcome1' +export ORCL_SSO_PASS + +# +# Set to the name of the program you are using to create +# container images (i.e., docker or podman) +# +IMAGE_BUILDER_NAME=docker +export IMAGE_BUILDER_NAME + +############################################################# +# DO NOT EDIT BELOW HERE # +############################################################# + +WKTUI_QS_HOME="$( cd "$( dirname "$0" )" && pwd )"; export WKTUI_QS_HOME + +platform=$(uname) +if [ "${platform}" = "Darwin" ]; then + WLSDEPLOY_HOME="${WKTUI_HOME}/Contents/tools/weblogic-deploy" +else + WLSDEPLOY_HOME="${WKTUI_HOME}/tools/weblogic-deploy" +fi +export WLSDEPLOY_HOME + +if [ -n "${IMAGE_BUILDER_NAME}" ]; then + IMAGE_BUILDER_EXE=$(command -v "${IMAGE_BUILDER_NAME}") + if [ -z "${IMAGE_BUILDER_EXE}" ]; then + echo "Unable to find ${IMAGE_BUILDER_NAME} on the PATH...exiting" >&2 + exit 1 + elif [ ! -x "${IMAGE_BUILDER_EXE}" ]; then + echo "${IMAGE_BUILDER_EXE} is not executable...exiting" >&2 + exit 1 + fi + export IMAGE_BUILDER_EXE +fi diff --git a/samples/quickstart/sql/init-schema.sql b/samples/quickstart/sql/init-schema.sql new file mode 100644 index 000000000..31c472e17 --- /dev/null +++ b/samples/quickstart/sql/init-schema.sql @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2020, 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +CREATE TABLE ToDos (taskId INT NOT NULL AUTO_INCREMENT, + task VARCHAR(200) NOT NULL, + completed BOOLEAN, + constraint todo_pk PRIMARY KEY (taskId)); +INSERT INTO ToDos (task, completed) +VALUES + ('Install WKTUI', FALSE), + ('Install Verrazzano', FALSE), + ('Move ToDo List to the the cloud', FALSE), + ('Celebrate', FALSE), + ('Clean off my desk', FALSE);