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

Add github actions to build and publish macvtap images. #125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
55 changes: 55 additions & 0 deletions .github/workflows/image-push-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Push container image
Copy link
Contributor

@oshoval oshoval Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please dont add this file
we need to change this prow job instead, after the PR is merged

https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/logs/publish-macvtap-cni/1839203924632932352

a follow-up effort (or maybe pre refactor)
might be good indeed to use git actions instead, but this is up to Miguel decision
note please that if we are doing that, we will need of course to align project-infra, this repo, and CNAO
as CNAO consumes the images, this why imho it better be orthogonal follow-up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @oshoval, I see that the above Prow job uses the script publish.sh to build and push the macvtap CNI image, and it uses the make command. Are you suggesting that we can add multi-platform support(like we added for cnao nad other cnis) by make command and adding export PLATFORMS=all in publish.sh as a follow-up to the PR? This way, we would have two options: we can either continue using the Prow job here to build and publish the image, or we can switch to using GitHub Actions for the same purpose.
cc @maiqueb

Copy link
Contributor

@oshoval oshoval Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally i prefer to add the "all" and stick to prow atm,
switching to git actions require changes on more repos and personally won't have time to focus on that
it can be done as follow-up when time comes, but better not rush it please
thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sure, I will raise new PR with multi support enabled using make commands so that it can be easily work with existing prow job.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can even add the "all" in this PR imo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oshoval I created a new PR: #127 to enable multi-platform builds using the make command. This change ensures compatibility with the existing Prow jobs that handle the build and push of release images. I will add the GitHub Actions changes in a follow-up PR.

Copy link
Contributor

@oshoval oshoval Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks
Please drop the git actions, it is not good to have both atm, and not required
imo we can have just one PR which is 125 + 127 without git actions for now

later on we can consider to move to git actions, but not now please

on:
push:
branches:
- main
tags:
- 'v*.*.*'

env:
REGISTRY: quay.io
IMAGE_NAME: kubevirt/macvtap-cni
BUILD_PLATFORMS: linux/amd64,linux/arm64,linux/s390x

jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

# Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker
if: github.repository_owner == 'kubevirt'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push latest Macvtap container image
if: github.repository_owner == 'kubevirt'
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: ${{ env.BUILD_PLATFORMS }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
file: ./cmd/Dockerfile

- name: Build and push tagged Macvtap container image
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: ${{ env.BUILD_PLATFORMS }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
file: ./cmd/Dockerfile
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ go_sources=$(call rwildcard,cmd/,*.go) $(call rwildcard,pkg/,*.go) $(call rwildc

# Configure Go
export GOOS=linux
export GOARCH=amd64
export GOARCH=$(shell uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to https://github.com/kubevirt/macvtap-cni/pull/125/files#r1874637326
we might need to support all flag as done with other PRs please ?

export CGO_ENABLED=0
export GO111MODULE=on
export GOFLAGS=-mod=vendor
Expand Down Expand Up @@ -69,7 +69,7 @@ vet: $(go_sources) $(GO)
$(GO) vet ./pkg/... ./cmd/... ./tests/...

docker-build:
$(OCI_BIN) build -t ${IMAGE_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG} -f ./cmd/Dockerfile .
$(OCI_BIN) build --build-arg goarch=${GOARCH} -t ${IMAGE_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG} -f ./cmd/Dockerfile .

docker-push:
ifeq ($(OCI_BIN),podman)
Expand Down
13 changes: 11 additions & 2 deletions cmd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# Multi-stage dockerfile building a container image with both binaries included

FROM quay.io/projectquay/golang:1.20 as builder
FROM --platform=$BUILDPLATFORM quay.io/projectquay/golang:1.20 AS builder
ENV GOPATH=/go
WORKDIR /go/src/github.com/kubevirt/macvtap-cni
ARG goarch=
ARG TARGETOS
ARG TARGETARCH
ENV TARGETOS=${TARGETOS:-linux}
ENV TARGETARCH=${TARGETARCH:-amd64}

ENV GOOS=${TARGETOS}
ENV GOARCH=${goarch:-$TARGETARCH}

COPY . .
RUN GOOS=linux CGO_ENABLED=0 go build -o /macvtap-deviceplugin github.com/kubevirt/macvtap-cni/cmd/deviceplugin
RUN GOOS=linux CGO_ENABLED=0 go build -o /macvtap-cni github.com/kubevirt/macvtap-cni/cmd/cni

FROM registry.access.redhat.com/ubi8/ubi-minimal
FROM --platform=linux/${TARGETARCH} registry.access.redhat.com/ubi8/ubi-minimal
COPY --from=builder /macvtap-deviceplugin /macvtap-deviceplugin
COPY --from=builder /macvtap-cni /macvtap-cni