deploy on vps

This commit is contained in:
Anton Romanov 2018-09-06 22:50:34 +04:00
parent e9d81fef48
commit cbcc006b13
2 changed files with 44 additions and 13 deletions

View File

@ -1,4 +1,4 @@
image: gradle:alpine image: ubuntu:18.04
cache: cache:
key: "$CI_PROJECT_ID" key: "$CI_PROJECT_ID"
@ -8,10 +8,17 @@ cache:
variables: variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false" 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: build:
stage: build stage: build
script: gradle --build-cache assemble script: ./gradlew assemble
cache: cache:
key: "$CI_PROJECT_ID" key: "$CI_PROJECT_ID"
policy: push policy: push
@ -19,13 +26,15 @@ build:
- build - build
- .gradle - .gradle
deploy:
#test: stage: deploy
# stage: test script:
# script: gradle check - sh deploy/gdccloud/deploy.sh
# cache: only:
# key: "$CI_PROJECT_ID" - master
# policy: pull cache:
# paths: key: "$CI_PROJECT_ID"
# - build policy: pull
# - .gradle paths:
- build
- .gradle

22
deploy/gdccloud/deploy.sh Normal file
View File

@ -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"