Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Merge pull request #42 from gotwarlost/xface #27

Merge pull request #42 from gotwarlost/xface

Merge pull request #42 from gotwarlost/xface #27

name: docker build and push
on:
pull_request: {}
push:
branches:
- main
tags:
- '*'
env:
GO_VERSION: '1.21.3'
DOCKER_BUILDX_VERSION: 'v0.11.2'
XP_CHANNEL: master
XP_VERSION: current
XPKG_ACCESS_ID: ${{ secrets.XPKG_ACCESS_ID }}
XPKG: index.docker.io/gotwarlost/crossplane-function-cue
jobs:
build:
name: build multi-arch packages
runs-on: ubuntu-22.04
strategy:
fail-fast: true
matrix:
arch:
- amd64
- arm64
steps:
- name: setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: setup Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.DOCKER_BUILDX_VERSION }}
install: true
- name: checkout
uses: actions/checkout@v4
- name: setup LDFLAGS
run: |
LDFLAGS="$(make ci-print-ldflags)"
echo "LDFLAGS=${LDFLAGS}">>$GITHUB_ENV
# We ask Docker to use GitHub Action's native caching support to speed up
# the build, per https://docs.docker.com/build/cache/backends/gha/.
- name: build runtime
id: image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/${{ matrix.arch }}
cache-from: type=gha
cache-to: type=gha,mode=max
target: image
build-args: |
GO_VERSION=${{ env.GO_VERSION }}
LDFLAGS=${{ env.LDFLAGS }}
outputs: type=docker,dest=runtime-${{ matrix.arch }}.tar
- name: setup the Crossplane CLI
run: "curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"
- name: remove examples from tree
run: rm -rf examples/
- name: build Package
run: ./crossplane xpkg build --package-file=${{ matrix.arch }}.xpkg --package-root=package/ --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar
- name: upload single-platform package
uses: actions/upload-artifact@v3
with:
name: packages
path: "*.xpkg"
if-no-files-found: error
retention-days: 1
# This job downloads the single-platform packages built by the build job, and
# pushes them as a multi-platform package.
push:
runs-on: ubuntu-22.04
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Single-Platform Packages
uses: actions/download-artifact@v3
with:
name: packages
path: .
- name: Setup the Crossplane CLI
run: "curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"
- name: Set Multi-Platform Package Version
run: echo "XPKG_VERSION=$(make ci-print-version)" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.XPKG_ACCESS_ID }}
password: ${{ secrets.XPKG_TOKEN }}
if: env.XPKG_ACCESS_ID != ''
- name: Push Multi-Platform Package to docker hub
if: env.XPKG_ACCESS_ID != ''
run: "./crossplane --verbose xpkg push --package-files $(echo *.xpkg|tr ' ' ,) ${{ env.XPKG }}:${{ env.XPKG_VERSION }}"