variables: SPRING_ENV: "test" WORKDIR: "/home/gitlab-runner/gitlab-ci/iot-device-cloud/$SPRING_ENV" stages: - build - deploy maven-build: stage: build tags: - test-runner script: # maven打包 - export - mvn clean package -Dmaven.test.skip=true -P dev - mkdir -p $WORKDIR/iot-data-bus - cp iot-data-bus/iot-data-bus-server/target/*SNAPSHOT.jar $WORKDIR/iot-data-bus/app.jar - cp iot-data-bus/iot-data-bus-server/Dockerfile $WORKDIR/iot-data-bus/ - mkdir -p $WORKDIR/iot-device-access - cp iot-device-access/iot-device-access-netty-server/target/*SNAPSHOT.jar $WORKDIR/iot-device-access/app.jar - cp iot-device-access/iot-device-access-netty-server/Dockerfile $WORKDIR/iot-device-access/ - mkdir -p $WORKDIR/iot-device-manager - cp iot-device-manager/iot-device-manager-server/target/*SNAPSHOT.jar $WORKDIR/iot-device-manager/app.jar - cp iot-device-manager/iot-device-manager-server/Dockerfile $WORKDIR/iot-device-manager/ - mkdir -p $WORKDIR/iot-open-api - cp iot-open-api/iot-open-api-server/target/*SNAPSHOT.jar $WORKDIR/iot-open-api/app.jar - cp iot-open-api/iot-open-api-server/Dockerfile $WORKDIR/iot-open-api/ - echo "打包完成" when: manual ########################################################################### deploy-iot-data-bus: stage: deploy tags: - test-runner script: # 文件路径 /cicd-workspace/项目名/模块名/阶段名/文件名 - echo "构造 iot-data-bus docker镜像" - cd $WORKDIR/iot-data-bus/ - docker build --no-cache -t iot-data-bus-$SPRING_ENV . # 强制关闭已开启的容器 并忽略错误,错误会发生在容器不存在的时候 - docker rm -f iot-data-bus-$SPRING_ENV 2> /dev/null # 删除旧的镜像 - docker run -d --net=host --restart=always --name=iot-data-bus-$SPRING_ENV iot-data-bus-$SPRING_ENV --spring.profiles.active=$SPRING_ENV when: manual ########################################################################### deploy-iot-device-access: stage: deploy tags: - test-runner script: # 文件路径 /cicd-workspace/项目名/模块名/阶段名/文件名 - echo "构造 iot-device-access docker镜像" - cd $WORKDIR/iot-device-access/ - docker build --no-cache -t iot-device-access-$SPRING_ENV . # 强制关闭已开启的容器 并忽略错误,错误会发生在容器不存在的时候 - docker rm -f iot-device-access-$SPRING_ENV 2> /dev/null # 删除旧的镜像 - docker run -d --net=host --restart=always --name=iot-device-access-$SPRING_ENV iot-device-access-$SPRING_ENV --spring.profiles.active=$SPRING_ENV when: manual ########################################################################### deploy-iot-device-manager: stage: deploy tags: - test-runner script: # 文件路径 /cicd-workspace/项目名/模块名/阶段名/文件名 - echo "构造 iot-device-manager docker镜像" - cd $WORKDIR/iot-device-manager/ - docker build --no-cache -t iot-device-manager-$SPRING_ENV . # 强制关闭已开启的容器 并忽略错误,错误会发生在容器不存在的时候 - docker rm -f iot-device-manager-$SPRING_ENV 2> /dev/null # 删除旧的镜像 - docker run -d --net=host --restart=always --name=iot-device-manager-$SPRING_ENV iot-device-manager-$SPRING_ENV --spring.profiles.active=$SPRING_ENV when: manual ########################################################################### deploy-iot-open-api: stage: deploy tags: - test-runner script: # 文件路径 /cicd-workspace/项目名/模块名/阶段名/文件名 - echo "构造 iot-open-api docker镜像" - cd $WORKDIR/iot-open-api/ - docker build --no-cache -t iot-open-api-$SPRING_ENV . # 强制关闭已开启的容器 并忽略错误,错误会发生在容器不存在的时候 - docker rm -f iot-open-api-$SPRING_ENV 2> /dev/null # 删除旧的镜像 - docker run -d --net=host --restart=always --name=iot-open-api-$SPRING_ENV iot-open-api-$SPRING_ENV --spring.profiles.active=$SPRING_ENV when: manual