diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..274f298 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/Dockerfile +/localEnv/run/* \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1d0ae64 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "php", + "request": "launch", + "name": "Launch Running", + "program": "${file}", + "cwd": "${fileDirname}", + "port": 9013, + "runtimeExecutable": "/usr/bin/php", + "stopOnEntry": true + }, + { + "type": "php", + "request": "launch", + "name": "Listen PHP Docker", + "port": 9013, + "pathMappings": { + "/var/www/contents-manager-service": "${workspaceRoot}/app/public", + "/home/asdynamics/private/contents-manager-service": "${workspaceRoot}/app/private", + "/home/asdynamics/private/asdphp": "/home/rik/workspace-php/kube/asdphpKube/app/private" + } + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index f3b2c98..8bc7a7c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # Skel Job Processor +Per usare il progetto è sufficiente modificare +- File config +- Environment files in localEnv (specialmente il nome database) +- Rinominare sample.gitlab-ci.yml +- Modificare variabili in gitlab-ci.yml +- Modificare environments in gitlab-ci.yml \ No newline at end of file diff --git a/app/os/opcache.template.ini b/app/os/opcache.template.ini new file mode 100644 index 0000000..d2a11b3 --- /dev/null +++ b/app/os/opcache.template.ini @@ -0,0 +1,12 @@ +[opcache] +opcache.enable=1 +opcache.enable_cli=1 +opcache.memory_consumption=128 +opcache.interned_strings_buffer=16 +opcache.max_accelerated_files=10000 +opcache.revalidate_freq=360 +opcache.validate_timestamps=0 +opcache.preload=/var/www/§PROJECT_BUILDNAME§/load.php +opcache.preload_user=www-data +;opcache.blacklist_filename=/var/www/contents-manager-service/index.php +opcache.fast_shutdown=1 diff --git a/app/os/worker-entrypoint b/app/os/worker-entrypoint new file mode 100644 index 0000000..4e79a64 --- /dev/null +++ b/app/os/worker-entrypoint @@ -0,0 +1,21 @@ +#!/bin/bash + +function exit_func { + echo "SIGTERM detected" + exit 1 +} +trap exit_func SIGTERM SIGINT + +ASD_BINDIR="/home/asdynamics/private/${ASD_BUILDNAME}/bin" + +$ASD_BINDIR/ensureConstraints.php + +if [ $? -ne 0 ]; then + echo "Impossible to ensure constraints"; + exit 1; +fi + +mkdir -p "/tmp/asdynamics/${ASD_BUILDNAME}" + +$ASD_BINDIR/processJobs.php & wait +exit $? diff --git a/app/private/bin/ensureConstraints.php b/app/private/bin/ensureConstraints.php new file mode 100755 index 0000000..15cabc2 --- /dev/null +++ b/app/private/bin/ensureConstraints.php @@ -0,0 +1,27 @@ +#!/usr/local/bin/php + \ No newline at end of file diff --git a/app/private/bin/generateDefaults.php b/app/private/bin/generateDefaults.php new file mode 100755 index 0000000..fae77e2 --- /dev/null +++ b/app/private/bin/generateDefaults.php @@ -0,0 +1,24 @@ +#!/usr/local/bin/php + \ No newline at end of file diff --git a/app/private/bin/processJobs.php b/app/private/bin/processJobs.php new file mode 100644 index 0000000..b1c5ae7 --- /dev/null +++ b/app/private/bin/processJobs.php @@ -0,0 +1,46 @@ +#!/usr/local/bin/php +getFilePath("comunication.shutdown"), + Context::getEnvironment()->getFilePath("comunication.execution"), + Context::getEnvironment()->getFilePath("comunication.idle") + ); + $execStrat = new SingleJobExecutionStrategy(); + $logStrategy = new LogManagerLoggingStrategy("job"); + + $executor = new JobExecutor($storageClass, $comStrategy, $execStrat, $logStrategy ); + $executor->run(); + exit(0); +} +catch (Exception $ex) { + var_dump($ex); + exit(1); +} + + + +?> diff --git a/app/private/common/catalogue.en.php b/app/private/common/catalogue.en.php new file mode 100644 index 0000000..f8a87c1 --- /dev/null +++ b/app/private/common/catalogue.en.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/app/private/common/catalogue.it.php b/app/private/common/catalogue.it.php new file mode 100644 index 0000000..cfd83e3 --- /dev/null +++ b/app/private/common/catalogue.it.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/app/private/common/config.php b/app/private/common/config.php new file mode 100644 index 0000000..cd7913e --- /dev/null +++ b/app/private/common/config.php @@ -0,0 +1,22 @@ +addDirectoryPath("comunication", "/jobComunication"); +Context::getEnvironment()->addFilePath("comunication.shutdown", Context::getEnvironment()->getDirectoryPath("comunication")."/shutdown" ); +Context::getEnvironment()->addFilePath("comunication.execution", Context::getEnvironment()->getDirectoryPath("comunication")."/execution" ); +Context::getEnvironment()->addFilePath("comunication.idle", Context::getEnvironment()->getDirectoryPath("comunication")."/idle" ); + + +?> diff --git a/app/private/lib/catalogue/lib.config.php b/app/private/lib/catalogue/lib.config.php new file mode 100644 index 0000000..4ae5700 --- /dev/null +++ b/app/private/lib/catalogue/lib.config.php @@ -0,0 +1,26 @@ +getDirectoryPath("common"); + +foreach ($supportedLanguages as $language){ + if (file_exists($commonFolder."/catalogue.$language.php") ){ + ASD\CatalogueManager::addCatalogue( + $language, + new ASD\Catalogue( + new ASD\CatalogueFileRetriever($commonFolder."/catalogue.$language.php"), + new ASD\KeyValueCatalogueTokenizer() + ) + ); + } +} + +?> \ No newline at end of file diff --git a/app/private/lib/db/lib.config.php b/app/private/lib/db/lib.config.php new file mode 100644 index 0000000..3cd0376 --- /dev/null +++ b/app/private/lib/db/lib.config.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/app/private/lib/db/lib.inclusion.php b/app/private/lib/db/lib.inclusion.php new file mode 100644 index 0000000..bf14a20 --- /dev/null +++ b/app/private/lib/db/lib.inclusion.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/app/private/lib/db/mongo/customFields/lib.inclusion.php b/app/private/lib/db/mongo/customFields/lib.inclusion.php new file mode 100644 index 0000000..7095e00 --- /dev/null +++ b/app/private/lib/db/mongo/customFields/lib.inclusion.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/app/private/lib/db/mongo/lib.config.php b/app/private/lib/db/mongo/lib.config.php new file mode 100644 index 0000000..2a900ba --- /dev/null +++ b/app/private/lib/db/mongo/lib.config.php @@ -0,0 +1,24 @@ + \ No newline at end of file diff --git a/app/private/lib/db/mongo/lib.inclusion.php b/app/private/lib/db/mongo/lib.inclusion.php new file mode 100644 index 0000000..06c597f --- /dev/null +++ b/app/private/lib/db/mongo/lib.inclusion.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/app/private/lib/db/mongo/models/lib.inclusion.php b/app/private/lib/db/mongo/models/lib.inclusion.php new file mode 100644 index 0000000..7095e00 --- /dev/null +++ b/app/private/lib/db/mongo/models/lib.inclusion.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/app/private/lib/fileSystem/lib.config.php b/app/private/lib/fileSystem/lib.config.php new file mode 100644 index 0000000..925f9ee --- /dev/null +++ b/app/private/lib/fileSystem/lib.config.php @@ -0,0 +1,22 @@ +getDirectoryPath("log"), new FileSystemRuleset(FileSystemRuleset::PERMISSION_READ + FileSystemRuleset::PERMISSION_WRITE)); + +// Lettura e scrittura su storage +FileSystemManager::addRuleset(Context::getEnvironment()->getDirectoryPath("storage"), new FileSystemRuleset(FileSystemRuleset::PERMISSION_READ + FileSystemRuleset::PERMISSION_WRITE)); + +// Lettura e scrittura su tmp +FileSystemManager::addRuleset(Context::getEnvironment()->getDirectoryPath("tmp"), new FileSystemRuleset(FileSystemRuleset::PERMISSION_READ + FileSystemRuleset::PERMISSION_WRITE)); + + +?> \ No newline at end of file diff --git a/app/private/lib/lib.configs.php b/app/private/lib/lib.configs.php new file mode 100644 index 0000000..be61f51 --- /dev/null +++ b/app/private/lib/lib.configs.php @@ -0,0 +1,23 @@ +0){ +foreach ($modules as $module){ + require_once(dirname(__FILE__)."/$module/lib.config.php"); +} +} +date_default_timezone_set("Europe/Rome"); + +?> \ No newline at end of file diff --git a/app/private/lib/lib.inclusions.php b/app/private/lib/lib.inclusions.php new file mode 100644 index 0000000..4eabdc4 --- /dev/null +++ b/app/private/lib/lib.inclusions.php @@ -0,0 +1,20 @@ +0){ + foreach ($modules as $module){ + require_once(dirname(__FILE__)."/$module/lib.inclusion.php"); + } +} + +?> \ No newline at end of file diff --git a/app/private/lib/logger/lib.config.php b/app/private/lib/logger/lib.config.php new file mode 100644 index 0000000..afc8bba --- /dev/null +++ b/app/private/lib/logger/lib.config.php @@ -0,0 +1,26 @@ +get("name") == "local") { + LogManager::addLogger(new FileLogger("core", Context::getEnvironment()->getFilePath("log.core") , Logger::LEVEL_DEBUG)); + LogManager::addLogger(new FileLogger("dao", Context::getEnvironment()->getFilePath("log.dao"), Logger::LEVEL_DEBUG)); +} +else { + $httpClient = new HttpClient(); + LogManager::addLogger(new GELFLogger("core", "http://graylog3:12201/gelf", $httpClient, Logger::LEVEL_NOTICE)); + LogManager::addLogger(new GELFLogger("dao", "http://graylog3:12201/gelf", $httpClient, Logger::LEVEL_NOTICE)); +} + + +?> \ No newline at end of file diff --git a/app/private/load.php b/app/private/load.php new file mode 100644 index 0000000..43ccdf2 --- /dev/null +++ b/app/private/load.php @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/app/public/index.php b/app/public/index.php new file mode 100644 index 0000000..c8cb0da --- /dev/null +++ b/app/public/index.php @@ -0,0 +1,20 @@ + + + + + + + + + Works + + + + IT WORKS! + + + \ No newline at end of file diff --git a/app/public/load.php b/app/public/load.php new file mode 100644 index 0000000..8bc48f8 --- /dev/null +++ b/app/public/load.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/cicd/dockerfiles/build.dockerfile b/cicd/dockerfiles/build.dockerfile new file mode 100644 index 0000000..1af54f6 --- /dev/null +++ b/cicd/dockerfiles/build.dockerfile @@ -0,0 +1,32 @@ +# Use a PHP runtime as a parent image +FROM 662348923997.dkr.ecr.eu-west-1.amazonaws.com/asdynamics/asdphp-kube:§ASDPHP_VERSION§ + +# Set the working directory to /app +WORKDIR /§PROJECT_BUILDNAME§ + +# Install some useful packages +ENV PACKAGES="dnsutils nano" +RUN apt-get update && \ + apt-get install -yq --no-install-recommends $PACKAGES && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Copy the current directory contents into the container at /app +COPY ./app /§PROJECT_BUILDNAME§ + +COPY ./version /§PROJECT_BUILDNAME§ + +COPY ./config /§PROJECT_BUILDNAME§ + +COPY ./install /§PROJECT_BUILDNAME§ + +RUN chmod 744 /§PROJECT_BUILDNAME§/install + +RUN /§PROJECT_BUILDNAME§/install + + +ENTRYPOINT ["§PROJECT_BUILDNAME§-entrypoint"] + +# Make port 80 available to the world outside this container +EXPOSE 80 + diff --git a/cicd/dockerfiles/debug.dockerfile b/cicd/dockerfiles/debug.dockerfile new file mode 100644 index 0000000..e9e99ab --- /dev/null +++ b/cicd/dockerfiles/debug.dockerfile @@ -0,0 +1,34 @@ +# Use a PHP runtime as a parent image +FROM 662348923997.dkr.ecr.eu-west-1.amazonaws.com/asdynamics/asdphp-kube:§ASDPHP_VERSION§ + +# Set the working directory to /app +WORKDIR /§PROJECT_BUILDNAME§ + +# Install some useful packages +ENV PACKAGES="dnsutils nano" +RUN apt-get update && \ + apt-get install -yq --no-install-recommends $PACKAGES && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install XDebug +RUN pecl install xdebug | tail -n 1 | awk -F"\"" '{print $2}' > /usr/local/etc/php/conf.d/xdebug.ini +RUN echo "\n\n[XDebug]\nxdebug.remote_enable = 1\nxdebug.remote_autostart = 1\nxdebug.remote_host = §DEBUG_REMOTE_IP§\nxdebug.remote_port = §DEBUG_REMOTE_PORT§\n" >> /usr/local/etc/php/conf.d/xdebug.ini + +# Copy the current directory contents into the container at /app +COPY ./app /§PROJECT_BUILDNAME§ + +COPY ./version /§PROJECT_BUILDNAME§ + +COPY ./config /§PROJECT_BUILDNAME§ + +COPY ./install /§PROJECT_BUILDNAME§ + +RUN chmod 744 /§PROJECT_BUILDNAME§/install + +RUN /§PROJECT_BUILDNAME§/install + +ENTRYPOINT ["§PROJECT_BUILDNAME§-entrypoint"] + +# Make port 80 available to the world outside this container +EXPOSE 80 diff --git a/cicd/dockerfiles/test.dockerfile b/cicd/dockerfiles/test.dockerfile new file mode 100644 index 0000000..0ab8cc1 --- /dev/null +++ b/cicd/dockerfiles/test.dockerfile @@ -0,0 +1,15 @@ +FROM 662348923997.dkr.ecr.eu-west-1.amazonaws.com/asdynamics/unittest/asdphp-kube:§ASDPHP_VERSION§ + +WORKDIR /§PROJECT_BUILDNAME§ +COPY ./app /§PROJECT_BUILDNAME§ +COPY ./test /test§PROJECT_BUILDNAME§ +COPY ./version /§PROJECT_BUILDNAME§ +COPY ./config /§PROJECT_BUILDNAME§ +COPY ./test/install /§PROJECT_BUILDNAME§ + +RUN chmod 744 /§PROJECT_BUILDNAME§/install + +RUN /§PROJECT_BUILDNAME§/install + +ENTRYPOINT ["/usr/local/bin/phpunit"] +CMD ["--help"] diff --git a/cicd/generateDockerfile.sh b/cicd/generateDockerfile.sh new file mode 100755 index 0000000..a093e35 --- /dev/null +++ b/cicd/generateDockerfile.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +function help() { + printf "\n" + printf "generateDockerfile [-h] [-t|b|d]\n" + printf "\n" + printf "Version name is mandatory.\n" + printf "Available options:\n" + printf "\t -h this message\n" + printf "\t -t Test dockerfile\n" + printf "\t -b Build dockerfile\n" + printf "\t -d Debug dockerfile\n" + printf "\n" +} + +BUILD_VERSION=false +TEST_VERSION=false +DEBUG_VERSION=false + +VERSION_ACTIVE=0 + +while getopts ":hbtd" optname +do + case "$optname" in + "h") + OPTION_HELP=true + ;; + "b") + # This version is the running environment + STARTING_FILE="dockerfiles/build.dockerfile" + VERSION_ACTIVE=$VERSION_ACTIVE+1 + ;; + "t") + # This version is the unit-test only environment + STARTING_FILE="dockerfiles/test.dockerfile" + VERSION_ACTIVE=$VERSION_ACTIVE+1 + ;; + "d") + # This version is a running environment with x-debugger included + STARTING_FILE="dockerfiles/debug.dockerfile" + VERSION_ACTIVE=$VERSION_ACTIVE+1 + ;; + ":") + echo "No argument value for option $OPTARG" + exit 1; + ;; + *) + # Should not occur + echo "Unknown error while processing options" + ;; + esac +done + + +if [[ $VERSION_ACTIVE -eq 0 ]]; then + echo "Impossible to run script without chosing a version between debug, test and build"; + exit 1; +fi + +if [[ $VERSION_ACTIVE -gt 1 ]]; then + echo "Invalid version requested, only one between -t -d and -b can be used, $VERSION_ACTIVE passed"; + exit 1; +fi + + +my_dir="$(dirname "$0")" +DIR_RETURN=`pwd` + +cd "$my_dir" + +source ../config + +# echo "sed -e 's/§ASDPHP_VERSION§/${ASDPHP_VERSION}/g'"; +# echo "sed -e 's/§DEBUG_REMOTE_IP§/${DEBUG_REMOTE_IP}/g'"; +# echo "sed -e 's/§PROJECT_BUILDNAME§/${PROJECT_BUILDNAME}/g'"; +# echo "sed -e 's~§PROJECT_GROUP§~${PROJECT_GROUP}~g'"; +# echo "sed -e 's/§DEBUG_REMOTE_PORT§/${DEBUG_REMOTE_PORT}/g'"; + +cat "$STARTING_FILE" | + sed -e "s/§ASDPHP_VERSION§/${ASDPHP_VERSION}/g" | + sed -e "s/§DEBUG_REMOTE_IP§/${DEBUG_REMOTE_IP}/g" | + sed -e "s/§PROJECT_BUILDNAME§/${PROJECT_BUILDNAME}/g" | + sed -e "s~§PROJECT_GROUP§~${PROJECT_GROUP}~g" | + sed -e "s/§DEBUG_REMOTE_PORT§/${DEBUG_REMOTE_PORT}/g" \ + > "$DIR_RETURN/Dockerfile" + + +cd "$DIR_RETURN" diff --git a/config b/config new file mode 100644 index 0000000..17c5cba --- /dev/null +++ b/config @@ -0,0 +1,7 @@ +ASDPHP_VERSION="2.3.0-rev3" +DEBUG_REMOTE_IP="10.0.1.3" +DEBUG_REMOTE_PORT="9003" + +PROJECT_GROUP="azzurro/microservices" +PROJECT_BUILDNAME="testskel-job" +PROJECT_TYPE="api" \ No newline at end of file diff --git a/install b/install new file mode 100644 index 0000000..2a034d2 --- /dev/null +++ b/install @@ -0,0 +1,30 @@ +#!/bin/bash + +my_dir="$(dirname "$0")" +DIR_RETURN=`pwd` + +cd "$my_dir" + +source ./config + +# Create paths +mkdir -p /home/asdynamics/{private,storage}/$PROJECT_BUILDNAME +mkdir -p /var/log/asdynamics/$PROJECT_BUILDNAME + +# Copy application +cp -r ./private/* /home/asdynamics/private/$PROJECT_BUILDNAME/ + +# Make bin executables +chmod 0744 /home/asdynamics/private/$PROJECT_BUILDNAME/bin/* + +# Overwrite opcache default config +cat ./os/opcache.template.ini | + sed -e "s/§PROJECT_BUILDNAME§/${PROJECT_BUILDNAME}/g" \ + > /usr/local/etc/php/conf.d/opcache.ini + +# Generate Entrypoint +cp "./os/worker-entrypoint" "/usr/local/bin/$PROJECT_BUILDNAME-entrypoint" +chmod 0744 /usr/local/bin/$PROJECT_BUILDNAME-entrypoint + + +cd "$DIR_RETURN" diff --git a/localEnv/composeLocal.sh b/localEnv/composeLocal.sh new file mode 100755 index 0000000..7542d14 --- /dev/null +++ b/localEnv/composeLocal.sh @@ -0,0 +1,63 @@ +#!/bin/bash + + +my_dir="$(dirname "$0")" +DIR_RETURN=`pwd` + +cd "$my_dir" + +echo "Reading project variables" +source ../config + +echo "Generating run env" +mkdir -p run +cd run + +USEDIR="/home/asdynamics/dockerenv/$PROJECT_BUILDNAME" +if [ ! -d "$USEDIR" ]; then + mkdir -p "$USEDIR" +fi + +$(aws ecr get-login --no-include-email) +echo "Generating Dockerfile" +../../cicd/generateDockerfile.sh -d +docker build -t "662348923997.dkr.ecr.eu-west-1.amazonaws.com/$PROJECT_GROUP/$PROJECT_BUILDNAME:local" -f Dockerfile ../../ + +echo "Copying envinronments" +cp ../webserver.env "$USEDIR/webserver.env" + +echo "Generating compose" +../generateCompose.sh -v local + +cd "$USEDIR" + +checkImages=(mongo worker) + +COMPOSER_NAME="local_$PROJECT_BUILDNAME" + +#docker-compose --log-level ERROR pull +docker-compose -p "$COMPOSER_NAME" up -d + +cd "$DIR_RETURN" + +sleep 5 +RED='\033[0;31m' +NC='\033[0m' # No Color +GREEN='\033[0;32m' + + +for img in "${checkImages[@]}" +do + echo "Checking $img..." + INSTANCES=`docker ps | grep "${COMPOSER_NAME}_${img}" | wc -l` + if [[ $INSTANCES -eq 0 ]]; then + printf "${RED}ERROR! No ${img} instance found for ${COMPOSER_NAME} after composing!!!${NC}\n"; + exit 1; + fi +done + +printf "${GREEN}SUCCESS! All instances found after composing${NC}\n"; +exit 0; + + + diff --git a/localEnv/docker-compose.yml b/localEnv/docker-compose.yml new file mode 100644 index 0000000..9e984e8 --- /dev/null +++ b/localEnv/docker-compose.yml @@ -0,0 +1,26 @@ +version: "3" +services: + mongo: + image: mongo:4.4.0 + restart: "no" + networks: + db-network: + volumes: + - §PROJECT_BUILDNAME§-db-persist:/usr/local/mongodb + worker: + image: 662348923997.dkr.ecr.eu-west-1.amazonaws.com/§PROJECT_GROUP§/§PROJECT_BUILDNAME§:§TAG_NAME§ + env_file: webserver.env + restart: "no" + networks: + db-network: + links: + - mongo:database + volumes: + - §PROJECT_BUILDNAME§-storage:/home/asdynamics/storage/§PROJECT_BUILDNAME§ + - §PROJECT_BUILDNAME§-log:/var/log/asdynamics/ + + +volumes: + §PROJECT_BUILDNAME§-storage: + §PROJECT_BUILDNAME§-log: + §PROJECT_BUILDNAME§-db-persist: \ No newline at end of file diff --git a/localEnv/generateCompose.sh b/localEnv/generateCompose.sh new file mode 100755 index 0000000..8b2a455 --- /dev/null +++ b/localEnv/generateCompose.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +my_dir="$(dirname "$0")" +DIR_RETURN=`pwd` + +cd "$my_dir" + +source ../config + +PROJECT_NAME="$PROJECT_BUILDNAME" +TEMPLATE_FILE="docker-compose.yml" + +function help() { + printf "\n" + printf "deploy [-h] [-t|p]\n" + printf "\n" + printf "Available options:\n" + printf "\t -h this message\n" + printf "\t -t Deploy test\n" + printf "\t -p Deploy production\n" + printf "\n" +} + +TAG_NAME="" +DEPLOY_PRODUCTION=false +DEPLOY_TEST=false +FINAL_DIR="" +ENVIRONMENT_TYPE="test" + + +while getopts ":hptv:" optname +do + case "$optname" in + "h") + OPTION_HELP=true + ;; + "v") + TAG_NAME="$OPTARG" + ;; + ":") + echo "No argument value for option $OPTARG" + exit 1; + ;; + *) + # Should not occur + echo "Unknown error while processing options" + ;; + esac +done + +if [[ -z $TAG_NAME ]]; then + echo "You must pass a tagname!"; + exit 1; +fi + +FINAL_DIR="/home/asdynamics/dockerenv/$PROJECT_NAME" +COMPOSE_PROJECT_NAME="local_$PROJECT_NAME" + + + +cat "$TEMPLATE_FILE" | + sed -e "s/§TAG_NAME§/${TAG_NAME}/g" | + sed -e "s/§PROJECT_BUILDNAME§/${PROJECT_BUILDNAME}/g" | + sed -e "s~§PROJECT_GROUP§~${PROJECT_GROUP}~g" | + sed -e "s/§ENVIRONMENT_TYPE§/${ENVIRONMENT_TYPE}/g" \ + > "$FINAL_DIR/docker-compose.yml" + +if [[ $? -ne 0 ]]; then + echo "Compose file creation failed..." + exit 1 +fi + +cd "$DIR_RETURN" diff --git a/localEnv/runNotDetached.sh b/localEnv/runNotDetached.sh new file mode 100755 index 0000000..f70fb2f --- /dev/null +++ b/localEnv/runNotDetached.sh @@ -0,0 +1,22 @@ +#!/bin/bash + + +my_dir="$(dirname "$0")" +DIR_RETURN=`pwd` + +cd "$my_dir" + +echo "Reading project variables" +source ../config + +cd "/home/asdynamics/dockerenv/$PROJECT_BUILDNAME" + +COMPOSER_NAME="local_$PROJECT_BUILDNAME" + +docker-compose -p "$COMPOSER_NAME" up webserver + +cd "$DIR_RETURN" +exit 0; + + + diff --git a/localEnv/testLocal.sh b/localEnv/testLocal.sh new file mode 100755 index 0000000..dbec573 --- /dev/null +++ b/localEnv/testLocal.sh @@ -0,0 +1,21 @@ +#!/bin/bash + + +my_dir="$(dirname "$0")" +DIR_RETURN=`pwd` + +cd "$my_dir" + +source ../config + +echo "Generating run env" +mkdir -p run +cd run + +$(aws ecr get-login --no-include-email) +../../cicd/generateDockerfile.sh -t +docker build -t "$PROJECT_GROUP/$PROJECT_BUILDNAME:unittest-local" -f Dockerfile ../../ + +docker run -e ASD_BUILDNAME="$PROJECT_BUILDNAME" -v $HOME/Scrivania/$PROJECT_BUILDNAME/:/tmp/htmlreport/ "$PROJECT_GROUP/$PROJECT_BUILDNAME:unittest-local" -v -c "/test$PROJECT_BUILDNAME/phpunit.xml" + +cd "$DIR_RETURN" \ No newline at end of file diff --git a/localEnv/webserver.env b/localEnv/webserver.env new file mode 100644 index 0000000..47eef6e --- /dev/null +++ b/localEnv/webserver.env @@ -0,0 +1,7 @@ +ASD_PROJECTNAME=TestSkel +ASD_BUILDNAME=testskel +ASD_ENVIRONMENT_NAME=local +ASD_IS_PRODUCTION=false + +ASD_MONGO_DBNAME=testskel +ASD_MONGO_LOCATION=database diff --git a/sample.gitlab-ci.yml b/sample.gitlab-ci.yml new file mode 100644 index 0000000..cb9eefb --- /dev/null +++ b/sample.gitlab-ci.yml @@ -0,0 +1,100 @@ +variables: + PROJECT_BUILDNAME: "testskel-job" + REPO_URI: "662348923997.dkr.ecr.eu-west-1.amazonaws.com/testskel-job" + KUBE_DEPLOYMENT_NAME: "testskel-job" + KUBE_CONTAINER_NAME: "testskel-job" + + +stages: + - test + - build + - deploy + + +Run Unit: + stage: test + tags: + - docker + - x86 + - aws + only: + - /^[0-9]+\.[0-9]+\.[0-9]+$/ + except: + - branches + - triggers + script: + - echo "Logging into AWS" + - $(aws ecr get-login --no-include-email) + - echo "Generating Unit Test $CI_COMMIT_TAG Dockerfile" + - ./cicd/generateDockerfile.sh -t + - echo "Building Unit Test Image $PROJECT_BUILDNAME-unit:$CI_COMMIT_TAG" + - docker build -t $PROJECT_BUILDNAME-unit:$CI_COMMIT_TAG . + - echo "Running unit tests" + - docker run -e ASD_BUILDNAME="$PROJECT_BUILDNAME" $PROJECT_BUILDNAME-unit:$CI_COMMIT_TAG -c /test$PROJECT_BUILDNAME/phpunit.xml + + +Build image: + stage: build + tags: + - docker + - aws + - x86 + only: + - /^[0-9]+\.[0-9]+\.[0-9]+$/ + except: + - branches + - triggers + script: + - echo "Logging into AWS" + - $(aws ecr get-login --no-include-email) + - echo "Generating Build $CI_COMMIT_TAG Dockerfile" + - ./cicd/generateDockerfile.sh -b + - echo "Setting version file with $CI_COMMIT_TAG" + - echo "$CI_COMMIT_TAG" > version + - echo "Building image with name $REPO_URI:$CI_COMMIT_TAG" + - docker build -t $REPO_URI:$CI_COMMIT_TAG . + - echo "Pushing image" + - docker push "$REPO_URI:$CI_COMMIT_TAG" | cat + + +Deploy Test: + stage: deploy + tags: + - kube + - deployer + - test + only: + - /^[0-9]+\.[0-9]+\.[0-9]+$/ + except: + - branches + - triggers + environment: + name: test + # url: https://$PROJECT_BUILDNAME.azzurroservice.it/test/ + script: + - echo "Updating image version" + - kubectl set image deployments $KUBE_DEPLOYMENT_NAME $KUBE_CONTAINER_NAME="$REPO_URI:$CI_COMMIT_TAG" + - echo "Checking status" + - kubectl rollout status deployments $KUBE_CONTAINER_NAME + + +Deploy Production: + stage: deploy + tags: + - kube + - deployer + - production + only: + - /^[0-9]+\.[0-9]+\.[0-9]+$/ + except: + - branches + - triggers + when: manual + environment: + name: production + # url: https://$PROJECT_BUILDNAME.azzurroservice.it/ + script: + - echo "Updating image version" + - kubectl set image deployments $KUBE_DEPLOYMENT_NAME $KUBE_CONTAINER_NAME="$REPO_URI:$CI_COMMIT_TAG" + - echo "Checking status" + - kubectl rollout status deployments $KUBE_CONTAINER_NAME diff --git a/test/core/TestFake.php b/test/core/TestFake.php new file mode 100644 index 0000000..dcdde2a --- /dev/null +++ b/test/core/TestFake.php @@ -0,0 +1,20 @@ +assertEquals(true,true); + } + } +} + + +?> \ No newline at end of file diff --git a/test/install b/test/install new file mode 100644 index 0000000..715c73d --- /dev/null +++ b/test/install @@ -0,0 +1,10 @@ +#!/bin/bash + +source ./config + +# Create paths +mkdir -p /home/asdynamics/private/$PROJECT_BUILDNAME +mkdir -p /var/log/asdynamics/$PROJECT_BUILDNAME + +# Copy stuff +cp -r ./private/* /home/asdynamics/private/$PROJECT_BUILDNAME/ \ No newline at end of file diff --git a/test/phpunit.xml b/test/phpunit.xml new file mode 100644 index 0000000..606bb6c --- /dev/null +++ b/test/phpunit.xml @@ -0,0 +1,22 @@ + + + + core/TestFake.php + + + + + + + + + diff --git a/test/test.inclusions.php b/test/test.inclusions.php new file mode 100644 index 0000000..f50bf8d --- /dev/null +++ b/test/test.inclusions.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/test/utility/lib.inclusions.php b/test/utility/lib.inclusions.php new file mode 100644 index 0000000..f835601 --- /dev/null +++ b/test/utility/lib.inclusions.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/version b/version new file mode 100644 index 0000000..c2c027f --- /dev/null +++ b/version @@ -0,0 +1 @@ +local \ No newline at end of file