@@ -131,22 +132,38 @@ If these exercises are followed using an Azure student account, then a MariaDB d
\begin{enumerate}
\item Follow the instructions at \href{https://docs.microsoft.com/en-us/azure/mysql/howto-configure-ssl}{https://docs.microsoft.com/en-us/azure/mysql/howto-configure-ssl} to download the \texttt{BaltimoreCyberTrustRoot.crt.pem} file and save it into the \texttt{src} directory.
\itemOpen a command prompt or Bash shell window in the \texttt{src} directory. Then connect to the remote MariaDB database server using the command given in Listing~\ref{listing:mysql-connect}. If this command is typed into a Bash shell on Windows, then it must be prefixed by \texttt{winpty}. This prefix is not needed when the client command is used with a Windows command prompt or a Bash shell on Linux or OSX. Using the teaching environment:
\itemSet the environment variables for either the student account or teaching environment:
\begin{itemize}
\item\texttt{db\_server} - The full database server name, ending in \texttt{.mariadb.database.azure.com}.
\item\texttt{db\_user} - The MariaDB user name issued.
\item\texttt{db\_password} - The MariaDB password issued.
\item\texttt{db\_name} - The \texttt{db\_user}, when using the teaching environment.
\item\texttt{DB\_SERVER} - The full database server name, ending in \texttt{.mariadb.database.azure.com}.
\item\texttt{DB\_USER} - The MariaDB user name.
\item\texttt{DB\_PASSWORD} - The MariaDB password.
\item\texttt{DB\_NAME} - The database name. (This is the same as the \texttt{DB\_USER}, when using the teaching environment.)
\end{itemize}
\item Open a command prompt or Bash shell window in the \texttt{src} directory. Then connect to the remote MariaDB database server using the command given in Listing~\ref{listing:mysql-connect} or \ref{listing:mysql-connect-ssl}, where Listing~\ref{listing:mysql-connect-ssl} should be used if the \texttt{BaltimoreCyberTrustRoot.crt.pem} certificate has already been installed on the host operating system. If this command is typed into a Bash shell on Windows, then it must be prefixed by \texttt{winpty}.
\clearpage
\begin{lstlisting}[caption={Connecting to the remote MariaDB server.},label=listing:mysql-connect,numbers=none,language=,showspaces=true]
\begin{lstlisting}[caption={Connecting to the remote MariaDB server.},label=listing:mysql-connect-ssl,numbers=none,language=,showspaces=true]
mysql --host $DB_SERVER \
--user $DB_USER -p$DB_PASSWORD --ssl \
--tls-version="TLSv1.2,TLSv1.3" $DB_NAME
\end{lstlisting}
If the command given in Listing~\ref{listing:mysql-connect} fails with the error that is given in Listing~\ref{listing:ssl-error}, run the command that is given in Listing~\ref{listing:mysql-connect-ssl} instead. This error can occur if the \texttt{BaltimoreCyberTrustRoot.crt.pem} is already installed on the host computer, such that it clashes with the version provided locally.
ERROR 2026 (HY000): SSL connection error: Server certificate validation failed. A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.
\end{lstlisting}
\item Check the tables present and remove any existing tables by using Listing~\ref{listing:list-tables} and \ref{listing:db-reset}, respectively. The Listing~\ref{listing:db-reset} assumes that the teaching environment is being used.
\item Check the tables present and remove any existing tables by using Listing~\ref{listing:list-tables} and \ref{listing:db-reset}, respectively. The name \texttt{db\_name} should be replaced with the database name.
\begin{lstlisting}[caption={Listing the tables and columns.},label=listing:list-tables,numbers=none,language=,showspaces=true]
SHOW TABLES;
...
...
@@ -154,8 +171,8 @@ SHOW COLUMNS IN book;
\end{lstlisting}
\begin{lstlisting}[caption={Creating an empty database, where \texttt{db\_user} should be replaced by the database user name.},label=listing:db-reset,numbers=none,language=,showspaces=true]
DROP DATABASE IF EXISTS db_user;
CREATE DATABASE db_user;
DROP DATABASE IF EXISTS db_name;
CREATE DATABASE db_name;
\end{lstlisting}
\end{enumerate}
...
...
@@ -164,9 +181,23 @@ CREATE DATABASE db_user;
It is easier to debug a program when it is running on the local computer, since the log messages may be clearer, the edit and update loop is quicker and a debugger can be used.
\begin{enumerate}
\item Set the environment variables.
\item Run the web service on the local computer, using the Azure MariaDB database.
\item Verify the end points work as expected by using Listing~\ref{listing:web-service-test}.
\item Use Visual Studio Code to open the \texttt{azure-stateful-webapp/src} folder.
\item Open the \texttt{app.py} file.
\item Run the file \texttt{app.py}. This will fail, since there is no local database server.
\item Set the environment variables within the \texttt{TERMINAL} window:
\begin{itemize}
\item\texttt{DB\_SERVER} is the full name of the remote database server, ending in ``mariadb.database.azure.com'' without the quotations.
\item\texttt{DB\_USER} is the user name for the remote database server.
\item\texttt{DB\_PASSWORD} is the password for the remote database server.
\item\texttt{DB\_NAME} is the name of the database within the remote database server.
\item\texttt{DB\_SSL} is set to \texttt{"true"}, if the \texttt{BaltimoreCyberTrustRoot.crt.pem} is already installed on the host operating system.
\item\texttt{DB\_SSL\_CERT} is set to \texttt{BaltimoreCyberTrustRoot.crt.pem}, if the \texttt{BaltimoreCyberTrustRoot.crt.pem} is not installed on the host operating system.
\end{itemize}
Either \texttt{DB\_SSL} or \texttt{DB\_SSL\_CERT} should be set, but not both.
\item Run the file \texttt{app.py}.
\item Verify the end points work as expected by using Listing~\ref{listing:web-service-test} or Postman.
\begin{lstlisting}[caption={Testing the web service.},label=listing:web-service-test,numbers=none,language=,showspaces=true]
\item Create a Web App by using Listing~\ref{listing:create-web-app}.
\item Create a Web App by using Listing~\ref{listing:create-web-app}, where the \texttt{plan\_id} should be replaced with the id of the existing plan on the teaching environment. Alternatively, a plan can be created in the student account. Following the Azure resource naming convention, the \texttt{app\_name} should start with the prefix ``app-''.
\begin{lstlisting}[caption={Creating a Web App.},label=listing:create-web-app,numbers=none,language=,showspaces=true]
az webapp create --name $app_name --resource-group $resource_group \
--plan $plan_name --runtime "python|3.9" \
az webapp create --name $app_name \
--plan $plan_id \
--resource-group $resource_group \
--runtime "python|3.9" \
--startup-file startup.txt
\end{lstlisting}
\item Configure the Web App by using Listing~\ref{listing:web-app-config}.
\item Configure the Web App by using Listing~\ref{listing:web-app-config}. The DB\_SSL\_CERT setting is needed, since the Linux App Service Plan does not contain the \texttt{BaltimoreCyberTrustRoot.crt.pem} certificate.
\begin{lstlisting}[caption={Configuring the Web App, with the database connection details and build flag.},label=listing:web-app-config,numbers=none,language=,showspaces=true]
az webapp config appsettings set --resource-group $resource_group \