build: 多架构镜像构建

This commit is contained in:
CaptainB 2022-02-16 23:36:31 +08:00 committed by 刘瑞斌
parent d0bdd8fce1
commit c6a8e58700
3 changed files with 79 additions and 59 deletions

View File

@ -5,6 +5,7 @@ on:
branches: branches:
- master - master
- v1* - v1*
- test-build
workflow_dispatch: workflow_dispatch:
jobs: jobs:
@ -49,11 +50,39 @@ jobs:
- name: Build with Maven - name: Build with Maven
run: mvn -B package --file pom.xml run: mvn -B package --file pom.xml
- name: Push to Docker Hub - name: Unzip jar
uses: docker/build-push-action@v1 run: mkdir -p backend/target/dependency && (cd backend/target/dependency; jar -xf ../*.jar)
- name: Prepare
id: prepare
run: |
DOCKER_IMAGE=metersphere/metersphere
DOCKER_PLATFORMS=linux/amd64,linux/arm64
TAG_NAME=${{ env.GITHUB_REF_SLUG }}
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME} --tag ${DOCKER_IMAGE}:latest"
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${TAG_NAME}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
--build-arg VERSION=${TAG_NAME} \
--build-arg MS_VERSION=${{ env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${DOCKER_IMAGE_TAGS} .
- name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v3
- name: Docker Buildx (build)
run: |
docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }}
- name: Login to Registry
uses: docker/login-action@v1
with: with:
username: metersphere username: metersphere
password: ${{ secrets.DOCKER_HUB_TOKEN }} password: ${{ secrets.DOCKER_HUB_TOKEN }}
repository: metersphere/metersphere
tags: ${{ env.GITHUB_REF_SLUG }} - name: Docker Buildx (push)
build_args: MS_VERSION=${{ env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }} run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }}

View File

@ -1,26 +1,19 @@
FROM openjdk:8-jdk-alpine as build
WORKDIR /workspace/app
COPY backend/target/*.jar .
RUN mkdir -p dependency && (cd dependency; jar -xf ../*.jar)
FROM metersphere/fabric8-java-alpine-openjdk8-jre FROM metersphere/fabric8-java-alpine-openjdk8-jre
LABEL maintainer="FIT2CLOUD <support@fit2cloud.com>" LABEL maintainer="FIT2CLOUD <support@fit2cloud.com>"
ARG MS_VERSION=dev ARG MS_VERSION=dev
ARG DEPENDENCY=/workspace/app/dependency ARG DEPENDENCY=backend/target/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app COPY ${DEPENDENCY}/BOOT-INF/classes /app
RUN mv /app/lib/ms-jmeter-core-*.jar /app/lib/ms-jmeter-core.jar RUN mv /app/lib/ms-jmeter-core-*.jar /app/lib/ms-jmeter-core.jar
RUN mv /app/jmeter /opt/ RUN mv /app/jmeter /opt/
RUN mkdir -p /opt/jmeter/lib/junit RUN mkdir -p /opt/jmeter/lib/junit
ENV JAVA_CLASSPATH=/app:/app/lib/ms-jmeter-core.jar:/app/lib/* ENV JAVA_CLASSPATH=/app:/app/lib/ms-jmeter-core-*.jar:/app/lib/*
ENV JAVA_MAIN_CLASS=io.metersphere.Application ENV JAVA_MAIN_CLASS=io.metersphere.Application
ENV AB_OFF=true ENV AB_OFF=true
ENV MS_VERSION=${MS_VERSION} ENV MS_VERSION=${MS_VERSION}

8
Jenkinsfile vendored
View File

@ -1,7 +1,7 @@
pipeline { pipeline {
agent { agent {
node { node {
label 'metersphere' label 'metersphere-buildx'
} }
} }
options { quietPeriod(600) } options { quietPeriod(600) }
@ -17,15 +17,13 @@ pipeline {
// sh "yarn install" // sh "yarn install"
// sh "cd .." // sh "cd .."
sh "./mvnw clean package --settings ./settings.xml" sh "./mvnw clean package --settings ./settings.xml"
sh "mkdir -p backend/target/dependency && (cd backend/target/dependency; jar -xf ../*.jar)"
} }
} }
} }
stage('Docker build & push') { stage('Docker build & push') {
steps { steps {
sh "docker build --build-arg MS_VERSION=\${TAG_NAME:-\$BRANCH_NAME}-\${GIT_COMMIT:0:8} -t ${IMAGE_NAME}:\${TAG_NAME:-\$BRANCH_NAME} ." sh "docker buildx build --build-arg MS_VERSION=\${TAG_NAME:-\$BRANCH_NAME}-\${GIT_COMMIT:0:8} -t ${IMAGE_PREFIX}/${IMAGE_NAME}:\${TAG_NAME:-\$BRANCH_NAME} --platform linux/amd64,linux/arm64 . --push"
sh "docker tag ${IMAGE_NAME}:\${TAG_NAME:-\$BRANCH_NAME} ${IMAGE_PREFIX}/${IMAGE_NAME}:\${TAG_NAME:-\$BRANCH_NAME}"
sh "docker push ${IMAGE_PREFIX}/${IMAGE_NAME}:\${TAG_NAME:-\$BRANCH_NAME}"
sh "docker rmi ${IMAGE_NAME}:\${TAG_NAME:-\$BRANCH_NAME} ${IMAGE_PREFIX}/${IMAGE_NAME}:\${TAG_NAME:-\$BRANCH_NAME}"
} }
} }
} }