From d256c2ddb26a434c4a99c4f0185485d8b09b2960 Mon Sep 17 00:00:00 2001 From: Ramindu Deshapriya Date: Sat, 23 Jul 2022 01:43:32 -0400 Subject: [PATCH 01/10] Dockerized backend --- Dockerfile | 10 ++++++++++ README.md | 8 ++++++++ config.example.bal | 5 +++++ docker-compose.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 config.example.bal create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..91b8039 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +from ballerina/ballerina:latest + +COPY . /app +COPY ./config.example.bal /app/config.bal +WORKDIR /app +RUN mkdir /home/ballerina/.ballerina + +EXPOSE 8080 + +ENTRYPOINT ["bal", "run"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e1cc9d --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +## Medicines for LK - Admin API + +The medicines LK app is comprised of a [React Frontend](https://github.com/LSFLK/MedicinesforLK), [Ballerina Donor API](https://github.com/LSFLK/MedicinesforLK-DonorAPI) and [Ballerina Admin API](https://github.com/LSFLK/MedicinesforLK-AdminAPI). + + +### Run using Docker Compose + +- `docker-compose up -d` \ No newline at end of file diff --git a/config.example.bal b/config.example.bal new file mode 100644 index 0000000..941a0d2 --- /dev/null +++ b/config.example.bal @@ -0,0 +1,5 @@ +configurable string dbHost = "medicinesforlk-mysql"; +configurable int dbPort = 3306; +configurable string dbUser = "root"; +configurable string dbPass = "root"; +configurable string db = "mysql"; \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ec5c9b3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +version: "3.5" + +services: + medicinesforlk-adminapi: + build: + context: ./ + restart: unless-stopped + container_name: medicinesforlk-adminapi + image: medicinesforlk-adminapi + ports: + - "8080:8080" + volumes: + - "./:/home" + - "./target:/app/target" + networks: + medicinesforlk-network: + ipv4_address: 172.16.238.10 + + + mysql: + image: mysql + container_name: medicinesforlk-mysql + command: --default-authentication-plugin=mysql_native_password + environment: + MYSQL_ROOT_PASSWORD: root + ports: + - "3306:3306" + volumes: + - "./mysql-scripts/creation-ddl.sql:/docker-entrypoint-initdb.d/1.sql" + networks: + medicinesforlk-network: + ipv4_address: 172.16.238.11 + + +networks: + medicinesforlk-network: + name: medicinesforlk-network + driver: bridge + ipam: + driver: default + config: + - subnet: 172.16.238.0/24 \ No newline at end of file From c275c4117ef6d7018c1cef305ff2d1e8e2a4fed9 Mon Sep 17 00:00:00 2001 From: Ramindu Deshapriya Date: Sat, 23 Jul 2022 02:19:07 -0400 Subject: [PATCH 02/10] Redefined config file --- Dependencies.toml | 12 ++++++------ Dockerfile | 3 +-- config.bal | 8 ++++---- config.example.bal | 5 ----- docker-compose.yml | 1 + 5 files changed, 12 insertions(+), 17 deletions(-) delete mode 100644 config.example.bal diff --git a/Dependencies.toml b/Dependencies.toml index faf08de..77c869c 100644 --- a/Dependencies.toml +++ b/Dependencies.toml @@ -9,7 +9,7 @@ dependencies-toml-version = "2" [[package]] org = "ballerina" name = "auth" -version = "2.2.1" +version = "2.3.1" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, @@ -41,7 +41,7 @@ dependencies = [ [[package]] org = "ballerina" name = "file" -version = "1.2.2" +version = "1.3.0" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -54,7 +54,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.2.2" +version = "2.3.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -101,7 +101,7 @@ version = "0.0.0" [[package]] org = "ballerina" name = "jwt" -version = "2.2.1" +version = "2.3.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -214,7 +214,7 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.2.1" +version = "2.3.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -234,7 +234,7 @@ dependencies = [ [[package]] org = "ballerina" name = "os" -version = "1.2.1" +version = "1.3.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] diff --git a/Dockerfile b/Dockerfile index 91b8039..d418d26 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,9 @@ from ballerina/ballerina:latest COPY . /app -COPY ./config.example.bal /app/config.bal WORKDIR /app RUN mkdir /home/ballerina/.ballerina EXPOSE 8080 -ENTRYPOINT ["bal", "run"] \ No newline at end of file +ENTRYPOINT ["bal", "run"]dock \ No newline at end of file diff --git a/config.bal b/config.bal index a54d06e..941a0d2 100644 --- a/config.bal +++ b/config.bal @@ -1,5 +1,5 @@ -configurable string dbHost = "dbHost"; +configurable string dbHost = "medicinesforlk-mysql"; configurable int dbPort = 3306; -configurable string dbUser = "dbUser"; -configurable string dbPass = "dbPass"; -configurable string db = "db"; \ No newline at end of file +configurable string dbUser = "root"; +configurable string dbPass = "root"; +configurable string db = "mysql"; \ No newline at end of file diff --git a/config.example.bal b/config.example.bal deleted file mode 100644 index 941a0d2..0000000 --- a/config.example.bal +++ /dev/null @@ -1,5 +0,0 @@ -configurable string dbHost = "medicinesforlk-mysql"; -configurable int dbPort = 3306; -configurable string dbUser = "root"; -configurable string dbPass = "root"; -configurable string db = "mysql"; \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index ec5c9b3..e3c4e35 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,7 @@ services: volumes: - "./:/home" - "./target:/app/target" + - "./Dependencies.toml:/app/Dependencies.toml" networks: medicinesforlk-network: ipv4_address: 172.16.238.10 From 6376c23fbf8e5998538ed41c7ddd501fc88c018b Mon Sep 17 00:00:00 2001 From: Ramindu Deshapriya Date: Sat, 23 Jul 2022 02:47:38 -0400 Subject: [PATCH 03/10] Changed config --- Dockerfile | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d418d26..331bfd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,6 @@ COPY . /app WORKDIR /app RUN mkdir /home/ballerina/.ballerina -EXPOSE 8080 +EXPOSE 443 ENTRYPOINT ["bal", "run"]dock \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e3c4e35..a4bf493 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: container_name: medicinesforlk-adminapi image: medicinesforlk-adminapi ports: - - "8080:8080" + - "443:8080" volumes: - "./:/home" - "./target:/app/target" From 8ae5031fbe3baafbda25c553001ec490e79dce6d Mon Sep 17 00:00:00 2001 From: Ramindu Deshapriya Date: Sat, 23 Jul 2022 13:23:03 -0400 Subject: [PATCH 04/10] Removed chars that could cause an error --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 331bfd2..1f48c8e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,4 @@ RUN mkdir /home/ballerina/.ballerina EXPOSE 443 -ENTRYPOINT ["bal", "run"]dock \ No newline at end of file +ENTRYPOINT ["bal", "run"] \ No newline at end of file From 1fa8f07bee279528389129a5d0d14c7f72a35571 Mon Sep 17 00:00:00 2001 From: Ramindu Deshapriya Date: Sat, 23 Jul 2022 13:23:33 -0400 Subject: [PATCH 05/10] Added newline --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1f48c8e..9927bbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,4 @@ RUN mkdir /home/ballerina/.ballerina EXPOSE 443 -ENTRYPOINT ["bal", "run"] \ No newline at end of file +ENTRYPOINT ["bal", "run"] From cd21728062a82fdf71a92a994da4e7497045e4f0 Mon Sep 17 00:00:00 2001 From: Ramindu Deshapriya Date: Sat, 23 Jul 2022 13:24:22 -0400 Subject: [PATCH 06/10] Added more missing newlines --- README.md | 2 +- config.bal | 2 +- docker-compose.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3e1cc9d..395b0ad 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,4 @@ The medicines LK app is comprised of a [React Frontend](https://github.com/LSFLK ### Run using Docker Compose -- `docker-compose up -d` \ No newline at end of file +- `docker-compose up -d` diff --git a/config.bal b/config.bal index 941a0d2..560d8c8 100644 --- a/config.bal +++ b/config.bal @@ -2,4 +2,4 @@ configurable string dbHost = "medicinesforlk-mysql"; configurable int dbPort = 3306; configurable string dbUser = "root"; configurable string dbPass = "root"; -configurable string db = "mysql"; \ No newline at end of file +configurable string db = "mysql"; diff --git a/docker-compose.yml b/docker-compose.yml index a4bf493..36f7e86 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,4 +40,4 @@ networks: ipam: driver: default config: - - subnet: 172.16.238.0/24 \ No newline at end of file + - subnet: 172.16.238.0/24 From 8c60d07fcfa6e0284dc8800cc84e518661150f65 Mon Sep 17 00:00:00 2001 From: Ramindu Deshapriya Date: Sun, 24 Jul 2022 00:14:05 -0400 Subject: [PATCH 07/10] Updated README with normal run instructions --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 395b0ad..8042d2d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ The medicines LK app is comprised of a [React Frontend](https://github.com/LSFLK/MedicinesforLK), [Ballerina Donor API](https://github.com/LSFLK/MedicinesforLK-DonorAPI) and [Ballerina Admin API](https://github.com/LSFLK/MedicinesforLK-AdminAPI). +### Development + +- [Set up Ballerina](https://ballerina.io/learn/install-ballerina/set-up-ballerina/) +- Run a MySQL server and execute the script `mysql-scripts/creation-ddl.sql` on it to bring up the DDL for the db. +- Modify `config.bal` with the values for the MySQL server you set up. +- `bal run` ### Run using Docker Compose From 5a25c1a5b08c701e271988dd34be7980c1226721 Mon Sep 17 00:00:00 2001 From: Ramindu Deshapriya Date: Sun, 24 Jul 2022 00:17:07 -0400 Subject: [PATCH 08/10] Updated with correct port --- Dockerfile | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9927bbc..c249856 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,6 @@ COPY . /app WORKDIR /app RUN mkdir /home/ballerina/.ballerina -EXPOSE 443 +EXPOSE 9090 ENTRYPOINT ["bal", "run"] diff --git a/docker-compose.yml b/docker-compose.yml index 36f7e86..6febb3b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: container_name: medicinesforlk-adminapi image: medicinesforlk-adminapi ports: - - "443:8080" + - "9090:9090" volumes: - "./:/home" - "./target:/app/target" From 01762dcb1e3cc46d60baacf1ebf49b203b398e9d Mon Sep 17 00:00:00 2001 From: Ramindu Deshapriya Date: Sun, 24 Jul 2022 00:29:40 -0400 Subject: [PATCH 09/10] Added db creation --- README.md | 4 ++-- config.bal | 2 +- docker-compose.yml | 3 ++- mysql-scripts/create-database.sql | 1 + mysql-scripts/creation-ddl.sql | 2 ++ 5 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 mysql-scripts/create-database.sql diff --git a/README.md b/README.md index 8042d2d..0fd929d 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ The medicines LK app is comprised of a [React Frontend](https://github.com/LSFLK ### Development - [Set up Ballerina](https://ballerina.io/learn/install-ballerina/set-up-ballerina/) -- Run a MySQL server and execute the script `mysql-scripts/creation-ddl.sql` on it to bring up the DDL for the db. -- Modify `config.bal` with the values for the MySQL server you set up. +- Run a MySQL server and execute the script `mysql-scripts/creation-ddl.sql` on it to bring up the DDL for the db. You need to have a `medicinesforlk` db in your MySQL server to set up the DDL in. +- Modify `config.bal` with the values for the MySQL server you set up. - `bal run` ### Run using Docker Compose diff --git a/config.bal b/config.bal index 560d8c8..405107f 100644 --- a/config.bal +++ b/config.bal @@ -2,4 +2,4 @@ configurable string dbHost = "medicinesforlk-mysql"; configurable int dbPort = 3306; configurable string dbUser = "root"; configurable string dbPass = "root"; -configurable string db = "mysql"; +configurable string db = "medicinesforlk"; diff --git a/docker-compose.yml b/docker-compose.yml index 6febb3b..26b8f7c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,8 @@ services: ports: - "3306:3306" volumes: - - "./mysql-scripts/creation-ddl.sql:/docker-entrypoint-initdb.d/1.sql" + - "./mysql-scripts/create-database.sql:/docker-entrypoint-initdb.d/1.sql" + - "./mysql-scripts/creation-ddl.sql:/docker-entrypoint-initdb.d/2.sql" networks: medicinesforlk-network: ipv4_address: 172.16.238.11 diff --git a/mysql-scripts/create-database.sql b/mysql-scripts/create-database.sql new file mode 100644 index 0000000..c278fff --- /dev/null +++ b/mysql-scripts/create-database.sql @@ -0,0 +1 @@ +CREATE DATABASE IF NOT EXISTS medicinesforlk; diff --git a/mysql-scripts/creation-ddl.sql b/mysql-scripts/creation-ddl.sql index 2f5c41a..53d0a39 100644 --- a/mysql-scripts/creation-ddl.sql +++ b/mysql-scripts/creation-ddl.sql @@ -1,3 +1,5 @@ +USE medicinesforlk; + CREATE TABLE IF NOT EXISTS SUPPLIER ( SUPPLIERID INT NOT NULL AUTO_INCREMENT, `NAME` VARCHAR (255) NOT NULL, From f09e5e26a37dca8eae2e77b6681cc720008bb186 Mon Sep 17 00:00:00 2001 From: Ramindu Deshapriya Date: Mon, 25 Jul 2022 09:13:39 -0400 Subject: [PATCH 10/10] Added info on testing API after run --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fd929d..5a064d2 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,10 @@ The medicines LK app is comprised of a [React Frontend](https://github.com/LSFLK - [Set up Ballerina](https://ballerina.io/learn/install-ballerina/set-up-ballerina/) - Run a MySQL server and execute the script `mysql-scripts/creation-ddl.sql` on it to bring up the DDL for the db. You need to have a `medicinesforlk` db in your MySQL server to set up the DDL in. - Modify `config.bal` with the values for the MySQL server you set up. -- `bal run` +- `bal run` (runs the API on port 9090) +- Test the API http://localhost:9090/admin/medicalneeds ### Run using Docker Compose - `docker-compose up -d` +- Test the API http://localhost:9090/admin/medicalneeds