Skip to content

Commit

Permalink
multi arch builds
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinsonneau committed Apr 25, 2023
1 parent d1d36c2 commit ebc2349
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
go: ['1.18','1.19']

steps:
- name: install make
run: sudo apt-get install make
Expand Down
24 changes: 7 additions & 17 deletions .github/workflows/push_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ on:

env:
REGISTRY_USER: netobserv+github_ci
REGISTRY_PASSWORD: ${{ secrets.QUAY_SECRET }}
REGISTRY: quay.io/netobserv
REG_IMAGE: network-observability-console-plugin
REG_TAG: main
IMAGE: network-observability-console-plugin
VERSION: main

jobs:
push-image:
Expand All @@ -26,23 +25,14 @@ jobs:
go-version: ${{ matrix.go }}
- name: checkout
uses: actions/checkout@v3
- name: build images
run: BASE_IMAGE="${{ env.REGISTRY }}/${{ env.REG_IMAGE }}" TAG="${{ env.REG_TAG }}" make build-ci-images
- 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.REG_IMAGE }}
tags: ${{ env.REG_TAG }} ${{ env.short_sha }}
registry: ${{ env.REGISTRY }}
- name: build and push manifest with images
run: VERSION=${{ env.VERSION }} make ci
- name: print image url
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"

Expand Down
20 changes: 8 additions & 12 deletions .github/workflows/push_image_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ on:
env:
REGISTRY_USER: netobserv+github_ci
REGISTRY: quay.io/netobserv
REG_IMAGE: network-observability-console-plugin
IMAGE: network-observability-console-plugin
VERSION: temp

jobs:
push-pr-image:
Expand All @@ -27,23 +28,18 @@ jobs:
uses: actions/checkout@v3
with:
ref: "refs/pull/${{ github.event.number }}/merge"
- name: build images
run: BASE_IMAGE="${{ env.REGISTRY }}/${{ env.REG_IMAGE }}" TAG=temp make build-ci-images
- 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.REG_IMAGE }}
tags: ${{ env.short_sha }}
registry: ${{ env.REGISTRY }}
- name: build and push images
run: IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:$(( env.short_sha )) make images
- name: build and push manifest
run: 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 @@ -36,20 +36,13 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: build images
run: IMAGE="quay.io/netobserv/${{ env.IMAGE }}:${{ env.tag }}" make image
- 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: OCI_BIN=docker IMAGE="quay.io/netobserv/${{ env.IMAGE }}:${{ env.tag }}" make images
- name: print image url
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
56 changes: 56 additions & 0 deletions .mk/shortcuts.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
##@ shortcuts helpers
.PHONY: fmt
fmt: fmt-backend fmt-frontend ## Fmt all

.PHONY: lint
lint: lint-backend lint-frontend ## Lint all

.PHONY: test
test: test-backend test-frontend ## Test all

.PHONY: i18n
i18n: ## Run frontend i18n
@echo "### generating frontend locales"
cd web && npm run i18n

.PHONY: build-frontend
build-frontend: install-frontend fmt-frontend just-build-frontend ## Run npm install, format and build frontend

.PHONY: build
build: build-backend build-frontend ## Build all

.PHONY: build-standalone
build-standalone: build-backend build-frontend-standalone ## Build all as standalone

.PHONY: frontend
frontend: build-frontend lint-frontend test-frontend ## Build lint and test frontend

.PHONY: backend
backend: build-backend lint-backend test-backend ## Build lint and test backend

.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
32 changes: 21 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
FROM registry.access.redhat.com/ubi9/nodejs-16:1 as web-builder

# 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
FROM --platform=$BUILDPLATFORM docker.io/library/node:16-alpine as web-builder
USER node

ARG TARGETPLATFORM
ARG TARGETARCH=amd64
WORKDIR /opt/app-root

COPY --chown=default Makefile Makefile
COPY --chown=default web/package.json web/package.json
COPY --chown=default web/package-lock.json web/package-lock.json
RUN NPM_INSTALL=ci make install-frontend
COPY --chown=node Makefile Makefile
COPY --chown=node web/package.json web/package.json
COPY --chown=node web/package-lock.json web/package-lock.json
RUN cd web && npm ci

COPY --chown=default web web
COPY --chown=node web web
COPY mocks mocks
RUN make fmt-frontend just-build-frontend
RUN cd web && npm run format-all
RUN cd web && npm run build

FROM docker.io/library/golang:1.19 as go-builder
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.19 as go-builder

ARG TARGETPLATFORM
ARG TARGETARCH=amd64
WORKDIR /opt/app-root

COPY .git .git
COPY go.mod go.mod
COPY go.sum go.sum
COPY vendor/ vendor/
COPY Makefile Makefile
COPY .mk/ .mk/
COPY cmd/ cmd/
COPY pkg/ pkg/

RUN make build-backend
RUN CGO_ENABLED=0 GOARCH=$TARGETARCH make build-backend

FROM registry.access.redhat.com/ubi9/ubi-minimal:9.1
FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi9/ubi-minimal:9.1

COPY --from=web-builder /opt/app-root/web/dist ./web/dist
COPY --from=go-builder /opt/app-root/plugin-backend ./
Expand Down
Loading

0 comments on commit ebc2349

Please sign in to comment.