diff --git a/.env b/.env new file mode 100644 index 000000000..8e3c6c03b --- /dev/null +++ b/.env @@ -0,0 +1,12 @@ +MYSQL_TAG=8.0.25 +MYSQL_DATABASE=oh +MYSQL_PORT=3306 +MYSQL_ROOT_PASSWORD=root +MYSQL_USER=isf +MYSQL_PASSWORD=isf123 + +GITHUB_ORG=SteveGT96 +OH_CORE_BRANCH=staging3 +OH_API_BRANCH=staging3-upgrade-2.6.7 +API_VERSION=0.0.1 +API_PORT:8080 \ No newline at end of file diff --git a/Dockerfile.backend b/Dockerfile.backend new file mode 100644 index 000000000..d8d659221 --- /dev/null +++ b/Dockerfile.backend @@ -0,0 +1,22 @@ +FROM maven:3.8-jdk-8 + +ARG GITHUB_ORG +ARG OH_CORE_BRANCH +ARG OH_API_BRANCH +ARG OH_VERSION + +RUN mkdir /oh_web +RUN apt-get update +RUN apt-get install -y git +WORKDIR /oh_web +RUN git clone https://github.com/${GITHUB_ORG}/openhospital-core.git --depth=1 -b ${OH_CORE_BRANCH} +WORKDIR ./openhospital-core +RUN mvn clean install -DskipTests=true +WORKDIR /oh_web +RUN git clone https://github.com/${GITHUB_ORG}/openhospital-api.git --depth=1 -b ${OH_API_BRANCH} +WORKDIR ./openhospital-api +# Database connection must be changed in order to work in docker network +RUN sed -i 's/localhost/database/g' src/main/resources/database.properties +RUN mvn clean install -DskipTests=true + +CMD mvn spring-boot:run \ No newline at end of file diff --git a/Dockerfile.database b/Dockerfile.database new file mode 100644 index 000000000..95ff4ac40 --- /dev/null +++ b/Dockerfile.database @@ -0,0 +1,18 @@ +FROM mysql:5.7.9 + +ARG GITHUB_ORG +ARG OH_CORE_BRANCH + +ENV MYSQL_DATABASE=oh +ENV MYSQL_ROOT_PASSWORD=root +ENV MYSQL_USER=isf +ENV MYSQL_PASSWORD=isf123 + +RUN mkdir /oh_web +RUN apt-get update +RUN apt-get install -y git +WORKDIR /oh_web +RUN git clone https://github.com/${GITHUB_ORG}/openhospital-core.git --depth=1 -b ${OH_CORE_BRANCH} +WORKDIR ./openhospital-core + +EXPOSE 3306 \ No newline at end of file diff --git a/README.md b/README.md index 6a2dd3368..f1c6ebb4d 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,21 @@ For the moment, to build this project you should Service available on localhost:8080 +## How to deploy backend in docker environment + +Make sure you have docker with docker-compose installed, then run the following commands: + + - DOCKER_BUILDKIT=0 docker-compose build [--no-cache] + - docker-compose up + - docker-compose exec database /bin/bash + - cd sql/ + - mysql -u isf -p + - source create_all_demo.sql; + +When done successfully, head over at http://localhost:[API_PORT]/oh-api/swagger-ui.html + +You can change the deployment branch and the repository organization in the .env file. + ## How to contribute You can find the contribution guidelines in the [Open Hospital wiki][contribution-guide]. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..e30a4df2c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +version: '3.8' +services: + database: + container_name: database + restart: always + command: --lower_case_table_names=1 + environment: + - "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" + - "MYSQL_PASSWORD=${MYSQL_PASSWORD}" + - "MYSQL_USER=${MYSQL_USER}" + - "MYSQL_DATABASE=${MYSQL_DATABASE}" + build: + context: . + dockerfile: Dockerfile.database + args: + OH_CORE_BRANCH: ${OH_CORE_BRANCH} + GITHUB_ORG: ${GITHUB_ORG} + ports: + - "${MYSQL_PORT}:3306" + backend: + container_name: backend + build: + context: . + dockerfile: Dockerfile.backend + args: + API_VERSION: ${API_VERSION} + OH_CORE_BRANCH: ${OH_CORE_BRANCH} + OH_API_BRANCH: ${OH_API_BRANCH} + GITHUB_ORG: ${GITHUB_ORG} + restart: always + ports: + - "${API_PORT}:8080" + depends_on: + - database + logging: + driver: "json-file" + options: + max-size: "100m" + max-file: "10" + diff --git a/pom.xml b/pom.xml index 05a5adf40..8d864df85 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.22.RELEASE + 2.6.7 org.isf @@ -16,6 +16,7 @@ 2.0.0 + 1.12.0-SNAPSHOT 1.8 2.1.3 UTF-8 @@ -37,6 +38,11 @@ + + commons-logging + commons-logging + 1.1.1 +