From f6f42b23758d47e9be4590cff94bbd3393a866d7 Mon Sep 17 00:00:00 2001 From: "Kipchumba C. Bett" Date: Wed, 13 Jul 2022 15:09:35 +0300 Subject: [PATCH] Zero installation/configuration but docker --- README.md | 8 +++--- install-maven.sh | 32 ---------------------- prepare-docker-env.sh | 63 +++++++++++++++---------------------------- 3 files changed, 26 insertions(+), 77 deletions(-) delete mode 100644 install-maven.sh diff --git a/README.md b/README.md index f90f65d..594bdc1 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Openmrs-module-queue - Webservices rest module -(Always bundled with the platform) ## Docker development environment -To prepare environment for development of the module, execute the following command; +Prepare the docker development environment by executing the following command; ```bash sh prepare-docker-env.sh @@ -40,7 +40,7 @@ OPENMRS_DB_REPLICAS=1 OMOD_TARGET="queue-1.0.0-SNAPSHOT.omod" ``` -Now, you can spin up an OpenMRS instance with the `required_modules` by executing the following command; +Now, spin up an OpenMRS instance with`required_modules` by executing the following command; ```bash docker-compose up -d @@ -51,12 +51,12 @@ To deploy module changes, run the following command; ```bash docker run --rm -w="/module" -v ${PWD}:/module openmrs/openmrs-core:dev-m1 mvn clean install ``` -Or if you already have maven installed on your system, you can use the following command; +Or if you already have maven installed on your system, use the following command; ```bash mvn clean install ``` -Then, you can restart the container(OpenMRS instance) by executing the following command; +Then, restart the container(OpenMRS instance) by executing the following command; ```bash docker-compose restart diff --git a/install-maven.sh b/install-maven.sh deleted file mode 100644 index ac75832..0000000 --- a/install-maven.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -set -e - -# script to install maven - -# TODO: Automatically grab the latest version -mvn_version=${mvn_version:-3.8.6} -url="http://www.mirrorservice.org/sites/ftp.apache.org/maven/maven-3/${mvn_version}/binaries/apache-maven-${mvn_version}-bin.tar.gz" -install_dir="/opt/maven" - -if [ -d ${install_dir} ]; then - mv ${install_dir} ${install_dir}."$(date +"%Y%m%d")" -fi - -mkdir ${install_dir} -curl -fsSL "${url}" | tar zx --strip-components=1 -C ${install_dir} - -cat << EOF > /etc/profile.d/maven.sh -#!/bin/sh -export MAVEN_HOME=${install_dir} -export M2_HOME=${install_dir} -export M2=${install_dir}/bin -export PATH=${install_dir}/bin:$PATH -EOF - -# shellcheck disable=SC2039 -source /etc/profile.d/maven.sh - -echo maven installed to ${install_dir} -mvn --version - -printf "\n\nTo get mvn in your path, open a new shell or execute: source /etc/profile.d/maven.sh\n" diff --git a/prepare-docker-env.sh b/prepare-docker-env.sh index a03e440..3533044 100644 --- a/prepare-docker-env.sh +++ b/prepare-docker-env.sh @@ -9,25 +9,19 @@ set -e # Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS # graphic logo is a trademark of OpenMRS Inc. -# This script is used to setup the development environment for the module. -# It is run once when the project is first clone/created. +# This script is used to setup the development environment for this module. +# It should be run once when the project is first clone/created. # Downloads the required openmrs modules and installs them. OPENMRS_SDK_PLUGIN="org.openmrs.maven.plugins:openmrs-sdk-maven-plugin" MODULES_DIR="required_modules" -#Extract project artifactId & version +# Extract project artifactId & version OMOD_NAME=$(mvn help:evaluate -Dexpression=project.artifactId | grep -e '^[^\[]') OMOD_VERSION=$(mvn help:evaluate -Dexpression=project.version | grep -e '^[^\[]') echo "Current version: $OMOD_NAME-$OMOD_VERSION" -installMaven() { - # Linux/unix - # TODO: Find a better way to do this (No mvn install needed) - sh install-maven.sh -} - -createEnvironmentVariablesFile() { +create_environment_variables_file() { cat <.env # OpenMRS core platform version. OPENMRS_CORE_VERSION=dev @@ -47,48 +41,35 @@ OMOD_TARGET="$OMOD_NAME-$OMOD_VERSION.omod" EOF } -setupOpenmrsSDK() { - # Setup SDK - mvn ${OPENMRS_SDK_PLUGIN}:setup-sdk -DbatchAnswers=n -B - #docker run -it -v maven-repo:/root/.m2 maven mvn ${OPENMRS_SDK_PLUGIN}:setup-sdk -DbatchAnswers=n -B +prepare_modules_directory() { + # prepare modules directory + if [ -d "${MODULES_DIR}" ]; then + echo "${MODULES_DIR} dir is already exists." + # remove contents + rm -rf "${MODULES_DIR:?}/"* + else + echo "Creating ${MODULES_DIR} directory..." + mkdir -p "${MODULES_DIR}" + fi } -downloadArtifacts() { - # Prepare the modules dir - if [ -d "${MODULES_DIR}" ]; then - echo "${MODULES_DIR} dir is already exists." - # Remove contents - rm -rf "${MODULES_DIR:?}/"* - else - echo "Creating ${MODULES_DIR} directory..." - mkdir -p "${MODULES_DIR}" - fi - +download_artifacts() { mkdir -p artifacts - # Download modules - #docker run -it openmrs/openmrs-core:dev-m1 mvn "$OPENMRS_SDK_PLUGIN":build-distro -Ddistro=module.properties -Ddir=artifacts -B - mvn ${OPENMRS_SDK_PLUGIN}:build-distro -Ddistro=module.properties -Ddir=artifacts -B + # download modules + docker run --rm -w="/module" -v ${PWD}:/module openmrs/openmrs-core:dev mvn ${OPENMRS_SDK_PLUGIN}:build-distro -Ddistro=module.properties -Ddir=artifacts -B + # copy downloaded modules to ${MODULES_DIR} directory cp -r artifacts/web/modules/* "${MODULES_DIR}" - # Clean up artifacts + # clean up artifacts rm -rf artifacts } if [ -x "$(command -v docker)" ]; then installed_docker_version=$(docker --version) echo "Installed ${installed_docker_version}" - echo "configuring openmrs sdk..." - - # docker run openmrs/openmrs-core:dev - # docker run openmrs/openmrs-core:dev mvn - - if ! command -v mvn -v &>/dev/null; then - echo "Installing maven..." - installMaven - fi - setupOpenmrsSDK - downloadArtifacts - createEnvironmentVariablesFile + prepare_modules_directory + download_artifacts + create_environment_variables_file else printf "Please install Docker and re-run prepare script.\n" fi