From 03d783f02a3085ad343d3f57ade2e816239c5cdc Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 02:55:01 +0200 Subject: [PATCH 01/44] Update README.md --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2e18ca6..ffedf27 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ -# Spring Boot MySQL Example +# Online store -You can learn more about my courses [here](http://courses.springframework.guru/courses/) on my site. \ No newline at end of file +## Resources + The original spring-boot application was inspired from here https://github.com/springframeworkguru/spring-boot-mysql-example +### Steps to build locally +1 - First, ensure to have Java JDK/JRE and maven installed on your local machine
+ a - install Java JDK by running the command `sudo apt install default-jdk -y`
+ b - install Java JRE by running the command `sudo apt install default-jre -y`
+ c - install maven bwith `sudo apt install maven -y`
+2 - Second, install and configure mysql + a - install from here https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/ + b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from here https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account + c - create database for the application ( use the same guide above ) + Note: all names and passwords must be updated in the `src/main/resources/application.properties` file +3 - Build the jar file and run + a - Run the command `mvn clean install`. This will create a directory named `target`. + b - navigate to the `target` directory and run the jar file with `java -jar ` From e2080c3525060c5578a3c4d783616edcfa343604 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 02:55:38 +0200 Subject: [PATCH 02/44] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ffedf27..728b0fa 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ a - install Java JDK by running the command `sudo apt install default-jdk -y`
b - install Java JRE by running the command `sudo apt install default-jre -y`
c - install maven bwith `sudo apt install maven -y`
-2 - Second, install and configure mysql - a - install from here https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/ - b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from here https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account - c - create database for the application ( use the same guide above ) - Note: all names and passwords must be updated in the `src/main/resources/application.properties` file -3 - Build the jar file and run - a - Run the command `mvn clean install`. This will create a directory named `target`. - b - navigate to the `target` directory and run the jar file with `java -jar ` +2 - Second, install and configure mysql
+ a - install from here https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/
+ b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from here https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account
+ c - create database for the application ( use the same guide above )
+ Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
+3 - Build the jar file and run
+ a - Run the command `mvn clean install`. This will create a directory named `target`.
+ b - navigate to the `target` directory and run the jar file with `java -jar `
From 8c61ce176fd8e04c8c00c48af9adb80728c276bc Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 02:57:08 +0200 Subject: [PATCH 03/44] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 728b0fa..2ddcef2 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # Online store ## Resources - The original spring-boot application was inspired from here https://github.com/springframeworkguru/spring-boot-mysql-example + The original spring-boot application was inspired from [here](https://github.com/springframeworkguru/spring-boot-mysql-example) ### Steps to build locally 1 - First, ensure to have Java JDK/JRE and maven installed on your local machine
a - install Java JDK by running the command `sudo apt install default-jdk -y`
b - install Java JRE by running the command `sudo apt install default-jre -y`
c - install maven bwith `sudo apt install maven -y`
2 - Second, install and configure mysql
- a - install from here https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/
- b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from here https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account
+ a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
+ b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
c - create database for the application ( use the same guide above )
Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
3 - Build the jar file and run
From 3bdda6550e6160b0ea73c4f372e4a4dda202901d Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 02:57:53 +0200 Subject: [PATCH 04/44] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2ddcef2..82ae2fd 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ The original spring-boot application was inspired from [here](https://github.com/springframeworkguru/spring-boot-mysql-example) ### Steps to build locally 1 - First, ensure to have Java JDK/JRE and maven installed on your local machine
- a - install Java JDK by running the command `sudo apt install default-jdk -y`
- b - install Java JRE by running the command `sudo apt install default-jre -y`
- c - install maven bwith `sudo apt install maven -y`
+ a - install Java JDK by running the command `sudo apt install default-jdk -y`
+ b - install Java JRE by running the command `sudo apt install default-jre -y`
+ c - install maven bwith `sudo apt install maven -y`
2 - Second, install and configure mysql
- a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
- b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
- c - create database for the application ( use the same guide above )
- Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
+ a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
+ b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
+ c - create database for the application ( use the same guide above )
+ Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
3 - Build the jar file and run
- a - Run the command `mvn clean install`. This will create a directory named `target`.
- b - navigate to the `target` directory and run the jar file with `java -jar `
+ a - Run the command `mvn clean install`. This will create a directory named `target`.
+ b - navigate to the `target` directory and run the jar file with `java -jar `
From 9d5439346415f5d6b96bb2fe27e35680e12e268a Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 03:08:38 +0200 Subject: [PATCH 05/44] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 82ae2fd..8040937 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ The original spring-boot application was inspired from [here](https://github.com/springframeworkguru/spring-boot-mysql-example) ### Steps to build locally 1 - First, ensure to have Java JDK/JRE and maven installed on your local machine
- a - install Java JDK by running the command `sudo apt install default-jdk -y`
- b - install Java JRE by running the command `sudo apt install default-jre -y`
- c - install maven bwith `sudo apt install maven -y`
+* a - install Java JDK by running the command `sudo apt install default-jdk -y`
+* b - install Java JRE by running the command `sudo apt install default-jre -y`
+* c - install maven bwith `sudo apt install maven -y`
2 - Second, install and configure mysql
- a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
- b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
- c - create database for the application ( use the same guide above )
- Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
+* a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
+* b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
+* c - create database for the application ( use the same guide above )
+* Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
3 - Build the jar file and run
- a - Run the command `mvn clean install`. This will create a directory named `target`.
- b - navigate to the `target` directory and run the jar file with `java -jar `
+* a - Run the command `mvn clean install`. This will create a directory named `target`.
+* b - navigate to the `target` directory and run the jar file with `java -jar `
From 66dff3c7d67b4391d02a98bd4f95acdbeaafefcc Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 03:10:35 +0200 Subject: [PATCH 06/44] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8040937..820969f 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ The original spring-boot application was inspired from [here](https://github.com/springframeworkguru/spring-boot-mysql-example) ### Steps to build locally 1 - First, ensure to have Java JDK/JRE and maven installed on your local machine
-* a - install Java JDK by running the command `sudo apt install default-jdk -y`
-* b - install Java JRE by running the command `sudo apt install default-jre -y`
-* c - install maven bwith `sudo apt install maven -y`
+  a - install Java JDK by running the command `sudo apt install default-jdk -y`
+b - install Java JRE by running the command `sudo apt install default-jre -y`
+c - install maven bwith `sudo apt install maven -y`
2 - Second, install and configure mysql
-* a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
-* b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
-* c - create database for the application ( use the same guide above )
-* Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
+a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
+b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
+c - create database for the application ( use the same guide above )
+Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
3 - Build the jar file and run
-* a - Run the command `mvn clean install`. This will create a directory named `target`.
-* b - navigate to the `target` directory and run the jar file with `java -jar `
+a - Run the command `mvn clean install`. This will create a directory named `target`.
+b - navigate to the `target` directory and run the jar file with `java -jar `
From ebfd50d6ac844c9abaf6dc66eba82db713b668c4 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 03:11:40 +0200 Subject: [PATCH 07/44] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 820969f..ba89e4d 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,13 @@ ### Steps to build locally 1 - First, ensure to have Java JDK/JRE and maven installed on your local machine
  a - install Java JDK by running the command `sudo apt install default-jdk -y`
-b - install Java JRE by running the command `sudo apt install default-jre -y`
-c - install maven bwith `sudo apt install maven -y`
+  b - install Java JRE by running the command `sudo apt install default-jre -y`
+  c - install maven bwith `sudo apt install maven -y`
2 - Second, install and configure mysql
-a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
-b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
-c - create database for the application ( use the same guide above )
-Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
+  a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
+  b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
+  c - create database for the application ( use the same guide above )
+  Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
3 - Build the jar file and run
-a - Run the command `mvn clean install`. This will create a directory named `target`.
-b - navigate to the `target` directory and run the jar file with `java -jar `
+  a - Run the command `mvn clean install`. This will create a directory named `target`.
+  b - navigate to the `target` directory and run the jar file with `java -jar `
From f34e54b72872c771633dd0c270ddbf66e6bbf310 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 03:34:52 +0200 Subject: [PATCH 08/44] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba89e4d..18c6d88 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,14 @@   a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
  b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
  c - create database for the application ( use the same guide above )
+3 - Put the information in `.env` file +``` +MYSQL_DB_HOST= +MYSQL_DB_PORT= +MYSQL_DB_USERNAME= +MYSQL_DB_PASSWORD= +```   Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
-3 - Build the jar file and run
+4 - Build the jar file and run
  a - Run the command `mvn clean install`. This will create a directory named `target`.
  b - navigate to the `target` directory and run the jar file with `java -jar `
From 90cf7eb347ea2afa4951bd60b3c345688f19d747 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 03:35:15 +0200 Subject: [PATCH 09/44] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 18c6d88..eceffb3 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ MYSQL_DB_PORT= MYSQL_DB_USERNAME= MYSQL_DB_PASSWORD= ``` -  Note: all names and passwords must be updated in the `src/main/resources/application.properties` file
+  Note: all names and passwords will be updated in the `src/main/resources/application.properties` file
4 - Build the jar file and run
  a - Run the command `mvn clean install`. This will create a directory named `target`.
  b - navigate to the `target` directory and run the jar file with `java -jar `
From bded1b3154eb08a20ecf9dfaf04abc7f260c2aea Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 03:35:57 +0200 Subject: [PATCH 10/44] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index eceffb3..ccf9023 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,16 @@ ## Resources The original spring-boot application was inspired from [here](https://github.com/springframeworkguru/spring-boot-mysql-example) -### Steps to build locally -1 - First, ensure to have Java JDK/JRE and maven installed on your local machine
+## Steps to build locally +### 1 - First, ensure to have Java JDK/JRE and maven installed on your local machine
  a - install Java JDK by running the command `sudo apt install default-jdk -y`
  b - install Java JRE by running the command `sudo apt install default-jre -y`
  c - install maven bwith `sudo apt install maven -y`
-2 - Second, install and configure mysql
+### 2 - Second, install and configure mysql
  a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
  b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
  c - create database for the application ( use the same guide above )
-3 - Put the information in `.env` file +### 3 - Put the information in `.env` file ``` MYSQL_DB_HOST= MYSQL_DB_PORT= @@ -19,6 +19,6 @@ MYSQL_DB_USERNAME= MYSQL_DB_PASSWORD= ```   Note: all names and passwords will be updated in the `src/main/resources/application.properties` file
-4 - Build the jar file and run
+### 4 - Build the jar file and run
  a - Run the command `mvn clean install`. This will create a directory named `target`.
  b - navigate to the `target` directory and run the jar file with `java -jar `
From ecc8ca29c033d0c2ceacee64c5a1b5c25b4ec289 Mon Sep 17 00:00:00 2001 From: osamamagdy Date: Fri, 5 Nov 2021 03:39:56 +0200 Subject: [PATCH 11/44] Build local complete --- .classpath | 49 ++++++++++++++++++++++ .gitignore | 3 ++ .project | 34 +++++++++++++++ .settings/org.eclipse.core.resources.prefs | 5 +++ .settings/org.eclipse.jdt.apt.core.prefs | 2 + .settings/org.eclipse.jdt.core.prefs | 10 +++++ .settings/org.eclipse.m2e.core.prefs | 4 ++ pom.xml | 14 ++++++- src/main/resources/application.properties | 6 +-- 9 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.apt.core.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..39abf1c --- /dev/null +++ b/.classpath @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore index d46f5ca..878fc8f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ target # IDE files .idea *.iml + +# env file +.env \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..33768c5 --- /dev/null +++ b/.project @@ -0,0 +1,34 @@ + + + spring-boot-mysql + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + + + 1636074914226 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..839d647 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.apt.core.prefs b/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 0000000..d4313d4 --- /dev/null +++ b/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..951833c --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,10 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.methodParameters=generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml index 0002268..29e2e68 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.0.RELEASE + 2.1.6.RELEASE @@ -47,6 +47,11 @@ spring-boot-starter-test test + + javax.xml.bind + jaxb-api + 2.3.0 + @@ -55,6 +60,11 @@ org.springframework.boot spring-boot-maven-plugin + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + @@ -95,4 +105,4 @@ - + \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8e4417a..757fd57 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,9 +2,9 @@ # = DATA SOURCE # =============================== # Set here configurations for the database connection -spring.datasource.url=jdbc:mysql://localhost:3306/springboot_mysql_example -spring.datasource.username=root -#spring.datasource.password=YOUR_DB_PASSWORD +spring.datasource.url=jdbc:mysql://${MYSQL_DB_HOST}:${MYSQL_DB_PORT}/springboot_mysql_example +spring.datasource.username=${MYSQL_DB_USERNAME} +spring.datasource.password=${MYSQL_DB_PASSWORD} spring.datasource.driver-class-name=com.mysql.jdbc.Driver # Keep the connection alive if idle for a long time (needed in production) From b51d640d49f5bd0806b3709291dc9be90b36455e Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Fri, 5 Nov 2021 05:45:50 +0200 Subject: [PATCH 12/44] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ccf9023..7b1169a 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ MYSQL_DB_HOST= MYSQL_DB_PORT= MYSQL_DB_USERNAME= MYSQL_DB_PASSWORD= +MYSQL_DB_DNNAME= ```   Note: all names and passwords will be updated in the `src/main/resources/application.properties` file
### 4 - Build the jar file and run
From 1cf29b8adbe5788676b42c634d8be72fadf7ff90 Mon Sep 17 00:00:00 2001 From: osamamagdy Date: Fri, 5 Nov 2021 20:02:08 +0200 Subject: [PATCH 13/44] Docker Compose --- .dockerignore | 21 ++++++++++++ Dockerfile | 25 ++++++++++++++ docker-compose.yaml | 40 +++++++++++++++++++++++ src/main/resources/application.properties | 2 +- 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..878fc8f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,21 @@ +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +target + +# IDE files +.idea +*.iml + +# env file +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ae0de31 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM maven:latest as builder +WORKDIR /app +COPY . . + +RUN ["mvn","clean","install","-DskipTests"] + +FROM openjdk:latest +COPY --from=builder /app/target/spring-boot-mysql-0.0.1-SNAPSHOT.jar /usr/src/myapp/ +WORKDIR /usr/src/myapp + +ARG MYSQL_DB_HOST +ARG MYSQL_DB_PORT +ARG MYSQL_DB_USERNAME +ARG MYSQL_DB_PASSWORD +ARG MYSQL_DB_DNAME + +ENV MYSQL_DB_HOST=${MYSQL_DB_HOST} +ENV MYSQL_DB_USERNAME=${MYSQL_DB_USERNAME} +ENV MYSQL_DB_PORT=${MYSQL_DB_PORT} +ENV MYSQL_DB_PASSWORD=${MYSQL_DB_PASSWORD} +ENV MYSQL_DB_DNAME=${MYSQL_DB_DNAME} + +EXPOSE 8080 + +CMD ["java", "-jar","spring-boot-mysql-0.0.1-SNAPSHOT.jar"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..1ca61af --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,40 @@ +version: '3' +services: + db: + image: mysql:5.7 + restart: always + environment: + MYSQL_DATABASE: "$MYSQL_DB_DNAME" + # So you don't have to use root, but you can if you like + MYSQL_USER: "$MYSQL_DB_USERNAME" + # You can use whatever password you like + MYSQL_PASSWORD: "$MYSQL_DB_PASSWORD" + # Password for root access + MYSQL_ROOT_PASSWORD: "$MYSQL_DB_PASSWORD" + ports: + # : < MySQL Port running inside container> + #Host port is used for outside communication + #MYSQL internal port used for Networked service-to-service communication + - '3000:3306' + volumes: + - my-db:/var/lib/mysql + web-app: + depends_on: + - db + restart: on-failure + links: + - "db:db" + build: + context: . + dockerfile: Dockerfile + args: + MYSQL_DB_HOST: ${MYSQL_DB_HOST} + MYSQL_DB_PORT: ${MYSQL_DB_PORT} + MYSQL_DB_USERNAME: ${MYSQL_DB_USERNAME} + MYSQL_DB_PASSWORD: ${MYSQL_DB_PASSWORD} + MYSQL_DB_DNAME: ${MYSQL_DB_DNAME} + ports: + - "8080:8080" +## Names our volume +volumes: + my-db: \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 757fd57..54fcd20 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,7 @@ # = DATA SOURCE # =============================== # Set here configurations for the database connection -spring.datasource.url=jdbc:mysql://${MYSQL_DB_HOST}:${MYSQL_DB_PORT}/springboot_mysql_example +spring.datasource.url=jdbc:mysql://${MYSQL_DB_HOST}:${MYSQL_DB_PORT}/${MYSQL_DB_DNAME}?enabledTLSProtocols=TLSv1.2 spring.datasource.username=${MYSQL_DB_USERNAME} spring.datasource.password=${MYSQL_DB_PASSWORD} spring.datasource.driver-class-name=com.mysql.jdbc.Driver From 71fbb2554283f59b9b227a43cf8167b083d71f20 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sat, 6 Nov 2021 06:20:38 +0200 Subject: [PATCH 14/44] Update README.md --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b1169a..6ae0ae4 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@   a - install from [here](https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/)
  b - configure mysql by creating a user with `mysql_native_password` for the authentication method. You can take guidance from [here](https://linuxize.com/post/how-to-manage-mysql-databases-and-users-from-the-command-line/#create-a-new-mysql-user-account)
  c - create database for the application ( use the same guide above )
-### 3 - Put the information in `.env` file +### 3 - Put the information in a new `.env` file ``` MYSQL_DB_HOST= MYSQL_DB_PORT= @@ -23,3 +23,21 @@ MYSQL_DB_DNNAME= ### 4 - Build the jar file and run
  a - Run the command `mvn clean install`. This will create a directory named `target`.
  b - navigate to the `target` directory and run the jar file with `java -jar `
+## Build locally using Docker +### 1 - Install Docker & Docker-Compose
+  a - Install docker from the official documentation [here](https://docs.docker.com/engine/install/ubuntu/)
+  b - Install docker-compose from the official documentation [here](https://docs.docker.com/compose/install/)
+  Note: If you choose to build with docker, you will not need all the previous installation for running the project locally. You only need to install docker and docker-compose and it saves you the hassle of installing JDK, JRE, maven, and even mysql. + +### 2 - Put the information in a new `.env` file +  For the sake of consistency, we use the same name while building locally
+``` +MYSQL_DB_HOST= +MYSQL_DB_PORT= +MYSQL_DB_USERNAME= +MYSQL_DB_PASSWORD= +MYSQL_DB_DNNAME= +``` +### 3 - Build and Run +  Run the command `docker-compose up` in the directory where docker files are. Docker will first pull the needed images for you and start working.
+  If you want to edit the configurations and build again, run `docker-compose up --build` to ignore chache and start building again.
From 83fc53487d58f839f0256891e2ae10a961a3a8d4 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sat, 6 Nov 2021 06:21:09 +0200 Subject: [PATCH 15/44] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ae0ae4..583b473 100644 --- a/README.md +++ b/README.md @@ -39,5 +39,5 @@ MYSQL_DB_PASSWORD= MYSQL_DB_DNNAME= ``` ### 3 - Build and Run -  Run the command `docker-compose up` in the directory where docker files are. Docker will first pull the needed images for you and start working.
+  Run the command `docker-compose up` in the directory where docker files are. Docker will first pull the needed images and start working.
  If you want to edit the configurations and build again, run `docker-compose up --build` to ignore chache and start building again.
From c2d1007721bcabb8fdf8a7c40741799856f665f9 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sat, 6 Nov 2021 06:23:54 +0200 Subject: [PATCH 16/44] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 583b473..3afb47e 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ MYSQL_DB_DNNAME= ### 2 - Put the information in a new `.env` file   For the sake of consistency, we use the same name while building locally
``` -MYSQL_DB_HOST= -MYSQL_DB_PORT= +MYSQL_DB_HOST=db #this one is necessary as it is the service name in docker-compose.yaml file +MYSQL_DB_PORT=3306 #this is the default port used by mysql official image so don't choose any port else MYSQL_DB_USERNAME= MYSQL_DB_PASSWORD= MYSQL_DB_DNNAME= From db7abc7d797e88270094d0b5370a3dd771269c94 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sat, 6 Nov 2021 17:59:20 +0200 Subject: [PATCH 17/44] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3afb47e..5efa7eb 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ MYSQL_DB_HOST= MYSQL_DB_PORT= MYSQL_DB_USERNAME= MYSQL_DB_PASSWORD= -MYSQL_DB_DNNAME= +MYSQL_DB_DNAME= ```   Note: all names and passwords will be updated in the `src/main/resources/application.properties` file
### 4 - Build the jar file and run
@@ -36,7 +36,7 @@ MYSQL_DB_HOST=db #this one is necessary as it is the service name in docker-com MYSQL_DB_PORT=3306 #this is the default port used by mysql official image so don't choose any port else MYSQL_DB_USERNAME= MYSQL_DB_PASSWORD= -MYSQL_DB_DNNAME= +MYSQL_DB_DNAME= ``` ### 3 - Build and Run   Run the command `docker-compose up` in the directory where docker files are. Docker will first pull the needed images and start working.
From 25de3d5ee62e32cf00c90d5bd01c5c3a1a0678db Mon Sep 17 00:00:00 2001 From: osamamagdy Date: Sat, 6 Nov 2021 18:16:25 +0200 Subject: [PATCH 18/44] env isn't needed in dockerfile --- Dockerfile | 13 ------------- docker-compose.yaml | 12 ++++++------ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index ae0de31..ca906c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,19 +7,6 @@ RUN ["mvn","clean","install","-DskipTests"] FROM openjdk:latest COPY --from=builder /app/target/spring-boot-mysql-0.0.1-SNAPSHOT.jar /usr/src/myapp/ WORKDIR /usr/src/myapp - -ARG MYSQL_DB_HOST -ARG MYSQL_DB_PORT -ARG MYSQL_DB_USERNAME -ARG MYSQL_DB_PASSWORD -ARG MYSQL_DB_DNAME - -ENV MYSQL_DB_HOST=${MYSQL_DB_HOST} -ENV MYSQL_DB_USERNAME=${MYSQL_DB_USERNAME} -ENV MYSQL_DB_PORT=${MYSQL_DB_PORT} -ENV MYSQL_DB_PASSWORD=${MYSQL_DB_PASSWORD} -ENV MYSQL_DB_DNAME=${MYSQL_DB_DNAME} - EXPOSE 8080 CMD ["java", "-jar","spring-boot-mysql-0.0.1-SNAPSHOT.jar"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 1ca61af..b2fd539 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -24,15 +24,15 @@ services: restart: on-failure links: - "db:db" + environment: + MYSQL_DB_HOST: ${MYSQL_DB_HOST} + MYSQL_DB_PORT: ${MYSQL_DB_PORT} + MYSQL_DB_USERNAME: ${MYSQL_DB_USERNAME} + MYSQL_DB_PASSWORD: ${MYSQL_DB_PASSWORD} + MYSQL_DB_DNAME: ${MYSQL_DB_DNAME} build: context: . dockerfile: Dockerfile - args: - MYSQL_DB_HOST: ${MYSQL_DB_HOST} - MYSQL_DB_PORT: ${MYSQL_DB_PORT} - MYSQL_DB_USERNAME: ${MYSQL_DB_USERNAME} - MYSQL_DB_PASSWORD: ${MYSQL_DB_PASSWORD} - MYSQL_DB_DNAME: ${MYSQL_DB_DNAME} ports: - "8080:8080" ## Names our volume From 95ea356895e6efd764bcbc082968cc45942a4e68 Mon Sep 17 00:00:00 2001 From: osamamagdy Date: Sun, 7 Nov 2021 02:49:17 +0200 Subject: [PATCH 19/44] Apply k8s --- .gitignore | 3 +- k8s_yaml/configmap.yaml | 6 ++++ k8s_yaml/mysql-deployment.yaml | 42 ++++++++++++++++++++++++ k8s_yaml/mysql-service.yaml | 11 +++++++ k8s_yaml/online-store-deployment.yaml | 47 +++++++++++++++++++++++++++ k8s_yaml/online-store-service.yaml | 13 ++++++++ 6 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 k8s_yaml/configmap.yaml create mode 100644 k8s_yaml/mysql-deployment.yaml create mode 100644 k8s_yaml/mysql-service.yaml create mode 100644 k8s_yaml/online-store-deployment.yaml create mode 100644 k8s_yaml/online-store-service.yaml diff --git a/.gitignore b/.gitignore index 878fc8f..546f3ee 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ target *.iml # env file -.env \ No newline at end of file +.env +k8s_yaml/secret.yaml diff --git a/k8s_yaml/configmap.yaml b/k8s_yaml/configmap.yaml new file mode 100644 index 0000000..fd7ef6c --- /dev/null +++ b/k8s_yaml/configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: online-store-configmap +data: + MYSQL_DB_HOST: mysql-service \ No newline at end of file diff --git a/k8s_yaml/mysql-deployment.yaml b/k8s_yaml/mysql-deployment.yaml new file mode 100644 index 0000000..58f304e --- /dev/null +++ b/k8s_yaml/mysql-deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mysql-deployment + labels: + app: mysql +spec: + replicas: 1 + selector: + matchLabels: + app: mysql + template: + metadata: + labels: + app: mysql + spec: + containers: + - name: mysql + image: mysql + ports: + - containerPort: 3306 + env: + - name: MYSQL_DATABASE + valueFrom: + secretKeyRef: + name: mysql-secret + key: MYSQL_DB_DNAME + - name: MYSQL_USER + valueFrom: + secretKeyRef: + name: mysql-secret + key: MYSQL_DB_USERNAME + - name: MYSQL_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-secret + key: MYSQL_DB_PASSWORD + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-secret + key: MYSQL_DB_PASSWORD diff --git a/k8s_yaml/mysql-service.yaml b/k8s_yaml/mysql-service.yaml new file mode 100644 index 0000000..d67f415 --- /dev/null +++ b/k8s_yaml/mysql-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: mysql-service +spec: + selector: + app: mysql + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 \ No newline at end of file diff --git a/k8s_yaml/online-store-deployment.yaml b/k8s_yaml/online-store-deployment.yaml new file mode 100644 index 0000000..5b87071 --- /dev/null +++ b/k8s_yaml/online-store-deployment.yaml @@ -0,0 +1,47 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: online-store + labels: + app: online-store +spec: + replicas: 1 + selector: + matchLabels: + app: online-store + template: + metadata: + labels: + app: online-store + spec: + containers: + - name: online-store + image: osamamagdy/online_store + ports: + - containerPort: 8080 + env: + - name: MYSQL_DB_HOST + valueFrom: + configMapKeyRef: + name: online-store-configmap + key: MYSQL_DB_HOST + - name: MYSQL_DB_PORT + valueFrom: + secretKeyRef: + name: mysql-secret + key: MYSQL_DB_PORT + - name: MYSQL_DB_USERNAME + valueFrom: + secretKeyRef: + name: mysql-secret + key: MYSQL_DB_USERNAME + - name: MYSQL_DB_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-secret + key: MYSQL_DB_PASSWORD + - name: MYSQL_DB_DNAME + valueFrom: + secretKeyRef: + name: mysql-secret + key: MYSQL_DB_DNAME \ No newline at end of file diff --git a/k8s_yaml/online-store-service.yaml b/k8s_yaml/online-store-service.yaml new file mode 100644 index 0000000..a945adb --- /dev/null +++ b/k8s_yaml/online-store-service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: online-store-service +spec: + selector: + app: online-store + type: LoadBalancer + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 + nodePort: 30000 #this is the port for external ip address that you will type into your browser \ No newline at end of file From 9efdf5426c7ebfe0671b90a99161cdc5ec18d30d Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sun, 7 Nov 2021 18:21:44 +0200 Subject: [PATCH 20/44] Update README.md --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 5efa7eb..66166db 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,38 @@ MYSQL_DB_DNAME= ### 3 - Build and Run   Run the command `docker-compose up` in the directory where docker files are. Docker will first pull the needed images and start working.
  If you want to edit the configurations and build again, run `docker-compose up --build` to ignore chache and start building again.
+ +## Deploy with kubernetes +### 1 - Install minikube
+  a - For testing purposes, we can deploy all our kubernetes deployments on a locally created single-node cluster with minikube [here](https://minikube.sigs.k8s.io/docs/start/)
+  Note: If you are running your ubuntu on a virtual machine upon other OS, you may need to follow this [guide](https://webme.ie/how-to-run-minikube-on-a-virtualbox-vm/) instead.
+ +### 2 - Put the information in a new `secret.yaml` file +  a - Here, we will replace the `.env` file with two files. A configmap.yaml which contains non-sensetive data to be accessible by all cluster resources (this one is created for you and is present in the repository.
+  b - A secret.yaml which contains sensetive data that not to be shared on publuic repository so create the file first and fill the data below
+ +``` +apiVersion: v1 +kind: Secret +metadata: + name: mysql-secret +type: Opaque +data: + MYSQL_DB_PORT: + MYSQL_DB_USERNAME: + MYSQL_DB_PASSWORD: + MYSQL_DB_DNAME: +``` +  Important Note: you can not just place the values in the secrets file as a plain text, first you will need to encode them to base64 (as k8s will decode them by default). And the way to do this in linux `echo -n text | base64 `, or you can use a website like [here](https://www.base64decode.org/)
+ +### 3 - Build and Run +  a - You will need to run `kubectl apply -f .yaml` to apply the configurations of each file. But due to using secrets and services, you will need to execute them in specific order
+   I - secrets file
+   II - mysql deployment files
+   III - mysql service files
+   IV - config map file
+   V - online-store deployment file
+   VI - online-store-service file
+  b - The loadbalancer used in online-store-service will assign an external ip → with using minikube, it will be in pending state until you allow it to take ip by typing “minikube service ” + + Note: If you want to edit any of the configurations, run `kubectl apply -f .yaml`.
From 1b2b797ef3a368ebe39f2dfb3e706a4b476614d0 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sun, 7 Nov 2021 18:24:47 +0200 Subject: [PATCH 21/44] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 66166db..694d630 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ MYSQL_DB_DNAME=   a - For testing purposes, we can deploy all our kubernetes deployments on a locally created single-node cluster with minikube [here](https://minikube.sigs.k8s.io/docs/start/)
  Note: If you are running your ubuntu on a virtual machine upon other OS, you may need to follow this [guide](https://webme.ie/how-to-run-minikube-on-a-virtualbox-vm/) instead.
-### 2 - Put the information in a new `secret.yaml` file +### 2 - Put the information in a new `secret.yaml` file (all files are in the k8s_yaml directory)   a - Here, we will replace the `.env` file with two files. A configmap.yaml which contains non-sensetive data to be accessible by all cluster resources (this one is created for you and is present in the repository.
  b - A secret.yaml which contains sensetive data that not to be shared on publuic repository so create the file first and fill the data below
From 661f454d0fdb0fbe14a12a422e5dafdc0ca21a60 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sun, 7 Nov 2021 23:32:02 +0200 Subject: [PATCH 22/44] Create pipeline.yml --- .github/workflows/pipeline.yml | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/pipeline.yml diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..4138e65 --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,60 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + + build_local: + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' + cache: maven + - name: Setup MySQL + - uses: mirromutth/mysql-action@v1.1 + with: + mysql database: 'springboot_mysql_example' + mysql root password: ${{ secrets.RootPassword }} + mysql user: 'osama' + mysql password: ${{ secrets.DatabasePassword }} + - name: Build the JAR file + - run: mvn clean install -DskipTests + + - name: Test + run: mvn test + env: + MYSQL_DB_HOST: 'mysql' + MYSQL_DB_PORT: '3306' + MYSQL_DB_USERNAME: 'osama' + MYSQL_DB_PASSWORD: ${{secrets.DatabasePassword}} + MYSQL_DB_DNAME: 'springboot_mysql_example' + + build_docker: + needs: build_local #as we don't push the image unless the + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Build & push Docker image + uses: mr-smithers-excellent/docker-build-push@v5 + with: + image: osamamagdy/online_store + tags: v1, latest + registry: docker.io + dockerfile: Dockerfile + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} From 0cf4a810c4eff4be06103d3189b5c40b6256a353 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sun, 7 Nov 2021 23:39:00 +0200 Subject: [PATCH 23/44] Create main.yml --- .github/workflows/main.yml | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..f3e6c09 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,71 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + + build_local: + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' + cache: maven + + + - name: Setup MySQL + - uses: mirromutth/mysql-action@v1.1 + with: + mysql database: 'springboot_mysql_example' + mysql root password: ${{ secrets.RootPassword }} + mysql user: 'osama' + mysql password: ${{ secrets.DatabasePassword }} + + + - name: Build the JAR file + run: mvn clean install -DskipTests + + + - name: Test + run: mvn test + env: + MYSQL_DB_HOST: 'mysql' + MYSQL_DB_PORT: '3306' + MYSQL_DB_USERNAME: 'osama' + MYSQL_DB_PASSWORD: ${{secrets.DatabasePassword}} + MYSQL_DB_DNAME: 'springboot_mysql_example' + + + + build_docker: + needs: build_local #as we don't push the image unless the + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + + - name: Build & push Docker image + uses: mr-smithers-excellent/docker-build-push@v5 + with: + image: osamamagdy/online_store + tags: v1, latest + registry: docker.io + dockerfile: Dockerfile + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} From 0fde86155d86d291671334a6d612e1dd1bcf03d1 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sun, 7 Nov 2021 23:41:21 +0200 Subject: [PATCH 24/44] Delete pipeline.yml --- .github/workflows/pipeline.yml | 60 ---------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 .github/workflows/pipeline.yml diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml deleted file mode 100644 index 4138e65..0000000 --- a/.github/workflows/pipeline.yml +++ /dev/null @@ -1,60 +0,0 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Java CI with Maven - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - - build_local: - - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v2 - with: - java-version: '11' - distribution: 'adopt' - cache: maven - - name: Setup MySQL - - uses: mirromutth/mysql-action@v1.1 - with: - mysql database: 'springboot_mysql_example' - mysql root password: ${{ secrets.RootPassword }} - mysql user: 'osama' - mysql password: ${{ secrets.DatabasePassword }} - - name: Build the JAR file - - run: mvn clean install -DskipTests - - - name: Test - run: mvn test - env: - MYSQL_DB_HOST: 'mysql' - MYSQL_DB_PORT: '3306' - MYSQL_DB_USERNAME: 'osama' - MYSQL_DB_PASSWORD: ${{secrets.DatabasePassword}} - MYSQL_DB_DNAME: 'springboot_mysql_example' - - build_docker: - needs: build_local #as we don't push the image unless the - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v2 - - name: Build & push Docker image - uses: mr-smithers-excellent/docker-build-push@v5 - with: - image: osamamagdy/online_store - tags: v1, latest - registry: docker.io - dockerfile: Dockerfile - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} From ec6116286df746748ec9123855225a7194ea6ee9 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sun, 7 Nov 2021 23:41:49 +0200 Subject: [PATCH 25/44] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f3e6c09..991c84c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: - name: Setup MySQL - - uses: mirromutth/mysql-action@v1.1 + uses: mirromutth/mysql-action@v1.1 with: mysql database: 'springboot_mysql_example' mysql root password: ${{ secrets.RootPassword }} From b6f3593da9e69c3c31b4c0f6af08ffd1b9c04743 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Sun, 7 Nov 2021 23:47:19 +0200 Subject: [PATCH 26/44] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 991c84c..95114be 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,7 +44,7 @@ jobs: - name: Test run: mvn test env: - MYSQL_DB_HOST: 'mysql' + MYSQL_DB_HOST: 'localhost' MYSQL_DB_PORT: '3306' MYSQL_DB_USERNAME: 'osama' MYSQL_DB_PASSWORD: ${{secrets.DatabasePassword}} From eeb16c6ce19d161ac07921ac2071ee7669f0e42a Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 00:02:24 +0200 Subject: [PATCH 27/44] Update main.yml --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 95114be..7397527 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,13 +29,15 @@ jobs: - name: Setup MySQL - uses: mirromutth/mysql-action@v1.1 + uses: haltuf/mysql-action@master with: mysql database: 'springboot_mysql_example' mysql root password: ${{ secrets.RootPassword }} mysql user: 'osama' mysql password: ${{ secrets.DatabasePassword }} +# - name: Configure Password permission +# run: ALTER USER 'osama'@'localhost' IDENTIFIED WITH mysql_native_password BY ${{ secrets.DatabasePassword }} ; - name: Build the JAR file run: mvn clean install -DskipTests From 7d70554889cf21a60b6a312a8f827c2b473b69d3 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 00:08:12 +0200 Subject: [PATCH 28/44] Update application.properties --- src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 54fcd20..f464490 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,7 @@ # = DATA SOURCE # =============================== # Set here configurations for the database connection -spring.datasource.url=jdbc:mysql://${MYSQL_DB_HOST}:${MYSQL_DB_PORT}/${MYSQL_DB_DNAME}?enabledTLSProtocols=TLSv1.2 +spring.datasource.url=jdbc:mysql://${MYSQL_DB_HOST}:${MYSQL_DB_PORT}/${MYSQL_DB_DNAME} spring.datasource.username=${MYSQL_DB_USERNAME} spring.datasource.password=${MYSQL_DB_PASSWORD} spring.datasource.driver-class-name=com.mysql.jdbc.Driver @@ -22,4 +22,4 @@ spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy # Allows Hibernate to generate SQL optimized for a particular DBMS -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect \ No newline at end of file +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect From c9d8d9d6416efba5080371ca4a95fbfd5a5ddef4 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 00:12:23 +0200 Subject: [PATCH 29/44] Update application.properties --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f464490..0d5c1d3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,7 @@ # = DATA SOURCE # =============================== # Set here configurations for the database connection -spring.datasource.url=jdbc:mysql://${MYSQL_DB_HOST}:${MYSQL_DB_PORT}/${MYSQL_DB_DNAME} +spring.datasource.url=jdbc:mysql://${MYSQL_DB_HOST}:${MYSQL_DB_PORT}/${MYSQL_DB_DNAME}?enabledTLSProtocols=TLSv1.2 spring.datasource.username=${MYSQL_DB_USERNAME} spring.datasource.password=${MYSQL_DB_PASSWORD} spring.datasource.driver-class-name=com.mysql.jdbc.Driver From aab1344ad811cb6485ca43ceb55c53596b8c1a55 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 00:30:34 +0200 Subject: [PATCH 30/44] Update main.yml --- .github/workflows/main.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7397527..de6cd37 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,10 +35,8 @@ jobs: mysql root password: ${{ secrets.RootPassword }} mysql user: 'osama' mysql password: ${{ secrets.DatabasePassword }} - -# - name: Configure Password permission -# run: ALTER USER 'osama'@'localhost' IDENTIFIED WITH mysql_native_password BY ${{ secrets.DatabasePassword }} ; - + - run: mysql --port 3306 -u root -p${{ secrets.RootPassword }} -e "ALTER USER 'osama'@'localhost' IDENTIFIED WITH mysql_native_password BY ${{ secrets.DatabasePassword }} ;" + - name: Build the JAR file run: mvn clean install -DskipTests @@ -55,7 +53,7 @@ jobs: build_docker: - needs: build_local #as we don't push the image unless the + needs: build_local #as we don't push the image unless the build job is done runs-on: ubuntu-latest steps: - name: Check out code From ce12e8e526b4fdf76efed304207ba9743a40a77d Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 00:34:37 +0200 Subject: [PATCH 31/44] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index de6cd37..c1d5892 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: mysql root password: ${{ secrets.RootPassword }} mysql user: 'osama' mysql password: ${{ secrets.DatabasePassword }} - - run: mysql --port 3306 -u root -p${{ secrets.RootPassword }} -e "ALTER USER 'osama'@'localhost' IDENTIFIED WITH mysql_native_password BY ${{ secrets.DatabasePassword }} ;" + - run: mysql --port 3306 -h 127.0.0.1 -u root -p${{ secrets.RootPassword }} -e "ALTER USER 'osama'@'localhost' IDENTIFIED WITH mysql_native_password BY ${{ secrets.DatabasePassword }} ;" - name: Build the JAR file run: mvn clean install -DskipTests From d0749395c4979cc7ec7c5b8f7923b1b6a8a67f92 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 00:50:09 +0200 Subject: [PATCH 32/44] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c1d5892..6928997 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: mysql root password: ${{ secrets.RootPassword }} mysql user: 'osama' mysql password: ${{ secrets.DatabasePassword }} - - run: mysql --port 3306 -h 127.0.0.1 -u root -p${{ secrets.RootPassword }} -e "ALTER USER 'osama'@'localhost' IDENTIFIED WITH mysql_native_password BY ${{ secrets.DatabasePassword }} ;" + - run: mysql --port 3306 -h 127.0.0.1 -u osama -p${{ secrets.RootPassword }} -e "ALTER USER 'osama'@'localhost' IDENTIFIED WITH mysql_native_password BY ${{ secrets.DatabasePassword }} ;" - name: Build the JAR file run: mvn clean install -DskipTests From 1cee19e5eca3617c04b662aa1fc473711f4c8d8e Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 01:01:14 +0200 Subject: [PATCH 33/44] Update main.yml --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6928997..7af9e6c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,8 @@ jobs: distribution: 'adopt' cache: maven - + - name: Docker run hello + run: docker run hello-world - name: Setup MySQL uses: haltuf/mysql-action@master with: From 36436a330df4989b9a9d48a6cfcf2f5df833d6b9 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 01:06:34 +0200 Subject: [PATCH 34/44] Update main.yml --- .github/workflows/main.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7af9e6c..32979ed 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,16 +28,15 @@ jobs: cache: maven - name: Docker run hello - run: docker run hello-world - - name: Setup MySQL - uses: haltuf/mysql-action@master - with: - mysql database: 'springboot_mysql_example' - mysql root password: ${{ secrets.RootPassword }} - mysql user: 'osama' - mysql password: ${{ secrets.DatabasePassword }} - - run: mysql --port 3306 -h 127.0.0.1 -u osama -p${{ secrets.RootPassword }} -e "ALTER USER 'osama'@'localhost' IDENTIFIED WITH mysql_native_password BY ${{ secrets.DatabasePassword }} ;" - + run: docker run mysql -p 3306:3306 + env: + MYSQL_DATABASE: 'springboot_mysql_example' + MYSQL_USER: 'osama' + MYSQL_PASSWORD: ${{secrets.DatabasePassword}} + MYSQL_ROOT_PASSWORD: ${{secrets.DatabasePassword}} + + + - name: Build the JAR file run: mvn clean install -DskipTests From aa3aa59dc71b9d8dc69bc815c5df91bef1cc0509 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 01:09:17 +0200 Subject: [PATCH 35/44] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 32979ed..7e6f388 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: cache: maven - name: Docker run hello - run: docker run mysql -p 3306:3306 + run: docker run -p 3306:3306 mysql env: MYSQL_DATABASE: 'springboot_mysql_example' MYSQL_USER: 'osama' From 26736fcbc3ce6bab69cbb73a33428db6ab9fdfbd Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 01:20:30 +0200 Subject: [PATCH 36/44] Update main.yml --- .github/workflows/main.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7e6f388..d93df3f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,13 +27,8 @@ jobs: distribution: 'adopt' cache: maven - - name: Docker run hello - run: docker run -p 3306:3306 mysql - env: - MYSQL_DATABASE: 'springboot_mysql_example' - MYSQL_USER: 'osama' - MYSQL_PASSWORD: ${{secrets.DatabasePassword}} - MYSQL_ROOT_PASSWORD: ${{secrets.DatabasePassword}} + - name: Docker run mysql + run: docker run -p 3306:3306 --env MYSQL_ROOT_PASSWORD=${{secrets.DatabasePassword}} --env MYSQL_DATABASE='springboot_mysql_example' --env MYSQL_USER='osama' --env MYSQL_PASSWORD=${{secrets.DatabasePassword}} mysql From 8896a4748c9b5bd00d75a379f47c4999a0c62640 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Mon, 8 Nov 2021 01:23:30 +0200 Subject: [PATCH 37/44] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d93df3f..7964223 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: cache: maven - name: Docker run mysql - run: docker run -p 3306:3306 --env MYSQL_ROOT_PASSWORD=${{secrets.DatabasePassword}} --env MYSQL_DATABASE='springboot_mysql_example' --env MYSQL_USER='osama' --env MYSQL_PASSWORD=${{secrets.DatabasePassword}} mysql + run: docker run -p 3306:3306 --env MYSQL_ROOT_PASSWORD=${{secrets.DatabasePassword}} --env MYSQL_DATABASE='springboot_mysql_example' --env MYSQL_USER='osama' --env MYSQL_PASSWORD=${{secrets.DatabasePassword}} -d mysql From 2edcea745be378e6811b03faababf1d5f01ee41c Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Tue, 9 Nov 2021 11:33:11 +0200 Subject: [PATCH 38/44] Add terraform file Terraform is intended to provision cloud infrastructure using the IaaC approach. This file creates a cloud computing instance on GCP with a boot disk of 20 GB size and an additional 100 GB disk locally attached to it to store data --- main.tf | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 main.tf diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..56be2a2 --- /dev/null +++ b/main.tf @@ -0,0 +1,64 @@ +// Configure the Google Cloud provider +provider "google" { + credentials = file("CRED.json") + project = "even-sun-331510" + region = "us-west1" +} + +// Terraform plugin for creating random ids +resource "random_id" "instance_id" { + byte_length = 8 +} + + +// A single Compute Engine instance +resource "google_compute_instance" "default" { + name = "capiter-${random_id.instance_id.hex}" + machine_type = "f1-micro" //As the server is intended to run calculate cimplex equations + zone = "us-west1-a" + + boot_disk { + initialize_params { + image = "debian-cloud/debian-9" + size = "20" + } + } + metadata = { + ssh-keys = "osamamagdy174@gmail.com:${file("~/.ssh/id_ed25519.pub")}" + } + + network_interface { + network = "default" + + access_config { + // Include this section to give the VM an external ip address + } + } + + lifecycle { + ignore_changes = [attached_disk] + } +} + +resource "google_compute_disk" "default" { + name = "capiter-disk" + type = "pd-ssd" //better for intensive applications with low latency + zone = "us-west1-a" + size = "100" + image = "debian-cloud/debian-9" + labels = { + environment = "dev" + } + physical_block_size_bytes = 4096 +} + +//Attach the resource disk to be attached to the compute instance +resource "google_compute_attached_disk" "default" { + disk = google_compute_disk.default.id + instance = google_compute_instance.default.id +} + +// A variable for extracting the external IP address of the instance +output "ip" { + value = google_compute_instance.default.network_interface.0.access_config.0.nat_ip +} \ No newline at end of file From 8a333adfedbdba1202eeb584dfb8a79a84f62c30 Mon Sep 17 00:00:00 2001 From: osamamagdy Date: Tue, 9 Nov 2021 11:46:12 +0200 Subject: [PATCH 39/44] Update github actions Make modifications to the README.md file and the terraform file ignored by github actions as they don't contribute to the building process --- .github/workflows/main.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7964223..ff52560 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,8 +6,14 @@ name: Java CI with Maven on: push: branches: [ master ] + paths-ignore: + - "**/README.md" + - "main.tf" pull_request: branches: [ master ] + paths-ignore: + - "**/README.md" + - "main.tf" jobs: From 38ff6fc88810740237eec4538b061562a3d992f4 Mon Sep 17 00:00:00 2001 From: osamamagdy Date: Tue, 9 Nov 2021 12:28:26 +0200 Subject: [PATCH 40/44] add terraform files --- .github/workflows/main.yml | 4 ++-- .gitignore | 7 +++++++ main.tf => terraform/main.tf | 0 3 files changed, 9 insertions(+), 2 deletions(-) rename main.tf => terraform/main.tf (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ff52560..3c9cccb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,12 +8,12 @@ on: branches: [ master ] paths-ignore: - "**/README.md" - - "main.tf" + - "terraform/**" pull_request: branches: [ master ] paths-ignore: - "**/README.md" - - "main.tf" + - "terraform/**" jobs: diff --git a/.gitignore b/.gitignore index 546f3ee..8a0d56f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,10 @@ target # env file .env k8s_yaml/secret.yaml + +#terraform files +terraform/* + +## except the *.tf files + +!terraform/*.tf \ No newline at end of file diff --git a/main.tf b/terraform/main.tf similarity index 100% rename from main.tf rename to terraform/main.tf From 652a6f4f72f600404ab520e4e03de774ff7f49a6 Mon Sep 17 00:00:00 2001 From: osamamagdy Date: Tue, 9 Nov 2021 13:20:18 +0200 Subject: [PATCH 41/44] update terraform --- terraform/main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/terraform/main.tf b/terraform/main.tf index 56be2a2..6631829 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -45,7 +45,6 @@ resource "google_compute_disk" "default" { type = "pd-ssd" //better for intensive applications with low latency zone = "us-west1-a" size = "100" - image = "debian-cloud/debian-9" labels = { environment = "dev" } From 1fb00258486d4bc7deeefaeff42d026f61586338 Mon Sep 17 00:00:00 2001 From: osamamagdy Date: Thu, 11 Nov 2021 05:10:41 +0200 Subject: [PATCH 42/44] add ingress nginx --- k8s_yaml/online-store-ingress.yaml | 16 ++++++++++++++++ k8s_yaml/online-store-internal-service.yaml | 11 +++++++++++ 2 files changed, 27 insertions(+) create mode 100644 k8s_yaml/online-store-ingress.yaml create mode 100644 k8s_yaml/online-store-internal-service.yaml diff --git a/k8s_yaml/online-store-ingress.yaml b/k8s_yaml/online-store-ingress.yaml new file mode 100644 index 0000000..dfc69dd --- /dev/null +++ b/k8s_yaml/online-store-ingress.yaml @@ -0,0 +1,16 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: online-store-ingress +spec: + rules: + - host: osama.com + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: online-store-internal-service + port: + number: 8080 \ No newline at end of file diff --git a/k8s_yaml/online-store-internal-service.yaml b/k8s_yaml/online-store-internal-service.yaml new file mode 100644 index 0000000..80f0e49 --- /dev/null +++ b/k8s_yaml/online-store-internal-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: online-store-internal-service #this is the one used bby ingress controller +spec: + selector: + app: online-store + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 \ No newline at end of file From 43c96b72fce41353e30ae8fd44962b4e419c6b36 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Thu, 11 Nov 2021 05:44:13 +0200 Subject: [PATCH 43/44] Update README.md --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 694d630..1ee7a57 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ data: ```   Important Note: you can not just place the values in the secrets file as a plain text, first you will need to encode them to base64 (as k8s will decode them by default). And the way to do this in linux `echo -n text | base64 `, or you can use a website like [here](https://www.base64decode.org/)
-### 3 - Build and Run +### 3 - Build and Run with external ip   a - You will need to run `kubectl apply -f .yaml` to apply the configurations of each file. But due to using secrets and services, you will need to execute them in specific order
   I - secrets file
   II - mysql deployment files
@@ -76,3 +76,13 @@ data:   b - The loadbalancer used in online-store-service will assign an external ip → with using minikube, it will be in pending state until you allow it to take ip by typing “minikube service ”  Note: If you want to edit any of the configurations, run `kubectl apply -f .yaml`.
+ +### 3 - Build and Run with ingress and domain name +  a - The configuration files used for this are online-store-ingress.yaml and online-store-internal-service.yaml (this will be applied instead of online-store-service.yaml)
+  b - Install the ingress-controller pod in your k8s cluster → with minikube you type `minikube addons enable ingress`and it will be added in the kube-system namespace
+  c - apply online-store-internal-service.yaml ( note that if you used the above steps exactly, you will have 2 services mapping to the same deployment and it is fine for testing. Otherwise, delete the service online-store-service )
+  d - apply the online-store-ingress.yaml ( note that you will replace the file in step 6 above with )
+  e - this will create an IP address to the hostname osama.com → type `kubectl get ingress` to know
+  f - For testing and with using minikube, this is a dummy hostname that is not available publicly. So we have to map it explicitly to the address created by minkube
+  g - to map in your linux, type `sudo nano /etc/hosts` → add the IP address created in step 5 and the hostname associated with it osama.com
+  h - Go to osama.com in your browser to open the application
From e96d2285c6010eaad7e4a61e13ac7dabfa737354 Mon Sep 17 00:00:00 2001 From: Osama Magdy <59124937+osamamagdy@users.noreply.github.com> Date: Thu, 11 Nov 2021 05:44:39 +0200 Subject: [PATCH 44/44] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ee7a57..f190d79 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ data:  Note: If you want to edit any of the configurations, run `kubectl apply -f .yaml`.
-### 3 - Build and Run with ingress and domain name +### 4 - Build and Run with ingress and domain name   a - The configuration files used for this are online-store-ingress.yaml and online-store-internal-service.yaml (this will be applied instead of online-store-service.yaml)
  b - Install the ingress-controller pod in your k8s cluster → with minikube you type `minikube addons enable ingress`and it will be added in the kube-system namespace
  c - apply online-store-internal-service.yaml ( note that if you used the above steps exactly, you will have 2 services mapping to the same deployment and it is fine for testing. Otherwise, delete the service online-store-service )