Sfoglia il codice sorgente

chore(CI): better build docker image

zhanghongtong 4 anni fa
parent
commit
d334b27e56
2 ha cambiato i file con 14 aggiunte e 51 eliminazioni
  1. 14 39
      .github/workflows/build_packages.yaml
  2. 0 12
      deploy/docker/Dockerfile

+ 14 - 39
.github/workflows/build_packages.yaml

@@ -356,62 +356,37 @@ jobs:
         path: .
     - name: unzip source code
       run: unzip -q source-${{ matrix.otp }}.zip
-    - name: get version
-      id: version
-      working-directory: source
-      run: echo "::set-output name=version::$(./pkg-vsn.sh)"
     - uses: docker/setup-buildx-action@v1
     - uses: docker/setup-qemu-action@v1
       with:
         image: tonistiigi/binfmt:latest
         platforms: all
-    - uses: docker/build-push-action@v2
-      if: github.event_name != 'release'
+    - uses: docker/metadata-action@v3
+      id: meta
       with:
-        push: false
-        pull: true
-        no-cache: true
-        platforms: linux/amd64,linux/arm64
-        tags: emqx/${{ matrix.profile }}:${{ steps.version.outputs.version }}
-        build-args: |
-          PKG_VSN=${{ steps.version.outputs.version }}
-          BUILD_FROM=ghcr.io/emqx/emqx-builder-helper/5.0:${{ matrix.otp }}-alpine3.14
-          RUN_FROM=alpine:3.14
-          EMQX_NAME=${{ matrix.profile }}
-        file: source/deploy/docker/Dockerfile
-        context: source
+        images: ${{ github.repository_owner }}/${{ matrix.profile }}
+        flavor: |
+          latest=${{ !github.event.release.prerelease }}
+        tags: |
+          type=ref,event=branch
+          type=ref,event=pr
+          type=ref,event=tag
+          type=semver,pattern={{version}}
+          type=semver,pattern={{major}}.{{minor}}
     - uses: docker/login-action@v1
       if: github.event_name == 'release'
       with:
         username: ${{ secrets.DOCKER_HUB_USER }}
         password: ${{ secrets.DOCKER_HUB_TOKEN }}
     - uses: docker/build-push-action@v2
-      if: github.event_name == 'release' && github.event.release.prerelease
       with:
-        push: true
+        push: ${{ github.event_name == 'release' }}
         pull: true
         no-cache: true
         platforms: linux/amd64,linux/arm64
-        tags: emqx/${{ matrix.profile }}:${{ steps.version.outputs.version }}
-        build-args: |
-          PKG_VSN=${{ steps.version.outputs.version }}
-          BUILD_FROM=ghcr.io/emqx/emqx-builder-helper/5.0:${{ matrix.otp }}-alpine3.14
-          RUN_FROM=alpine:3.14
-          EMQX_NAME=${{ matrix.profile }}
-        file: source/deploy/docker/Dockerfile
-        context: source
-    - uses: docker/build-push-action@v2
-      if: github.event_name == 'release' && !github.event.release.prerelease
-      with:
-        push: true
-        pull: true
-        no-cache: true
-        platforms: linux/amd64,linux/arm64
-        tags: |
-          emqx/${{ matrix.profile }}:latest
-          emqx/${{ matrix.profile }}:${{ steps.version.outputs.version }}
+        tags: ${{ steps.meta.outputs.tags }}
+        labels: ${{ steps.meta.outputs.labels }}
         build-args: |
-          PKG_VSN=${{ steps.version.outputs.version }}
           BUILD_FROM=ghcr.io/emqx/emqx-builder-helper/5.0:${{ matrix.otp }}-alpine3.14
           RUN_FROM=alpine:3.14
           EMQX_NAME=${{ matrix.profile }}

+ 0 - 12
deploy/docker/Dockerfile

@@ -20,7 +20,6 @@ RUN apk add --no-cache \
 
 COPY . /emqx
 
-ARG PKG_VSN
 ARG EMQX_NAME=emqx
 
 RUN cd /emqx \
@@ -29,17 +28,6 @@ RUN cd /emqx \
 
 FROM $RUN_FROM
 
-# Basic build-time metadata as defined at http://label-schema.org
-LABEL org.label-schema.docker.dockerfile="Dockerfile" \
-    org.label-schema.license="GNU" \
-    org.label-schema.name="emqx" \
-    org.label-schema.version=${PKG_VSN} \
-    org.label-schema.description="EMQ (Erlang MQTT Broker) is a distributed, massively scalable, highly extensible MQTT messaging broker written in Erlang/OTP." \
-    org.label-schema.url="https://emqx.io" \
-    org.label-schema.vcs-type="Git" \
-    org.label-schema.vcs-url="https://github.com/emqx/emqx" \
-    maintainer="Raymond M Mouthaan <raymondmmouthaan@gmail.com>, Huang Rui <vowstar@gmail.com>, EMQ X Team <support@emqx.io>"
-
 ARG EMQX_NAME=emqx
 
 COPY deploy/docker/docker-entrypoint.sh /usr/bin/