From e02fa2be091d85758eb339e4f3a25052ae830ac2 Mon Sep 17 00:00:00 2001 From: devome Date: Mon, 15 Nov 2021 13:48:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=A5=BDjar=E5=90=8E?= =?UTF-8?q?=E5=86=8D=E6=9E=84=E5=BB=BA=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 4 +--- Dockerfile | 17 ++--------------- buildx.sh | 9 +++++++-- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/.dockerignore b/.dockerignore index a929e5f0..ab14ee09 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,4 @@ * -!src -!pom.xml +!target/nginxWebUI-*.jar !Dockerfile !entrypoint.sh -!settings.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index da7c396c..ac5a5a64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,3 @@ -FROM alpine:3.14 AS builder -COPY . /build -RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ - && apk add --update --no-cache maven \ - && cd /build \ - && if [[ -s settings.xml ]]; then \ - mkdir -p /root/.m2; \ - cp -fv settings.xml /root/.m2/settings.xml; \ - fi \ - && mvn clean package \ - && mkdir -p /out/home \ - && cp target/nginxWebUI-*.jar /out/home/nginxWebUI.jar -COPY entrypoint.sh /out/usr/local/bin/entrypoint.sh - FROM alpine:3.14 ENV LANG=zh_CN.UTF-8 \ TZ=Asia/Shanghai \ @@ -34,7 +20,8 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \ && echo "${TZ}" > /etc/timezone \ && rm -rf /var/cache/apk/* /tmp/* -COPY --from=builder /out / +COPY target/nginxWebUI-*.jar /home/nginxWebUI.jar +COPY entrypoint.sh /usr/local/bin/entrypoint.sh VOLUME ["/home/nginxWebUI"] ENTRYPOINT ["tini", "entrypoint.sh"] diff --git a/buildx.sh b/buildx.sh index 10c1553b..c91e46dc 100755 --- a/buildx.sh +++ b/buildx.sh @@ -10,21 +10,26 @@ set -o pipefail ## 基本信息 repo="cym1102/nginxwebui" -arch="linux/amd64,linux/arm64,linux/arm/v7" +arch="linux/386,linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/ppc64le,linux/s390x" ver=$(cat pom.xml | grep -A1 nginxWebUI | grep version | grep -oP "\d+\.\d+\.\d+") echo "构建镜像:$repo" echo "构建架构:$arch" echo "构建版本:$ver" -echo "3秒后开始编译..." + +## 编译jar文件 +echo "3秒后开始编译jar文件..." sleep 3 +mvn clean package ## 准备跨平台构建环境 +echo "准备跨平台构建环境" docker pull tonistiigi/binfmt docker run --privileged --rm tonistiigi/binfmt --install all docker buildx create --name builder --use 2>/dev/null || docker buildx use builder docker buildx inspect --bootstrap ## 多平台镜像同时构建并推送 +echo "构建镜像并推送至Docker Hub" docker buildx build \ --cache-from "type=local,src=/tmp/.buildx-cache" \ --cache-to "type=local,dest=/tmp/.buildx-cache" \ -- Gitee