Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try xgo github action #12

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .github/workflows/build-latest-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}
run: ./scripts/image.sh
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
FROM registry.access.redhat.com/ubi9/ubi@sha256:9e6a89ab2a9224712391c77fab2ab01009e387aff42854826427aaf18b98b1ff
RUN dnf -y install iputils iproute ethtool pciutils; dnf clean all

Check failure on line 2 in Dockerfile

View workflow job for this annotation

GitHub Actions / Run Linters, Vet and unit tests

DL3041 warning: Specify version with `dnf install -y <package>-<version>`.
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

Check failure on line 15 in Dockerfile

View workflow job for this annotation

GitHub Actions / Run Linters, Vet and unit tests

DL3002 warning: Last USER should not be root
CMD ["/bin/sh", "-c", "/usr/bin/l2discovery"]
11 changes: 6 additions & 5 deletions scripts/image.sh
Original file line number Diff line number Diff line change
@@ -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}
Loading