Skip to content

Commit

Permalink
chore: initial structure for building / pushing oci images for ci specs
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Riobo Lorenzo <[email protected]>
  • Loading branch information
adrianriobo committed Aug 1, 2024
1 parent f6be286 commit 005bf5b
Show file tree
Hide file tree
Showing 23 changed files with 1,220 additions and 43 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/build-oci.yaml

This file was deleted.

66 changes: 66 additions & 0 deletions .github/workflows/crc-builder-oci-builder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: crc-builder-oci-builder

on:
push:
# If release-info is not changed we may override a version
tags: [ '*' ]
paths:
- '.github\/workflows\/crc-builder\/release-info'
pull_request:
branches: [ main ]
paths:
- 'crc-builder/**'
- '.github\/workflows\/crc-builder*'

jobs:
build:
name: build
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Prepare runner
shell: bash
run: |
sudo apt-get install -y qemu-user-static
- name: Build image for PR
if: ${{ github.event_name == 'pull_request' }}
env:
CRC_BUILDER: ghcr.io/crc-org/ci-crc-builder
CRC_BUILDER_V: pr-${{ github.event.number }}
run: |
make crc-builder-oci-build
CRC_BUILDER_SAVE=crc-builder make crc-builder-oci-save
echo "CRC_BUILDER=${SNC_RUNNER}" >> "$GITHUB_ENV"
echo "CRC_BUILDER_V=${SNC_RUNNER_V}" >> "$GITHUB_ENV"
- name: Build image for Release
if: ${{ github.event_name == 'push' }}
run: |
make crc-builder-oci-build
CRC_BUILDER_SAVE=crc-builder make crc-builder-oci-save
# Get values from release-info
CRC_BUILDER ?= $(sed -n 1p crc-builder/release-info)
CRC_BUILDER_V ?= v$(sed -n 2p crc-builder/release-info)
echo "CRC_BUILDER=${CRC_BUILDER}" >> "$GITHUB_ENV"
echo "CRC_BUILDER_V=${CRC_BUILDER_V}" >> "$GITHUB_ENV"
- name: Create image metadata
run: |
echo ${{ env.CRC_BUILDER }}:${{ env.CRC_BUILDER_V }} > crc-builder-info
echo ${{ github.event_name }} > crc-builder-build-event
- name: Upload crc-builder
uses: actions/upload-artifact@v4
with:
name: crc-builder
path: crc-builder*







31 changes: 31 additions & 0 deletions .github/workflows/crc-builder-oci-pusher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: crc-builder-oci-pusher

on:
workflow_run:
workflows: crc-builder-oci-builder
types:
- completed

jobs:
push:
name: push
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Download crc-builder-oci assets
id: download-gh-context-artifact
uses: actions/download-artifact@v4
with:
name: crc-builder
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}

- name: Build image for Release
run: |
ls -al



56 changes: 56 additions & 0 deletions .github/workflows/snc-runner-oci-builder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: snc-runner-oci-builder

on:
push:
tags: [ '*' ]
paths:
- '.github\/workflows\/snc-runner\/release-info'
pull_request:
branches: [ main ]
paths:
- 'snc-runner/**'
- '.github\/workflows\/snc-runner*'
jobs:
build:
name: build
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build image for PR
if: ${{ github.event_name == 'pull_request' }}
env:
# SNC_RUNNER: ghcr.io/crc-org/ci-snc-runner
SNC_RUNNER: ghcr.io/adrianriobo/ci-snc-runner
SNC_RUNNER_V: pr-${{ github.event.number }}
run: |
make snc-runner-oci-build
SNC_RUNNER_SAVE=snc-runner make snc-runner-oci-save
echo "image=${SNC_RUNNER}" >> "$GITHUB_ENV"
echo "tag=${SNC_RUNNER_V}" >> "$GITHUB_ENV"
- name: Build image for Release
if: ${{ github.event_name == 'push' }}
run: |
make snc-runner-oci-build
SNC_RUNNER_SAVE=snc-runner make snc-runner-oci-save
# Get values from release-info
echo "image=$(sed -n 1p snc-runner/release-info)" >> "$GITHUB_ENV"
echo "tag=v$(sed -n 2p snc-runner/release-info)" >> "$GITHUB_ENV"
- name: Create image metadata
run: |
echo ${{ env.image }}:${{ env.tag }} > snc-runner-image
echo ${{ github.event_name }} > snc-runner-build-event
- name: Upload snc-runner
uses: actions/upload-artifact@v4
with:
name: snc-runner
path: snc-runner*





57 changes: 57 additions & 0 deletions .github/workflows/snc-runner-oci-pusher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: snc-runner-oci-pusher

on:
workflow_run:
workflows: snc-runner-oci-builder
types:
- completed

jobs:
push:
name: push
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Download snc-runner assets
id: download-gh-context-artifact
uses: actions/download-artifact@v4
with:
name: snc-runner
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}

- name: Get snc-runner build informaiton
run: |
echo "source_event=$(cat snc-runner-build-event)" >> "$GITHUB_ENV"
echo "image=$(cat snc-runner-image)" >> "$GITHUB_ENV"
- name: Log in to ghcr.io for PR
if: ${{ env.source_event == 'pull_request' }}
uses: redhat-actions/podman-login@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to ghcr.io
if: ${{ env.source_event == 'push' }}
uses: redhat-actions/podman-login@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Loginquay.io
if: ${{ env.source_event == 'push' }}
uses: redhat-actions/podman-login@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_IO_USERNAME }}
password: ${{ secrets.QUAY_IO_PASSWORD }}

- name: Push snc-runner
run: |
podman load -i snc-runner.tar
podman push ${{ env.image }}
81 changes: 65 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,75 @@ CONTAINER_MANAGER ?= podman
TOOLS_DIR := tools
include tools/tools.mk

# Registries and versions
## Functions
# Set image and version on the task
# 1 image
# 2 version
# 3 context
define tkn_template
sed -e 's%cimage%$(1)%g' -e 's%cversion%$(2)%g' $(3)/tkn/tpl/task.tpl.yaml > $(3)/tkn/task.yaml
endef

# Push task as bundle
# 1 image
# 2 version
# 3 context
define tkn_push
$(TOOLS_BINDIR)/tkn bundle push $(1):$(2)-tkn -f $(3)/tkn/task.yaml
endef

#### snc-runner ####

.PHONY: snc-runner-oci-build snc-runner-oci-save snc-runner-oci-push

# Variables
SNC_RUNNER ?= $(shell sed -n 1p snc-runner/release-info)
SNC_RUNNER_V ?= $(shell sed -n 2p snc-runner/release-info)
SNC_RUNNER_V ?= v$(shell sed -n 2p snc-runner/release-info)
SNC_RUNNER_SAVE ?= snc-runner

.PHONY: oci-build oci-push tkn-create tkn-push
snc-runner-oci-build: CONTEXT=snc-runner/oci
snc-runner-oci-build: MANIFEST=$(SNC_RUNNER):$(SNC_RUNNER_V)
snc-runner-oci-build:
${CONTAINER_MANAGER} build -t $(MANIFEST) -f $(CONTEXT)/Containerfile $(CONTEXT)

## Functions
oci_builder = ${CONTAINER_MANAGER} build -t $(1):$(2) -f $(3)/oci/Containerfile $(3)/oci
oci_pusher = ${CONTAINER_MANAGER} push $(1):$(2)
tkn_creator = sed -e 's%cimage%$(1)%g' -e 's%cversion%$(2)%g' $(3)/tkn/tpl/task.tpl.yaml > $(3)/tkn/task.yaml
tkn_pusher = $(TOOLS_BINDIR)/tkn bundle push $(1):$(2)-tkn -f $(3)/tkn/task.yaml
snc-runner-oci-save:
${CONTAINER_MANAGER} save -o $(SNC_RUNNER_SAVE).tar $(SNC_RUNNER):$(SNC_RUNNER_V)

snc-runner-oci-push:
${CONTAINER_MANAGER} push $(SNC_RUNNER):$(SNC_RUNNER_V)

#### crc-builder ####

.PHONY: crc-builder-oci-build crc-builder-oci-save crc-builder-oci-push

# Registries and versions
CRC_BUILDER ?= $(shell sed -n 1p crc-builder/release-info)
CRC_BUILDER_V ?= v$(shell sed -n 2p crc-builder/release-info)
CRC_BUILDER_SAVE ?= crc-builder

crc-builder-oci-build: CONTEXT=crc-builder/oci
crc-builder-oci-build: MANIFEST=$(CRC_BUILDER):$(CRC_BUILDER_V)
crc-builder-oci-build:
${CONTAINER_MANAGER} manifest create $(MANIFEST)-linux
${CONTAINER_MANAGER} build --platform linux/arm64 --build-arg=TARGETARCH=arm64 --manifest $(MANIFEST)-linux -f $(CONTEXT)/Containerfile.linux $(CONTEXT)
${CONTAINER_MANAGER} build --platform linux/amd64 --build-arg=TARGETARCH=amd64 --manifest $(MANIFEST)-linux -f $(CONTEXT)/Containerfile.linux $(CONTEXT)
${CONTAINER_MANAGER} build -t $(MANIFEST)-windows -f $(CONTEXT)/Containerfile.non-linux --build-arg=OS=windows $(CONTEXT)
${CONTAINER_MANAGER} build -t $(MANIFEST)-darwin -f $(CONTEXT)/Containerfile.non-linux --build-arg=OS=darwin $(CONTEXT)

oci-build:
$(call oci_builder,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner)
crc-builder-oci-save: MANIFEST=$(CRC_BUILDER):$(CRC_BUILDER_V)
crc-builder-oci-save:
${CONTAINER_MANAGER} save -o $(CRC_BUILDER_SAVE)-linux.tar $(MANIFEST)-linux
${CONTAINER_MANAGER} save -o $(CRC_BUILDER_SAVE)-windows.tar $(MANIFEST)-windows
${CONTAINER_MANAGER} save -o $(CRC_BUILDER_SAVE)-darwin.tar $(MANIFEST)-darwin


oci-push:
$(call oci_pusher,$(SNC_RUNNER),$(SNC_RUNNER_V))
crc-builder-oci-push:
${CONTAINER_MANAGER} manifest push $(CRC_BUILDER):$(CRC_BUILDER_V)-linux
${CONTAINER_MANAGER} push $(CRC_BUILDER):$(CRC_BUILDER_V)-windows
${CONTAINER_MANAGER} push $(CRC_BUILDER):$(CRC_BUILDER_V)-darwin

tkn-create:
$(call tkn_creator,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner)
# tkn-create:
# $(call tkn_creator,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner)

tkn-push: install-out-of-tree-tools
$(call tkn_pusher,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner)
# tkn-push: install-out-of-tree-tools
# $(call tkn_pusher,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner)
9 changes: 9 additions & 0 deletions crc-builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## 1.0.0

* Initial version for managinig 2 types of builders
* linux multi arch container based
* windows and mac build on remote target


35 changes: 35 additions & 0 deletions crc-builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# CRC Builder

## Modifications to the image

Changes to `crc-builder/os/macos/builder/build.sh` require re-building and pushing the image to internal registry (ImageStream). Make sure the changes are pushed to some `mybranch` on your fork of the QE platform repo (`github.com/<your-username>/qe-platform`). Since the `crc-builder/manifests/buildconfig.yaml` will be guiding the build of the image, it needs to specify your branch on your fork as the source.

```diff
source:
contextDir: support/images/crc-builder
git:
# dev
+ ref: 'mybranch'
+ uri: 'https://gitlab.cee.redhat.com/<your-username>/qe-platform.git'
- ref: v2.14.0
- uri: 'https://gitlab.cee.redhat.com/crc/qe-platform.git'
type: Git
```

Log in to `codeready-container` project, apply the changes in `crc-builder/manifests/buildconfig.yaml` and start the build from the corresponding `BuildConfig` (depending on the platform).

```bash
oc apply -f support/images/crc-builder/manifests/buildconfig.yaml
oc start-build image-crc-builder-<platform>
```

Lastly, make sure that `imagePullPolicy` is set to `Always` in all places that use this imageStreamTag (e.g. `crc-builder:v0.0.3-macos`). In our case, we needed to change and re-apply the following YAML.

```bash
oc apply -f orchestrator/catalog/task/crc-builder-installer/0.3/crc-builder-installer.yaml
```

Then undo changes to `crc-builder/manifests/buildconfig.yaml` so it points to the upstream repository.

_If everything works as expected, send an MR to `gitlab.cee.redhat.com/crc/qe-platform`._

Loading

0 comments on commit 005bf5b

Please sign in to comment.