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

chore: fix multiarch support to be consistent with the way che-dashbord does it #99

Merged
merged 2 commits into from
Sep 18, 2023
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
98 changes: 98 additions & 0 deletions .github/workflows/next-build-multiarch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#
# Copyright (c) 2023 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

name: Che Configbump Next Build

on:
workflow_dispatch:
inputs: {}
push:
branches:
- main

env:
IMAGE: quay.io/che-incubator/configbump

jobs:

build-images:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
arch: [amd64,arm64]
outputs:
amd64: ${{ steps.result.outputs.amd64 }}
arm64: ${{ steps.result.outputs.arm64 }}
steps:
-
name: "Checkout Che Configbump source code"
uses: actions/checkout@v3
-
name: "Set up QEMU"
uses: docker/setup-qemu-action@v2
-
name: "Set up Docker Buildx ${{ matrix.arch }}"
uses: docker/setup-buildx-action@v2
-
name: "Login to quay.io"
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
-
name: "Build and push ${{ matrix.arch }}"
uses: docker/build-push-action@v3
with:
context: .
file: ./build/dockerfiles/Dockerfile
platforms: linux/${{ matrix.arch }}
push: true
provenance: false
tags: ${{ env.IMAGE }}:${{ matrix.arch }}-next
-
id: result
name: "Build result outputs version"
if: ${{ success() }}
run: echo "${{ matrix.arch }}=${{ matrix.arch }}-next" >> $GITHUB_OUTPUT

create-manifest:
if: always()
needs: build-images
runs-on: ubuntu-22.04
steps:
-
name: "Docker quay.io Login"
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
-
name: "Create and push manifest"
run: |
AMEND=""
AMD64_VERSION="${{ needs['build-images'].outputs.amd64 }}"
if [ -n "$AMD64_VERSION" ]; then
AMEND+=" --amend ${{ env.IMAGE }}:$AMD64_VERSION";
fi
ARM64_VERSION="${{ needs['build-images'].outputs.arm64 }}"
if [ -n "$ARM64_VERSION" ]; then
AMEND+=" --amend ${{ env.IMAGE }}:$ARM64_VERSION";
fi
if [ -z "$AMEND" ]; then
echo "[!] The job 'build-images' didn't provide any outputs. Can't create the manifest list."
exit 1;
fi
docker manifest create ${{ env.IMAGE }}:next $AMEND
docker manifest push ${{ env.IMAGE }}:next
48 changes: 0 additions & 48 deletions .github/workflows/next-build.yaml

This file was deleted.

119 changes: 91 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,109 @@
#

name: Release Che Configbump

on:
workflow_dispatch:
# Inputs the workflow accepts.
inputs:
version:
description: 'The version that is going to be released. Should be in format 7.y.z'
required: true
noCommit:
description: 'If true, will not commit the version bump changes'
default: ''
default: '7.y.z'
forceRecreateTags:
description: If true, tags will be recreated. Use with caution
required: false
default: 'false'

env:
IMAGE: quay.io/che-incubator/configbump

jobs:
build:
name: Create Release

build-images:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
arch: [amd64,arm64]
outputs:
amd64: ${{ steps.result.outputs.amd64 }}
arm64: ${{ steps.result.outputs.arm64 }}
steps:
- name: Checkout code
-
name: "Checkout Che Dashboard source code"
uses: actions/checkout@v3
-
name: "Set up QEMU"
uses: docker/setup-qemu-action@v2
-
name: "Set up Docker Buildx ${{ matrix.arch }}"
uses: docker/setup-buildx-action@v2
-
name: "Docker quay.io Login"
uses: docker/login-action@v2
with:
fetch-depth: 0
- name: Check existing tags
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
-
name: "Build and push ${{ matrix.arch }}"
uses: docker/build-push-action@v3
with:
context: .
file: ./build/dockerfiles/Dockerfile
platforms: linux/${{ matrix.arch }}
push: true
provenance: false
tags: ${{ env.IMAGE }}:${{ github.event.inputs.version }}-${{ matrix.arch }}
-
id: result
name: "Build result outputs version"
if: ${{ success() }}
run: echo "${{ matrix.arch }}=${{ github.event.inputs.version }}-${{ matrix.arch }}" >> $GITHUB_OUTPUT

create-manifest:
needs: build-images
runs-on: ubuntu-22.04
steps:
-
name: "Docker quay.io Login"
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
-
name: "Create and push manifest"
run: |
AMD64_VERSION="${{ needs['build-images'].outputs.amd64 }}"
ARM64_VERSION="${{ needs['build-images'].outputs.arm64 }}"

if [[ -z "$AMD64_VERSION" || \
-z "$ARM64_VERSION" ]]; then
echo "[!] The job 'build-images' fails on some of the architectures. Can't create complete manifest.";
exit 1;
fi

AMEND=""
AMEND+=" --amend ${{ env.IMAGE }}:$AMD64_VERSION";
AMEND+=" --amend ${{ env.IMAGE }}:$ARM64_VERSION";

docker manifest create ${{ env.IMAGE }}:${{ github.event.inputs.version }} $AMEND
docker manifest push ${{ env.IMAGE }}:${{ github.event.inputs.version }}
-
id: result
name: "Manifest result"
if: ${{ success() }}
run: echo "Manifest was created and pushed successfully"

tag-release:
needs: create-manifest
runs-on: ubuntu-22.04
steps:
-
name: "Checkout source code"
uses: actions/checkout@v3
-
name: Check existing tags
run: |
set +e
RECREATE_TAGS=${{ github.event.inputs.forceRecreateTags }}
Expand All @@ -52,29 +130,14 @@ jobs:
else
echo "[INFO] No existing tags detected for $VERSION"
fi
- name: Login to quay.io
uses: docker/login-action@v2
with:
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Create Release
-
name: "Tag release"
run: |
git config --global user.name "Mykhailo Kuznietsov"
git config --global user.email "[email protected]"
git config --global pull.rebase true
export GITHUB_TOKEN=${{ secrets.CHE_INCUBATOR_BOT_GITHUB_TOKEN }}
NO_COMMIT=${{ github.event.inputs.noCommit}}
if [[ $NO_COMMIT == "true" ]]; then
NO_COMMIT="--no-commit"
else
NO_COMMIT=
fi
/bin/bash make-release.sh --version ${{ github.event.inputs.version }} --trigger-release $NO_COMMIT
/bin/bash make-release.sh --version ${{ github.event.inputs.version }} --tag-release
# - name: Create failure MM message
# if: ${{ failure() }}
# run: |
Expand Down
23 changes: 5 additions & 18 deletions build/dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,12 @@
#
# Note: if we used a UBI image we could keep this current with
# https://github.com/eclipse-che/che-release/blob/main/.github/workflows/update-base-images.yml
FROM --platform=${BUILDPLATFORM:-linux/amd64} docker.io/golang:1.18-alpine as builder
FROM docker.io/golang:1.18-alpine as builder

ARG BUILD_DATE
ARG VCS_REF
ARG VERSION

ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN printf "I am running on ${BUILDPLATFORM:-linux/amd64}, building for ${TARGETPLATFORM:-linux/amd64}\n$(uname -a)\n" \
&& $(case ${TARGETPLATFORM:-linux/amd64} in \
"linux/amd64") echo "GOOS=linux GOARCH=amd64" > /tmp/.env ;; \
"linux/arm64") echo "GOOS=linux GOARCH=arm64" > /tmp/.env ;; \
"linux/ppc64le") echo "GOOS=linux GOARCH=ppc64le" > /tmp/.env ;; \
"linux/s390x") echo "GOOS=linux GOARCH=s390x" > /tmp/.env ;; \
*) echo "TARGETPLATFORM ${TARGETPLATFORM} not found..." && exit 1 ;; \
esac) \
&& cat /tmp/.env
RUN env $(cat /tmp/.env | xargs) go env

RUN apk --update --no-cache add \
build-base \
gcc \
Expand All @@ -44,13 +31,13 @@ ENV GOPROXY https://goproxy.io
ENV CGO_ENABLED=1
COPY go.mod .
COPY go.sum .
RUN env $(cat /tmp/.env | xargs) go mod download
RUN go mod download
COPY . ./

ARG VERSION=dev
RUN env $(cat /tmp/.env | xargs) go build -a -ldflags '-w -s' -a -installsuffix cgo -o configbump cmd/configbump/main.go
RUN GOOS=linux go build -a -ldflags '-w -s' -a -installsuffix cgo -o configbump cmd/configbump/main.go

FROM --platform=${TARGETPLATFORM:-linux/amd64} docker.io/alpine:3.12
FROM docker.io/alpine:3.12

ARG BUILD_DATE
ARG VCS_REF
Expand All @@ -73,7 +60,7 @@ RUN apk --update --no-cache add \
ca-certificates \
libressl \
tzdata \
&& rm -rf /tmp/* /var/cache/apk/*
&& rm -rf /tmp/* /var/cache/apk/*

USER appuser
COPY --from=builder /etc/passwd /etc/passwd
Expand Down
Loading