config(ci): 新增 ci 配置
This commit is contained in:
47
.gitlab-ci.yml
Normal file
47
.gitlab-ci.yml
Normal file
@@ -0,0 +1,47 @@
|
||||
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'
|
||||
|
||||
.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 -f $DEPLOY_PATH/*.jar"
|
||||
- scp ./target/*.jar "root@$DEPLOY_DEV_HOST_IP:$DEPLOY_PATH/"
|
||||
- ssh root@$DEPLOY_DEV_HOST_IP "mv $DEPLOY_PATH/*.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"
|
Reference in New Issue
Block a user