Skip to content

Commit

Permalink
Add caching to build system (#577)
Browse files Browse the repository at this point in the history
* use cache and run on PR

* fix package overrides

* run release only on refs/heads/master

* Fix github ref
  • Loading branch information
BoukeHaarsma23 committed Apr 12, 2023
1 parent b2c64a9 commit 09119e6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 11 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/builder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build base environment
on:
schedule:
- cron: "0 2 * * *"
workflow_dispatch:
jobs:
build-environment:
name: Build environment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- name: build builder image
uses: docker/build-push-action@v3
with:
context: .
tags: image-builder:latest
outputs: type=docker,dest=/tmp/builder.tar
- name: Cache builder image
id: builder-cache
uses: actions/cache@v3
with:
key: ${{ hashFiles('pkgs/**/PKGBUILD')}}
path: /tmp/builder.tar
- uses: actions/upload-artifact@v3
with:
name: image-builder
path: /tmp/builder.tar
45 changes: 36 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
push:
branches:
- 'master'
pull_request:
branches:
- 'master'
jobs:
list-pkgbuilds:
runs-on: ubuntu-latest
Expand All @@ -19,14 +22,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- name: build builder image
- name: Cache builder image
id: builder-cache
uses: actions/cache@v3
with:
key: ${{ hashFiles('pkgs/**/PKGBUILD')}}
path: /tmp/builder.tar
- if: ${{ steps.builder-cache.outputs.cache-hit != 'true' }}
uses: docker/setup-buildx-action@v2
- if: ${{ steps.builder-cache.outputs.cache-hit != 'true' }}
name: build builder image
uses: docker/build-push-action@v3
with:
context: .
tags: image-builder:${{ github.sha }}
tags: image-builder:latest
outputs: type=docker,dest=/tmp/builder.tar
- uses: actions/upload-artifact@v3
- if: ${{ steps.builder-cache.outputs.cache-hit != 'true' }}
uses: actions/upload-artifact@v3
with:
name: image-builder
path: /tmp/builder.tar
Expand All @@ -43,15 +55,22 @@ jobs:
package: ${{ fromJson(needs.list-pkgbuilds.outputs.aur-pkgs) }}
steps:
- uses: actions/checkout@v3
- name: Download builder
- name: Use cached builder image
id: builder-cache
uses: actions/cache@v3
with:
key: ${{ hashFiles('pkgs/**/PKGBUILD')}}
path: /tmp/builder.tar
- if: ${{ steps.builder-cache.outputs.cache-hit != 'true' }}
name: Download builder
uses: actions/download-artifact@v3
with:
name: image-builder
path: /tmp
- name: Build package
run: |
docker load --input /tmp/builder.tar
docker run --rm -v $(pwd):/workdir -v $(pwd)/output:/output --entrypoint=/workdir/build-package.sh --privileged=true image-builder:${{ github.sha }} ${{ matrix.package }}
docker run --rm -v $(pwd):/workdir -v $(pwd)/output:/output --entrypoint=/workdir/build-package.sh --privileged=true image-builder:latest ${{ matrix.package }}
- run: ls -ahl output/*
- name: Upload Package Archives
uses: actions/upload-artifact@v3
Expand All @@ -74,7 +93,14 @@ jobs:
image_filename: ${{ steps.build_image.outputs.image_filename }}
steps:
- uses: actions/checkout@v3
- name: Download builder
- name: Use cached builder image
id: builder-cache
uses: actions/cache@v3
with:
key: ${{ hashFiles('pkgs/**/PKGBUILD')}}
path: /tmp/builder.tar
- if: ${{ steps.builder-cache.outputs.cache-hit != 'true' }}
name: Download builder
uses: actions/download-artifact@v3
with:
name: image-builder
Expand All @@ -86,9 +112,10 @@ jobs:
- run: docker load --input /tmp/builder.tar
- name: Build system image
id: build_image
run: docker run --rm -v $(pwd):/workdir -v $(pwd)/output:/output -v $GITHUB_OUTPUT:$GITHUB_OUTPUT -e "GITHUB_OUTPUT=$GITHUB_OUTPUT" --privileged=true image-builder:${{ github.sha }} $(echo ${GITHUB_SHA} | cut -c1-7)
run: docker run --rm -v $(pwd):/workdir -v $(pwd)/output:/output -v $GITHUB_OUTPUT:$GITHUB_OUTPUT -e "GITHUB_OUTPUT=$GITHUB_OUTPUT" --privileged=true image-builder:latest $(echo ${GITHUB_SHA} | cut -c1-7)

- name: Create release
- if: github.ref == 'refs/heads/master'
name: Create release
id: create_release
uses: softprops/action-gh-release@v1
with:
Expand Down
5 changes: 3 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ cp -rv aur-pkgs/*.pkg.tar* ${BUILD_PATH}/extra_pkgs
# Own packages already exist in docker container
cp -rv /pkgs/**/*.pkg.tar* ${BUILD_PATH}/own_pkgs

# TODO(bouhaa): fix package overrides
# cp -rv /tmp/extra_pkgs/*.pkg.tar* ${BUILD_PATH}/extra_pkgs
if [ -n "${PACKAGE_OVERRIDES}" ]; then
cp -rv /tmp/extra_pkgs/*.pkg.tar* ${BUILD_PATH}/extra_pkgs
fi


# chroot into target
Expand Down

0 comments on commit 09119e6

Please sign in to comment.