如何在 Github Actions 中构建 Quarkus Native Docker ARM64 容器镜像?

问题描述 投票:0回答:0

我正在尝试为我的 Quarkus 原生应用创建一个基于 ARM64 的 Docker 镜像。似乎有很多讨论,但我找不到一个好的、最新的和简单的工作示例。 我的 Github Actions 工作流目前可以很好地构建 AMD64 图像(见下文工作流),但我很难将其适应基于 ARM64 的 Docker 图像构建并能够在我的 Mac M1 上运行它。有没有人有例子或能指出我正确的方向?

谢谢

name: Generate Docker Image
on:
  workflow_dispatch:
  push:
    branches:
      - 'master'
    tags:
      - 'v*'
jobs:
  build:
    name: Build Native Quarkus
    runs-on: ubuntu-latest
    steps:
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
      - name:  Checkout Source Code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Set up JDK
        uses: actions/setup-java@v3
        with:
          distribution: 'temurin'
          java-version: 17
          check-latest: true
      - name: Cache Maven packages
        uses: actions/cache@v3
        with:
          path: ~/.m2
          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-m2
      - name: Build Native Quarkus
        run: mvn -B install -Pnative -DskipTests
      - name: Login to DockerHub
        uses: docker/login-action@v2
        env:
          username: ${{ secrets.DOCKER_USERNAME }}
        if: ${{env.username != ''}}
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: test/my-test
          tags: |
            type=ref,event=branch
            type=ref,event=pr
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
      - name: Build and push
        uses: docker/build-push-action@v4
        if: ${{ github.event_name != 'pull_request' }}
        with:
          context: "."
          file: './src/main/docker/Dockerfile.native'
          platforms: linux/amd64
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

Dockerfile.native

FROM registry.access.redhat.com/ubi8/ubi-minimal:8.1
WORKDIR /work/
COPY target/*-runner /work/application

# set up permissions for user `1001`
RUN chmod 775 /work /work/application \
  && chown -R 1001 /work \
  && chmod -R "g+rwX" /work \
  && chown -R 1001:root /work

EXPOSE 8081
USER 1001

CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
github-actions quarkus arm64 quarkus-native
© www.soinside.com 2019 - 2024. All rights reserved.