66 lines
2.5 KiB
YAML
66 lines
2.5 KiB
YAML
stages:
|
|
- build
|
|
- deploy
|
|
|
|
cache:
|
|
paths:
|
|
- .m2
|
|
|
|
variables:
|
|
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
|
|
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version --settings $CI_PROJECT_DIR/.m2/settings.xml -DinstallAtEnd=true -DdeployAtEnd=true"
|
|
DEPLOY_PATH: '/opt/app/material-manage-service'
|
|
DEPLOY_DEV_HOST_IP: '192.168.137.123'
|
|
DEPLOY_TEST_PATH: '/home/opt/app/material-manage-service'
|
|
DEPLOY_TEST_HOST_IP: '192.168.137.1'
|
|
DEPLOY_TEST_HOST_PORT: '1022'
|
|
|
|
.import_ssh_key: &import_ssh_key
|
|
before_script:
|
|
- mkdir -p ~/.ssh
|
|
- chmod 700 ~/.ssh
|
|
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
|
|
- echo "${DEPLOY_SSH_KEY}" > ~/.ssh/id_rsa
|
|
- chmod 600 ~/.ssh/id_rsa
|
|
|
|
build:
|
|
image: maven:3.6.3-jdk-11
|
|
stage: build
|
|
artifacts:
|
|
paths:
|
|
- target/*.jar
|
|
expire_in: 1 days
|
|
script:
|
|
- cd $CI_PROJECT_DIR
|
|
- mvn $MAVEN_CLI_OPTS clean compile package -Dmaven.test.skip=true $MAVEN_OPTS
|
|
|
|
deploy:
|
|
<<: *import_ssh_key
|
|
image: kroniak/ssh-client:3.9
|
|
stage: deploy
|
|
dependencies:
|
|
- build
|
|
when: on_success
|
|
script:
|
|
- ssh root@$DEPLOY_DEV_HOST_IP "mkdir -p $DEPLOY_PATH"
|
|
- ssh root@$DEPLOY_DEV_HOST_IP "rm -rf $DEPLOY_PATH/*.jar"
|
|
- scp ./target/*-SNAPSHOT.jar "root@$DEPLOY_DEV_HOST_IP:$DEPLOY_PATH/"
|
|
- ssh root@$DEPLOY_DEV_HOST_IP "mv $DEPLOY_PATH/*-SNAPSHOT.jar $DEPLOY_PATH/app.jar"
|
|
- scp ./docker-compose.yml "root@$DEPLOY_DEV_HOST_IP:$DEPLOY_PATH/"
|
|
- ssh root@$DEPLOY_DEV_HOST_IP "cd $DEPLOY_PATH && su xxs && docker-compose up -d --force-recreate"
|
|
|
|
#deploy_huawei:
|
|
# <<: *import_ssh_key
|
|
# image: kroniak/ssh-client:3.9
|
|
# stage: deploy
|
|
# dependencies:
|
|
# - build
|
|
# when: on_success
|
|
# script:
|
|
# - ssh root@$DEPLOY_TEST_HOST_IP -p $DEPLOY_TEST_HOST_PORT "mkdir -p $DEPLOY_TEST_PATH"
|
|
# - ssh root@$DEPLOY_TEST_HOST_IP -p $DEPLOY_TEST_HOST_PORT "rm -rf $DEPLOY_TEST_PATH/*.jar"
|
|
# - scp -P $DEPLOY_TEST_HOST_PORT ./target/*-SNAPSHOT.jar "root@$DEPLOY_TEST_HOST_IP:$DEPLOY_TEST_PATH/"
|
|
# - ssh root@$DEPLOY_TEST_HOST_IP -p $DEPLOY_TEST_HOST_PORT "mv $DEPLOY_TEST_PATH/*-SNAPSHOT.jar $DEPLOY_TEST_PATH/app.jar"
|
|
# - scp -P $DEPLOY_TEST_HOST_PORT ./docker-compose.yml "root@$DEPLOY_TEST_HOST_IP:$DEPLOY_TEST_PATH/"
|
|
# - ssh root@$DEPLOY_TEST_HOST_IP -p $DEPLOY_TEST_HOST_PORT "cd $DEPLOY_TEST_PATH && su && docker-compose -f docker-compose.huawei.yml up -d --force-recreate"
|