Skip to content

Commit

Permalink
NETOBSERV-848 eBPF agent multi-arch builds (upstream) (#100)
Browse files Browse the repository at this point in the history
* multi arch builds

* keep current targets using defined functions

* trap exit

* makefile consistency
  • Loading branch information
jpinsonneau authored May 11, 2023
1 parent 4272333 commit cc0ca5a
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 97 deletions.
24 changes: 7 additions & 17 deletions .github/workflows/push_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ on:

env:
REGISTRY_USER: netobserv+github_ci
REGISTRY_PASSWORD: ${{ secrets.QUAY_SECRET }}
REGISTRY: quay.io/netobserv
IMAGE: netobserv-ebpf-agent
IMAGE_ORG: netobserv
TAGS: main
ORG: netobserv
VERSION: main

jobs:
push-image:
Expand All @@ -27,22 +26,13 @@ jobs:
go-version: ${{ matrix.go }}
- name: checkout
uses: actions/checkout@v3
- name: build images
run: make ci-images-build
- name: podman login to quay.io
uses: redhat-actions/podman-login@v1
- name: docker login to quay.io
uses: docker/login-action@v2
with:
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
password: ${{ secrets.QUAY_SECRET }}
registry: quay.io
- name: get short sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: push to quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.IMAGE }}
tags: ${{ env.TAGS }} ${{ env.short_sha }}
registry: ${{ env.REGISTRY }}
- name: build and push manifest with images
run: IMAGE_ORG=${{ env.ORG }} VERSION=${{ env.VERSION }} make ci
- name: print image url
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
20 changes: 8 additions & 12 deletions .github/workflows/push_image_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ env:
REGISTRY_USER: netobserv+github_ci
REGISTRY: quay.io/netobserv
IMAGE: netobserv-ebpf-agent
IMAGE_ORG: netobserv
ORG: netobserv
VERSION: temp

jobs:
push-pr-image:
Expand All @@ -28,23 +29,18 @@ jobs:
uses: actions/checkout@v3
with:
ref: "refs/pull/${{ github.event.number }}/merge"
- name: build images
run: SW_VERSION=temp make ci-images-build
- name: podman login to quay.io
uses: redhat-actions/podman-login@v1
- name: docker login to quay.io
uses: docker/login-action@v2
with:
username: ${{ env.REGISTRY_USER }}
password: ${{ secrets.QUAY_SECRET }}
registry: quay.io
- name: get short sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: push to quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.IMAGE }}
tags: ${{ env.short_sha }}
registry: ${{ env.REGISTRY }}
- name: build and push images
run: IMAGE_ORG=${{ env.ORG }} IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.short_sha }} make images
- name: build and push manifest
run: IMAGE_ORG=${{ env.ORG }} VERSION=${{ env.VERSION }} make ci-manifest
- uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,13 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: build images
run: SW_VERSION="${{ env.tag }}" make image-build
- name: podman login to quay.io
uses: redhat-actions/podman-login@v1
- name: docker login to quay.io
uses: docker/login-action@v2
with:
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
registry: quay.io
- name: push to quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.IMAGE }}
tags: ${{ env.tag }}
registry: ${{ env.REGISTRY }}
- name: build and push images
run: VERSION="${{ env.tag }}" make images
- name: print image url
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
31 changes: 31 additions & 0 deletions .mk/shortcuts.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
##@ shortcuts helpers

.PHONY: build
build: prereqs fmt lint test vendors compile ## Test and Build ebpf agent

.PHONY: build-image
build-image: image-build ## Build MULTIARCH_TARGETS images

.PHONY: push-image
push-image: image-push ## Push MULTIARCH_TARGETS images

.PHONY: build-manifest
build-manifest: manifest-build ## Build MULTIARCH_TARGETS manifest

.PHONY: push-manifest
push-manifest: manifest-push ## Push MULTIARCH_TARGETS manifest

.PHONY: images
images: image-build image-push manifest-build manifest-push ## Build and push MULTIARCH_TARGETS images and related manifest

.PHONY: build-ci-manifest
build-ci-manifest: ci-manifest-build ## Build CI manifest

.PHONY: push-ci-manifest
push-ci-manifest: ci-manifest-push ## Push CI manifest

.PHONY: ci-manifest
ci-manifest: ci-manifest-build ci-manifest-push ## Build and push CI manifest

.PHONY: ci
ci: images ci-manifest ## Build and push CI images and manifest
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# We do not use --platform feature to auto fill this ARG because of incompatibility between podman and docker
ARG TARGETPLATFORM=linux/amd64
ARG BUILDPLATFORM=linux/amd64
# Build the manager binary
FROM docker.io/library/golang:1.19 as builder
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.19 as builder

ARG SW_VERSION="unknown"
ARG TARGETPLATFORM
ARG TARGETARCH=amd64
ARG VERSION="unknown"

WORKDIR /opt/app-root

Expand All @@ -14,12 +19,13 @@ COPY vendor/ vendor/
COPY go.mod go.mod
COPY go.sum go.sum
COPY Makefile Makefile
COPY .mk/ .mk/

# Build
RUN make compile
RUN GOARCH=$TARGETARCH make compile

# Create final image from minimal + built binary
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.1
FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi9/ubi-minimal:9.1
WORKDIR /
COPY --from=builder /opt/app-root/bin/netobserv-ebpf-agent .
USER 65532:65532
Expand Down
Loading

0 comments on commit cc0ca5a

Please sign in to comment.