diff --git a/app/os/worker-entrypoint b/app/os/worker-entrypoint new file mode 100644 index 0000000..a0faa27 --- /dev/null +++ b/app/os/worker-entrypoint @@ -0,0 +1,16 @@ +#!/bin/bash + +function exit_func { + echo "SIGTERM detected" + exit 1 +} +trap exit_func SIGTERM SIGINT + +ASD_BINDIR="/home/${DDNINJA_AUTHOR}/private/${DDNINJA_BUILDNAME}/bin" + +mkdir -p "/tmp/${DDNINJA_AUTHOR}/${DDNINJA_BUILDNAME}" +mkdir -p "/home/${DDNINJA_AUTHOR}/storage/${DDNINJA_BUILDNAME}/media/" +mkdir -p "/var/log/${DDNINJA_AUTHOR}/${DDNINJA_BUILDNAME}/" + +php /home/${DDNINJA_AUTHOR}/private/${DDNINJA_BUILDNAME}/bin/worker.php & wait +exit $? diff --git a/app/private/bin/worker.php b/app/private/bin/worker.php new file mode 100755 index 0000000..2b16969 --- /dev/null +++ b/app/private/bin/worker.php @@ -0,0 +1,83 @@ +waitUntilThresholdReached(true); +} + + +?> \ No newline at end of file diff --git a/cicd/docker-compose/deploy.yml b/cicd/docker-compose/deploy.yml index 98361da..cb68de0 100644 --- a/cicd/docker-compose/deploy.yml +++ b/cicd/docker-compose/deploy.yml @@ -38,20 +38,24 @@ services: options: max-file: "5" max-size: "150m" - # worker: - # image: 662348923997.dkr.ecr.eu-west-1.amazonaws.com/§PROJECT_GROUP§/edenlandia-worker:§TAG_NAME§ - # env_file: worker.env - # restart: "no" - # networks: - # db-network: - # §PROJECT_BUILDNAME§-network: - # links: - # - mongo:database - # volumes: - # - §PROJECT_BUILDNAME§-storage:/home/asdynamics/storage/edenlandia-worker - # - edenlandia-worker-log:/var/log/asdynamics/ - # - ~/workspace-azzurro/webapps/edenlandia-worker/app/private:/home/asdynamics/private/§PROJECT_BUILDNAME§:ro - # - §PROJECT_BUILDNAME§-job-comms:/jobComunication/ + worker: + image: §PROJECT_REPOSITORY§/§PROJECT_GROUP§/§PROJECT_BUILDNAME§:§TAG_NAME§-worker + env_file: + - environments/common/worker.env + - environments/§ENVIRONMENT_TYPE§/worker.env + depends_on: + - mongo + - memcached + restart: "on-failure:3" + networks: + db-network: + §PROJECT_BUILDNAME§-network: + links: + - mongo:database + volumes: + - ./persistence/worker/storage:/home/§PROJECT_AUTHOR§/storage/§PROJECT_BUILDNAME§ + - §PROJECT_BUILDNAME§-wk-log:/var/log/§PROJECT_AUTHOR§/ + - §PROJECT_BUILDNAME§-job-comms:/jobComunication/ memcached: image: memcached:1.6.9-alpine restart: "on-failure:3" diff --git a/cicd/docker-compose/local-live.yml b/cicd/docker-compose/local-live.yml index ea9629c..208ae32 100644 --- a/cicd/docker-compose/local-live.yml +++ b/cicd/docker-compose/local-live.yml @@ -10,7 +10,7 @@ services: volumes: - §PROJECT_BUILDNAME§-db-persist:/usr/local/mongodb webserver: - image: §PROJECT_REPOSITORY§/§PROJECT_GROUP§/§PROJECT_BUILDNAME§:§TAG_NAME§-debug + image: §PROJECT_REPOSITORY§/§PROJECT_GROUP§/§PROJECT_BUILDNAME§:§TAG_NAME§-webserver-debug env_file: - environments/common/webserver.env - environments/local/webserver.env @@ -28,20 +28,22 @@ services: - §DEBUG_HOST_PROJECT_FOLDER§/app/public:/var/www/§PROJECT_BUILDNAME§:ro - §DEBUG_HOST_PROJECT_FOLDER§/app/private:/home/§PROJECT_AUTHOR§/private/§PROJECT_BUILDNAME§:ro - §PROJECT_BUILDNAME§-job-comms:/jobComunication/ - # worker: - # image: 662348923997.dkr.ecr.eu-west-1.amazonaws.com/§PROJECT_GROUP§/edenlandia-worker:§TAG_NAME§ - # env_file: worker.env - # restart: "no" - # networks: - # db-network: - # §PROJECT_BUILDNAME§-network: - # links: - # - mongo:database - # volumes: - # - §PROJECT_BUILDNAME§-storage:/home/asdynamics/storage/edenlandia-worker - # - edenlandia-worker-log:/var/log/asdynamics/ - # - ~/workspace-azzurro/webapps/edenlandia-worker/app/private:/home/asdynamics/private/§PROJECT_BUILDNAME§:ro - # - §PROJECT_BUILDNAME§-job-comms:/jobComunication/ + worker: + image: §PROJECT_REPOSITORY§/§PROJECT_GROUP§/§PROJECT_BUILDNAME§:§TAG_NAME§-worker-debug + env_file: + - environments/common/worker.env + - environments/local/worker.env + restart: "no" + networks: + db-network: + §PROJECT_BUILDNAME§-network: + links: + - mongo:database + volumes: + - §PROJECT_BUILDNAME§-storage:/home/§PROJECT_AUTHOR§/storage/§PROJECT_BUILDNAME§ + - ./worker-logs:/var/log/§PROJECT_AUTHOR§/ + - §DEBUG_HOST_PROJECT_FOLDER§/app/private:/home/§PROJECT_AUTHOR§/private/§PROJECT_BUILDNAME§:ro + - §PROJECT_BUILDNAME§-job-comms:/jobComunication/ memcached: image: memcached:1.6.9-alpine restart: "no" diff --git a/cicd/dockerfiles/webserver/build.dockerfile b/cicd/dockerfiles/webserver/build.dockerfile index 8e6611e..43216f5 100644 --- a/cicd/dockerfiles/webserver/build.dockerfile +++ b/cicd/dockerfiles/webserver/build.dockerfile @@ -1,5 +1,5 @@ # Use a PHP runtime as a parent image -FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-§FRAMEWORK_TYPE§ +FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-webserver # Set the working directory to /app WORKDIR /§PROJECT_BUILDNAME§ @@ -27,7 +27,7 @@ COPY ./install /§PROJECT_BUILDNAME§ RUN chmod 744 /§PROJECT_BUILDNAME§/install -RUN /§PROJECT_BUILDNAME§/install +RUN /§PROJECT_BUILDNAME§/install webserver ENTRYPOINT ["§PROJECT_BUILDNAME§-entrypoint"] diff --git a/cicd/dockerfiles/webserver/debug.dockerfile b/cicd/dockerfiles/webserver/debug.dockerfile index aecc05d..ef16f4d 100644 --- a/cicd/dockerfiles/webserver/debug.dockerfile +++ b/cicd/dockerfiles/webserver/debug.dockerfile @@ -1,5 +1,5 @@ # Use a PHP runtime as a parent image -FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-§FRAMEWORK_TYPE§ +FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-webserver # Set the working directory to /app WORKDIR /§PROJECT_BUILDNAME§ @@ -27,7 +27,7 @@ COPY ./install /§PROJECT_BUILDNAME§ RUN chmod 744 /§PROJECT_BUILDNAME§/install -RUN /§PROJECT_BUILDNAME§/install +RUN /§PROJECT_BUILDNAME§/install webserver ENTRYPOINT ["§PROJECT_BUILDNAME§-entrypoint"] diff --git a/cicd/dockerfiles/webserver/test.dockerfile b/cicd/dockerfiles/webserver/test.dockerfile index 994734f..8c28ebe 100644 --- a/cicd/dockerfiles/webserver/test.dockerfile +++ b/cicd/dockerfiles/webserver/test.dockerfile @@ -1,4 +1,4 @@ -FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-§FRAMEWORK_TYPE§-unit +FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-webserver-unit WORKDIR /§PROJECT_BUILDNAME§ COPY ./app /§PROJECT_BUILDNAME§ @@ -9,7 +9,7 @@ COPY ./test/install /§PROJECT_BUILDNAME§ RUN chmod 744 /§PROJECT_BUILDNAME§/install -RUN /§PROJECT_BUILDNAME§/install +RUN /§PROJECT_BUILDNAME§/install webserver ENTRYPOINT ["/usr/local/bin/phpunit"] CMD ["--help"] diff --git a/cicd/dockerfiles/worker/build.dockerfile b/cicd/dockerfiles/worker/build.dockerfile index 8e6611e..3717665 100644 --- a/cicd/dockerfiles/worker/build.dockerfile +++ b/cicd/dockerfiles/worker/build.dockerfile @@ -1,5 +1,5 @@ # Use a PHP runtime as a parent image -FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-§FRAMEWORK_TYPE§ +FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-worker # Set the working directory to /app WORKDIR /§PROJECT_BUILDNAME§ @@ -27,7 +27,7 @@ COPY ./install /§PROJECT_BUILDNAME§ RUN chmod 744 /§PROJECT_BUILDNAME§/install -RUN /§PROJECT_BUILDNAME§/install +RUN /§PROJECT_BUILDNAME§/install worker ENTRYPOINT ["§PROJECT_BUILDNAME§-entrypoint"] diff --git a/cicd/dockerfiles/worker/debug.dockerfile b/cicd/dockerfiles/worker/debug.dockerfile index aecc05d..98a6676 100644 --- a/cicd/dockerfiles/worker/debug.dockerfile +++ b/cicd/dockerfiles/worker/debug.dockerfile @@ -1,5 +1,5 @@ # Use a PHP runtime as a parent image -FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-§FRAMEWORK_TYPE§ +FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-worker # Set the working directory to /app WORKDIR /§PROJECT_BUILDNAME§ @@ -27,7 +27,7 @@ COPY ./install /§PROJECT_BUILDNAME§ RUN chmod 744 /§PROJECT_BUILDNAME§/install -RUN /§PROJECT_BUILDNAME§/install +RUN /§PROJECT_BUILDNAME§/install worker ENTRYPOINT ["§PROJECT_BUILDNAME§-entrypoint"] diff --git a/cicd/dockerfiles/worker/test.dockerfile b/cicd/dockerfiles/worker/test.dockerfile index 994734f..52b139c 100644 --- a/cicd/dockerfiles/worker/test.dockerfile +++ b/cicd/dockerfiles/worker/test.dockerfile @@ -1,4 +1,4 @@ -FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-§FRAMEWORK_TYPE§-unit +FROM §FRAMEWORK_REPOSITORY§/§FRAMEWORK_IMAGE§:§FRAMEWORK_VERSION§-worker-unit WORKDIR /§PROJECT_BUILDNAME§ COPY ./app /§PROJECT_BUILDNAME§ @@ -9,7 +9,7 @@ COPY ./test/install /§PROJECT_BUILDNAME§ RUN chmod 744 /§PROJECT_BUILDNAME§/install -RUN /§PROJECT_BUILDNAME§/install +RUN /§PROJECT_BUILDNAME§/install worker ENTRYPOINT ["/usr/local/bin/phpunit"] CMD ["--help"] diff --git a/cicd/environments/common/worker.env b/cicd/environments/common/worker.env new file mode 100644 index 0000000..fb799ef --- /dev/null +++ b/cicd/environments/common/worker.env @@ -0,0 +1,3 @@ +DDNINJA_PROJECTNAME=FDN2 +DDNINJA_BUILDNAME=fdn2 +DDNINJA_AUTHOR=ddninja \ No newline at end of file diff --git a/cicd/environments/local/worker.env b/cicd/environments/local/worker.env new file mode 100644 index 0000000..0fae887 --- /dev/null +++ b/cicd/environments/local/worker.env @@ -0,0 +1,7 @@ +DDNINJA_ENVIRONMENT_NAME=local +DDNINJA_IS_PRODUCTION=false + +DDNINJA_MONGO_DBNAME=fdn2 +DDNINJA_MONGO_LOCATION=database + +DDNINJA_PUBLIC_URL=http://www.fdn2.loc:8800 diff --git a/cicd/environments/production/worker.env b/cicd/environments/production/worker.env new file mode 100644 index 0000000..e2d1bd7 --- /dev/null +++ b/cicd/environments/production/worker.env @@ -0,0 +1,7 @@ +DDNINJA_ENVIRONMENT_NAME=production +DDNINJA_IS_PRODUCTION=true + +DDNINJA_MONGO_DBNAME=fdn2 +DDNINJA_MONGO_LOCATION=database + +DDNINJA_PUBLIC_URL=http://preproduction.ifattidinapoli.it diff --git a/cicd/environments/test/worker.env b/cicd/environments/test/worker.env new file mode 100644 index 0000000..b9c6c5a --- /dev/null +++ b/cicd/environments/test/worker.env @@ -0,0 +1,7 @@ +DDNINJA_ENVIRONMENT_NAME=test +DDNINJA_IS_PRODUCTION=false + +DDNINJA_MONGO_DBNAME=fdn2_test +DDNINJA_MONGO_LOCATION=database + +DDNINJA_PUBLIC_URL=http://test.ifattidinapoli.it diff --git a/config b/config index a71baea..c8656d2 100644 --- a/config +++ b/config @@ -4,7 +4,6 @@ declare -A CONFIG=( ["FRAMEWORK_REPOSITORY"]="299952237278.dkr.ecr.eu-west-1.amazonaws.com" ["FRAMEWORK_IMAGE"]="ddninja/phpframework" ["FRAMEWORK_VERSION"]="2.5.4" - ["FRAMEWORK_TYPE"]="webserver" ["FRAMEWORK_AUTHOR"]="ddninja" ["PROJECT_REPOSITORY"]="299952237278.dkr.ecr.eu-west-1.amazonaws.com" @@ -23,7 +22,6 @@ declare -A CONFIG=( FRAMEWORK_REPOSITORY=${CONFIG['FRAMEWORK_REPOSITORY']} FRAMEWORK_IMAGE=${CONFIG['FRAMEWORK_IMAGE']} FRAMEWORK_VERSION=${CONFIG['FRAMEWORK_VERSION']} -FRAMEWORK_TYPE=${CONFIG['FRAMEWORK_TYPE']} FRAMEWORK_AUTHOR=${CONFIG['FRAMEWORK_AUTHOR']} PROJECT_REPOSITORY=${CONFIG['PROJECT_REPOSITORY']} diff --git a/install b/install index f5fc21b..e080ba6 100644 --- a/install +++ b/install @@ -1,5 +1,11 @@ #!/bin/bash +if [ "$#" -ne 1 ]; then + echo "Illegal number of parameters" +fi + +TYPE=$1 + my_dir="$(dirname "$0")" DIR_RETURN=`pwd` @@ -25,11 +31,13 @@ chown -R www-data:www-data /var/log/$PROJECT_AUTHOR chmod 0744 /home/$PROJECT_AUTHOR/private/$PROJECT_BUILDNAME/bin/* # Apache -cat ./os/000-${PROJECT_TYPE}.template.conf | - sed -e "s/§PROJECT_BUILDNAME§/${PROJECT_BUILDNAME}/g" \ - > /etc/apache2/sites-available/000-default.conf +if [[ $TYPE == "webserver" ]]; then + cat ./os/000-${PROJECT_TYPE}.template.conf | + sed -e "s/§PROJECT_BUILDNAME§/${PROJECT_BUILDNAME}/g" \ + > /etc/apache2/sites-available/000-default.conf -a2enmod rewrite + a2enmod rewrite +fi # Overwrite opcache default config cat ./os/opcache.template.ini | @@ -40,7 +48,7 @@ cat ./os/opcache.template.ini | cat ./os/php.template.ini > /usr/local/etc/php/php.ini # Generate Entrypoint -cp "./os/webserver-entrypoint" "/usr/local/bin/$PROJECT_BUILDNAME-entrypoint" +cp "./os/${TYPE}-entrypoint" "/usr/local/bin/$PROJECT_BUILDNAME-entrypoint" chmod 0744 /usr/local/bin/$PROJECT_BUILDNAME-entrypoint diff --git a/private/crontab/core.5minutes.php b/private/crontab/core.5minutes.php deleted file mode 100644 index 8adf356..0000000 --- a/private/crontab/core.5minutes.php +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/php -core->loggingCatalogManager->getCatalog($unex->getMessage(),$unex->getData()); -// LoggingFacilityManager::getLogger("task")->log(LoggingFacility::$LEVEL_ERROR,"log.task.errorWhileExecutingTask",array("ProcessMailQueue.php",$msg),true); -// } -// catch (Exception $ex){ -// $msg = $application->core->loggingCatalogManager->getCatalog($ex->getMessage()); -// LoggingFacilityManager::getLogger("task")->log(LoggingFacility::$LEVEL_ERROR,"log.task.errorWhileExecutingTask",array("ProcessMailQueue.php",$msg),true); -// } - - -?> \ No newline at end of file diff --git a/private/crontab/core.monthly.php b/private/crontab/core.monthly.php deleted file mode 100644 index b874a34..0000000 --- a/private/crontab/core.monthly.php +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/php - \ No newline at end of file diff --git a/private/crontab/core.weekly.php b/private/crontab/core.weekly.php deleted file mode 100644 index 9ffa646..0000000 --- a/private/crontab/core.weekly.php +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/php -core->loggingCatalogManager->getCatalog($unex->getMessage(),$unex->getData()); -// LoggingFacilityManager::getLogger("task")->log(LoggingFacility::$LEVEL_ERROR,"log.task.errorWhileExecutingTask",array("ProcessMailQueue.php",$msg),true); -// } -// catch (Exception $ex){ -// $msg = $application->core->loggingCatalogManager->getCatalog($ex->getMessage()); -// LoggingFacilityManager::getLogger("task")->log(LoggingFacility::$LEVEL_ERROR,"log.task.errorWhileExecutingTask",array("ProcessMailQueue.php",$msg),true); -// } - -?> \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh index 0341b5a..cdbe948 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -97,7 +97,7 @@ if [[ $UNIT_MODE -gt 0 ]]; then OPTS+="v" fi - $DIR/generateDockerfile.sh -$OPTS -o $DOCKERFILE + $DIR/generateDockerfile.sh -I "${TYPE}" -$OPTS -o $DOCKERFILE msg "Building project image $TAG" docker build -t $PROJECT_REPOSITORY/$PROJECT_GROUP/$PROJECT_BUILDNAME:$TAG-unit -f $DOCKERFILE . @@ -112,7 +112,7 @@ if [[ $DEBUG_MODE -gt 0 ]]; then OPTS+="v" fi - $DIR/generateDockerfile.sh -$OPTS -o $DOCKERFILE + $DIR/generateDockerfile.sh -I "${TYPE}" -$OPTS -o $DOCKERFILE msg "Building project image $TAG" docker build -t $PROJECT_REPOSITORY/$PROJECT_GROUP/$PROJECT_BUILDNAME:$TAG-debug -f $DOCKERFILE . diff --git a/scripts/core.sh b/scripts/core.sh index 3ce74f4..c3b14d3 100755 --- a/scripts/core.sh +++ b/scripts/core.sh @@ -125,10 +125,14 @@ if [[ $UNIT_MODE -eq 1 ]]; then BUILDOPT+="v" UNITOPT="-v" fi - msg "running ./build.sh -$BUILDOPT -t $TAG" - ./build.sh -$BUILDOPT -t $TAG + msg "running ./build.sh -I webserver -$BUILDOPT -t \"$TAG-webserver\"" + ./build.sh -I webserver -$BUILDOPT -t "$TAG-webserver" - ./run-unit.sh $UNITOPT -t $TAG + msg "running ./build.sh -I worker -$BUILDOPT -t \"$TAG-worker\"" + ./build.sh -I worker -$BUILDOPT -t "$TAG-worker" + + ./run-unit.sh $UNITOPT -t $TAG-webserver + ./run-unit.sh $UNITOPT -t $TAG-worker fi if [[ $PUBLISH_MODE -eq 1 ]]; then @@ -151,7 +155,13 @@ if [[ $PUBLISH_MODE -eq 1 ]]; then ./publish.sh $VERBOPT -t "$TAG-webserver" - + # WORKER + msg "running ./build.sh -I worker -$BUILDOPT -t $TAG-worker" + ./build.sh -I webserver -$BUILDOPT -t "$TAG-worker" + + ./run-unit.sh $VERBOPT -t "$TAG-worker" + + ./publish.sh $VERBOPT -t "$TAG-worker" if [[ $TAG_IMPLICIT -ne 1 ]]; then git tag $TAG @@ -165,8 +175,10 @@ if [[ $DEBUG_MODE -eq 1 ]]; then if [[ $VERBOSE -gt 0 ]]; then BUILDOPT+="v" fi - msg "running ./build.sh -$BUILDOPT -t $TAG" - ./build.sh -$BUILDOPT -t $TAG + msg "running ./build.sh -I webserver -$BUILDOPT -t $TAG-webserver" + ./build.sh -$BUILDOPT -I webserver -t $TAG-webserver + msg "running ./build.sh -I worker -$BUILDOPT -t $TAG-worker" + ./build.sh -$BUILDOPT -I worker -t $TAG-worker OUT_FOLDER="/home/$PROJECT_AUTHOR/$PROJECT_BUILDNAME/local" mkdir -p $OUT_FOLDER