From cbcc006b131ce5426145be2803571845bb3957ac Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 6 Sep 2018 22:50:34 +0400 Subject: [PATCH] deploy on vps --- .gitlab-ci.yml | 35 ++++++++++++++++++++++------------- deploy/gdccloud/deploy.sh | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 deploy/gdccloud/deploy.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 340d77f..8d76138 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: gradle:alpine +image: ubuntu:18.04 cache: key: "$CI_PROJECT_ID" @@ -8,10 +8,17 @@ cache: variables: GRADLE_OPTS: "-Dorg.gradle.daemon=false" -#before_script: +before_script: + - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + - apt-get install openjdk-8-jdk git -y + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + build: stage: build - script: gradle --build-cache assemble + script: ./gradlew assemble cache: key: "$CI_PROJECT_ID" policy: push @@ -19,13 +26,15 @@ build: - build - .gradle - -#test: -# stage: test -# script: gradle check -# cache: -# key: "$CI_PROJECT_ID" -# policy: pull -# paths: -# - build -# - .gradle \ No newline at end of file +deploy: + stage: deploy + script: + - sh deploy/gdccloud/deploy.sh + only: + - master + cache: + key: "$CI_PROJECT_ID" + policy: pull + paths: + - build + - .gradle \ No newline at end of file diff --git a/deploy/gdccloud/deploy.sh b/deploy/gdccloud/deploy.sh new file mode 100644 index 0000000..a76a5a4 --- /dev/null +++ b/deploy/gdccloud/deploy.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +USERSERVER="root@212.8.234.87" + +PROCESS_NAME="java -jar ng-tracker" + +PROCESS_RUNNING=`ssh -oStrictHostKeyChecking=no $USERSERVER "pgrep -f '$PROCESS_NAME' > /dev/null"` + +if $PROCESS_RUNNING +then + ssh $USERSERVER "pkill -f '$PROCESS_NAME'" +else + echo "not running" +fi + +./gradlew assemble + +ssh $USERSERVER "cd /tmp && rm -rf ng-tracker*.jar && echo `date` 'killed' >> log_ng" +scp build/libs/ng-tracker-0.1.0-SNAPSHOT.jar $USERSERVER:/tmp/ng-tracker-0.1.0-SNAPSHOT.jar +ssh $USERSERVER -f "cd /tmp/ && /opt/jdk1.8.0_144/bin/java -jar ng-tracker-0.1.0-SNAPSHOT.jar -Xms 512m -Xmx 1024m --server.port=8443 --server.http.port=8080 >> /home/user/logfile_ng" & +sleep 10 +echo "is deployed" \ No newline at end of file