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

Use buildx to build multi architecture images #104

Closed
wants to merge 5 commits into from
Closed
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
238 changes: 181 additions & 57 deletions .github/workflows/build-test-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,187 @@
name: yocto-container build and test
on:
push:
branches:
- master
pull_request:
push:
branches:
- master
pull_request:

# Allow for manually running
workflow_dispatch:
# Allow for manually running
workflow_dispatch:

# Run at 00:52 UTC every Saturday
schedule:
- cron: '52 0 * * 6'
# Run at 00:52 UTC every Saturday
schedule:
- cron: "52 0 * * 6"

jobs:
build-test-deploy:
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
fail-fast: false
matrix:
distro_to_build: [
alma-8,
alma-9,
centos-7,
debian-10,
debian-11,
debian-12,
fedora-36,
fedora-37,
fedora-38,
fedora-39,
fedora-40,
opensuse-15.4,
opensuse-15.5,
ubuntu-18.04,
ubuntu-20.04,
ubuntu-22.04
]
targetplatform: [
linux/amd64
]
env:
DISTRO_TO_BUILD: ${{ matrix.distro_to_build }}
TARGETPLATFORM: ${{ matrix.targetplatform }}
REPO: crops/yocto
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
GHCR_USERNAME: ${{ github.actor }}
GHCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

# Build and test the images
- name: Run build-and-test.sh
run: ./build_container.sh

# Deploy the images
- name: Deploy
if: ${{ env.DOCKER_PASSWORD != '' && env.GHCR_PASSWORD != '' }}
run: ./deploy.sh
build-test-deploy:
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
fail-fast: false
matrix:
distro_to_build:
[
alma-8,
alma-9,
centos-7,
debian-10,
debian-11,
debian-12,
fedora-36,
fedora-37,
fedora-38,
fedora-39,
fedora-40,
opensuse-15.4,
opensuse-15.5,
ubuntu-18.04,
ubuntu-20.04,
ubuntu-22.04,
]
env:
DISTRO_TO_BUILD: ${{ matrix.distro_to_build }}
REPO: crops/yocto
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
GHCR_USERNAME: ${{ github.actor }}
GHCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ github.env.DOCKER_USERNAME }}
password: ${{ github.env.DOCKER_PASSWORD }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.env.GHCR_USERNAME }}
password: ${{ github.env.GHCR_PASSWORD }}

- name: Generate base tag
id: base-tag
run: echo "TAG=${{ matrix.distro_to_build }}-base" >> $GITHUB_OUTPUT

- name: Get docker dir
id: dockerdir
run: echo "DOCKER_DIR='find -name ${{ steps.base-tag.outputs.TAG}}'" >> $GITHUB_OUTPUT

- name: Get working directory
id: workdir
run: echo "WORK_DIR='mktemp --tmpdir -d tmp-${{ steps.base-tag.outputs.TAG}}.XXX'" >> $GITHUB_OUTPUT

- name: Setup working directory
id: setup-workdir
run: |
cp -r ${{ steps.dockerdir.outputs.DOCKER_DIR }} ${{ steps.workdir.outputs.WORK_DIR }}
WORK_DIR=${{ steps.workdir.outputs.WORK_DIR }}/${{ steps.base-tag.outputs.TAG }}
cp build-install-dumb-init.sh $WORK_DIR
cp install-buildtools.sh $WORK_DIR
cp install-buildtools-make.sh $WORK_DIR
echo "WORK_DIR=$WORK_DIR" >> $GITHUB_OUTPUT

- name: Get baseimage
id: baseimage
working-directory: ${{ steps.setup-workdir.outputs.WORK_DIR }}
run: echo "BASE_IMAGE=`grep FROM Dockerfile | sed -e 's/FROM //'" >> $GITHUB_OUTPUT

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Pull base image
run: docker pull ${{ steps.baseimage.outputs.BASE_IMAGE }}

- name: Build base
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: false
load: true
pull: true
context: ${{ steps.setup-workdir.outputs.WORK_DIR }}
build-args: |
BASE_DISTRO=${{ matrix.base_distro }}
http_proxy=$http_proxy
HTTP_PROXY=$http_proxy
https_proxy=$https_proxy
HTTPS_PROXY=$https_proxy
no_proxy=$no_proxy
NO_PROXY=$no_proxy
tags: ${{ github.env.REPO }}/${{ steps.tag.outputs.TAG }}

- name: Clean up
run: rm ${{ steps.setup-workdir.outputs.WORK_DIR }} -rf

- name: Create builder tag
id: builder-tag
run: echo "TAG=${{ matrix.distro_to_build }}-builder" >> $GITHUB_OUTPUT

- name: Build builder
id: builder-workdir
run: echo "WORK_DIR='mktemp --tmpdir -d tmp-${{ steps.builder-tag.outputs.TAG}}.XXX'" >> $GITHUB_OUTPUT

- name: Populate distro specific dockerfile
id: distro-dockerfile
run: |
workdir=${{ steps.builder-workdir.outputs.WORK_DIR }}
cp dockerfiles/templates/Dockerfile.builder $workdir/Dockerfile
cp distro-entry.sh $workdir
sed -i "s/DISTRO_TO_BUILD/$DISTRO_TO_BUILD/g" $workdir/Dockerfile
cp helpers/runbitbake.py $workdir

- name: Replace rewitt/yocto repo
id: replace-rewitt
working-directory: ${{ steps.builder-workdir.outputs.WORK_DIR }}
run: sed -i -e "s#crops/yocto#$REPO#" Dockerfile

- name: Build image
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: false
load: true
pull: true
context: ${{ steps.builder-workdir.outputs.WORK_DIR }}
build-args: |
http_proxy=$http_proxy
HTTP_PROXY=$http_proxy
https_proxy=$https_proxy
HTTPS_PROXY=$https_proxy
no_proxy=$no_proxy
NO_PROXY=$no_proxy
tags: ${{ github.env.REPO }}/${{ steps.builder-tag.outputs.TAG }}

- name: Test base container
run: ./tests/container/vnc-test.sh ${{ github.env.REPO}}:${{ steps.base-tag.outputs.TAG}}

- name: Test builder container
run: ./tests/container/smoke.sh ${{ github.env.REPO}}:${{ steps.builder-tag.outputs.TAG}}

- name: Cleanup
run: rm ${{ steps.builder-workdir.outputs.WORK_DIR }} -rf

- name: Push base image
uses: docker/build-push-action@v5
with:
context: ${{ steps.base-workdir.outputs.WORK_DIR }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.LATEST_TAG }}

- name: Push builder image
uses: docker/build-push-action@v5
with:
context: ${{ steps.builder-workdir.outputs.WORK_DIR }}
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.env.REPO }}/${{ steps.builder-tag.outputs.TAG }}
${{ steps.builder-tag.outputs.TAG }}