1.根目录需要包含.gitlab-ci.yml和Dockerfile两个文件
2..gitlab-ci.yml
stages:
- build-release
build-release:
stage: build-release
script:
- /usr/local/bin/deploy_yd_docker_image xxx-server
only:
- master
tags:
- xxx
2.Dockerfile
FROM maven:3.6-jdk-8-alpine AS builder
COPY pom.xml /build/
COPY src /build/src/
WORKDIR /build/
ENV SPRING_ACTIVE_PROFILE="prod"
RUN mvn clean install -Dspring.profiles.active=$SPRING_ACTIVE_PROFILE && mvn package -B -e -Dspring.profiles.active=$SPRING_ACTIVE_PROFILE
FROM openjdk:8-jre-alpine
WORKDIR /app
COPY --from=builder /build/target/*.jar /app/app.jar
CMD ["java","-jar","app.jar"]
只要有代码上传master分支gitlab就会自动打包