From 3d017f35886eccdc7cd342384f40dae8bdb320eb Mon Sep 17 00:00:00 2001 From: David Elie-Dit-Cosaque Date: Thu, 3 Oct 2024 17:58:59 -0400 Subject: [PATCH 1/2] try xgo github action --- .github/workflows/build-latest-image.yml | 34 ++++++++++++------------ Dockerfile | 10 +++++++ scripts/image.sh | 11 ++++---- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build-latest-image.yml b/.github/workflows/build-latest-image.yml index ed51ffb..ab83333 100644 --- a/.github/workflows/build-latest-image.yml +++ b/.github/workflows/build-latest-image.yml @@ -9,8 +9,6 @@ on: env: TERM: xterm-color REGISTRY: quay.io - L2DISCOVERY_IMAGE_NAME: redhat-cne/l2discovery - L2DISCOVERY_IMAGE_TAG: latest jobs: build-exe: name: Build and push image @@ -33,12 +31,21 @@ jobs: with: ref: ${{ github.sha }} - - name: Set up QEMU - uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 - + - name: Cross building images + uses: crazy-max/ghaction-xgo@v3 + with: + xgo_version: latest + go_version: 1.22 + dest: build + prefix: myapp + targets: linux/amd64,linux/arm64 + v: true + x: false + race: false + ldflags: -s -w + buildmode: default + trimpath: true + - name: Authenticate against Quay.io if: ${{ github.ref == 'refs/heads/main' && github.repository_owner == 'redhat-cne' }} uses: docker/login-action@v3 @@ -49,13 +56,6 @@ jobs: username: ${{ secrets.QUAY_ROBOT_USERNAME }} password: ${{ secrets.QUAY_ROBOT_TOKEN }} - - name: Build and push the latest images for multi-arch - uses: docker/build-push-action@32945a339266b759abcbdc89316275140b0fc960 # v6.8.0 + - name: Build and push image if: ${{ github.ref == 'refs/heads/main' && github.repository_owner == 'redhat-cne' }} - with: - context: . - file: Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: | - ${{ env.REGISTRY }}/${{ env.L2DISCOVERY_IMAGE_NAME }}:${{ env.L2DISCOVERY_IMAGE_TAG }} \ No newline at end of file + run: ./scripts/image.sh diff --git a/Dockerfile b/Dockerfile index 922db42..a2c60e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,16 @@ FROM registry.access.redhat.com/ubi9/ubi@sha256:9e6a89ab2a9224712391c77fab2ab01009e387aff42854826427aaf18b98b1ff RUN dnf -y install iputils iproute ethtool pciutils; dnf clean all RUN dnf -y remove python3-setuptools +COPY l2discovery-linux-amd64 /usr/bin +COPY l2discovery-linux-arm64 /usr/bin +RUN \ + if [ "$(uname -m)" = x86_64 ]; then \ + mv /usr/bin/l2discovery-linux-amd64 /usr/bin/l2discovery; \ + elif [ "$(uname -m)" = aarch64 ]; then \ + mv /usr/bin/l2discovery-linux-arm64 /usr/bin/l2discovery; \ + else \ + echo "CPU architecture is not supported." && exit 1; \ + fi COPY l2discovery /usr/bin USER 0 CMD ["/bin/sh", "-c", "/usr/bin/l2discovery"] diff --git a/scripts/image.sh b/scripts/image.sh index 960f123..77b76e7 100755 --- a/scripts/image.sh +++ b/scripts/image.sh @@ -1,10 +1,11 @@ #!/bin/sh set -x -VERSION=latest +VERSION=multi IMAGE_NAME=l2discovery REPO=quay.io/redhat-cne make test -go build l2discovery.go -podman build -t ${IMAGE_NAME} --rm -f Dockerfile . -podman tag ${IMAGE_NAME} ${REPO}/${IMAGE_NAME}:${VERSION} -podman push ${REPO}/${IMAGE_NAME}:${VERSION} +go install github.com/karalabe/xgo@latest +xgo --targets=linux/arm64,linux/amd64 . +podman manifest create ${REPO}/${IMAGE_NAME}:${VERSION} +podman build --platform linux/amd64,linux/arm64 --manifest ${REPO}/${IMAGE_NAME}:${VERSION} --rm -f Dockerfile . +podman manifest push ${REPO}/${IMAGE_NAME}:${VERSION} From 4d5e42d509b2d0a959fb81ac8d4d5ccb748b40b8 Mon Sep 17 00:00:00 2001 From: David Elie-Dit-Cosaque Date: Thu, 3 Oct 2024 18:05:24 -0400 Subject: [PATCH 2/2] fix lint --- scripts/image.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/image.sh b/scripts/image.sh index 77b76e7..aea7481 100755 --- a/scripts/image.sh +++ b/scripts/image.sh @@ -7,5 +7,5 @@ make test go install github.com/karalabe/xgo@latest xgo --targets=linux/arm64,linux/amd64 . podman manifest create ${REPO}/${IMAGE_NAME}:${VERSION} -podman build --platform linux/amd64,linux/arm64 --manifest ${REPO}/${IMAGE_NAME}:${VERSION} --rm -f Dockerfile . +podman build --platform linux/amd64,linux/arm64 --manifest ${REPO}/${IMAGE_NAME}:${VERSION} --rm -f Dockerfile . podman manifest push ${REPO}/${IMAGE_NAME}:${VERSION}