feat: add support for image caching

Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>
This commit is contained in:
K.B.Dharun Krishna 2024-05-11 14:53:11 +05:30
parent d532ae9449
commit 5d0b25c97f
No known key found for this signature in database
GPG key ID: 0CFDE7E6FAC14AF8
5 changed files with 54 additions and 45 deletions

View file

@ -3,8 +3,11 @@ name: Vib Build
on:
push:
branches: [ "main" ]
tags:
- '*'
schedule:
- cron: '21 3 * * *'
pull_request:
workflow_dispatch:
env:
@ -13,11 +16,14 @@ env:
jobs:
check_update:
runs-on: ubuntu-latest
outputs:
has_updates: ${{ steps.set_output.outputs.has_updates }}
base_image: ${{ steps.read_base_recipe.outputs.base_image }}
permissions:
contents: write
contents: write # Allow actions to create digest, etc.
steps:
- name: Checkout code
uses: actions/checkout@v4
@ -34,7 +40,7 @@ jobs:
echo "base_image=$BASE_IMAGE" >> "$GITHUB_OUTPUT"
echo "BASE_IMAGE=$BASE_IMAGE" >> "$GITHUB_ENV"
- name: get last successful run
- name: Get last successful run
if: ${{ github.ref_type == 'branch' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@ -86,8 +92,10 @@ jobs:
runs-on: ubuntu-latest
needs: check_update
if: ${{ needs.check_update.outputs.has_updates == 'true' }}
permissions:
packages: write
packages: write # Allow pushing images to GHCR.
steps:
- uses: actions/checkout@v4
@ -100,17 +108,45 @@ jobs:
run: |
REPO_OWNER_LOWERCASE="$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')"
echo "REPO_OWNER_LOWERCASE=$REPO_OWNER_LOWERCASE">> "$GITHUB_ENV"
echo "IMAGE_TAG=ghcr.io/$REPO_OWNER_LOWERCASE/${{ env.CUSTOM_IMAGE_NAME }}:main">> "$GITHUB_ENV"
echo "IMAGE_URL=ghcr.io/$REPO_OWNER_LOWERCASE/${{ env.CUSTOM_IMAGE_NAME }}">> "$GITHUB_ENV"
- name: Set image info
run: |
echo -n "${{ needs.check_update.outputs.base_image }}" > ./includes.container/image-info/base-image-name
echo -n "${{ env.REPO_OWNER_LOWERCASE }}/${{ env.CUSTOM_IMAGE_NAME }}" > ./includes.container/image-info/image-name
- name: Build the Docker image
run: docker image build -f Containerfile --tag "${{ env.IMAGE_TAG }}" .
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
${{ env. IMAGE_URL }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{raw}}
type=semver,pattern=v{{major}}
type=ref,event=branch
- name: Push To GHCR
run: |
docker login ghcr.io -u ${{ github.repository_owner }} -p ${{ secrets.GITHUB_TOKEN }}
docker image push "${{ env.IMAGE_TAG }}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Package Registry
uses: docker/login-action@v3
if: ${{ github.event_name == 'push' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push the Docker image
id: push
uses: docker/build-push-action@v5
with:
context: .
file: Containerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

View file

@ -1,27 +0,0 @@
name: Vib PR
on:
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: vanilla-os/vib-gh-action@v0.7.0
with:
recipe: 'recipe.yml'
plugins: 'Vanilla-OS/vib-fsguard:v1.4'
- name: Build the Docker image
run: docker image build -f Containerfile --tag testing .
- uses: actions/upload-artifact@v4
with:
name: Containerfile
path: Containerfile

View file

@ -6,18 +6,18 @@ It is suggested to check the [Vib repository's README](https://github.com/Vanill
## Getting Started
- First, click on the "Use this template" button in the top right corner, then from the drop-down menu select "Create a new repository". This would create a new repository with the same files and directories as this repository.
- Go to Settings → Actions → General and ensure "Allow all actions and reusable workflows" are enabled.
- First, click on the <kbd>Use this template</kbd> button in the top right corner, then from the drop-down menu select <kbd>Create a new repository</kbd>. This would create a new repository with the same files and directories as this repository.
- Go to **Settings → Actions → General** and ensure "_Allow all actions and reusable workflows_" are enabled.
- Now, clone the repository to your local machine and let's start customizing your image. You can also use the GitHub online editor if you prefer.
- Open the `vib-build.yml` workflow file and replace the custom image name with an image name of your choosing in line 11.
- Open the `recipe.yml` file and replace the image name and ID with your image name and ID in lines 2 and 3.
- Open the `vib-build.yml` workflow file and replace the custom image name with an image name of your choosing in line 14.
- Open the `recipe.yml` file and replace the image name and ID with your image name and ID in lines 1 and 2.
- Now, perform your additions and modifications to the recipe as per your requirements.
- If you just want to install .deb files, you can just put them in `includes.container/deb-pkgs`
- If you just want to install `.deb` files, you can just put them in `includes.container/deb-pkgs`
- Optionally, add your modules to the `modules` directory and add them to the package-modules `includes` in `recipe.yml`.
- You can check the Actions tab in GitHub to see the build progress of your image.
> [!NOTE]
> It is suggested to add a `vib-image` tag to your repository for your image to be easily discoverable.
> It is suggested to add `vib-image` and `vib` tags to your repository for your image to be easily discoverable to others.
## Use your custom image

View file

@ -1 +1 @@
This will be replaced by the github workflow to what is set in the recipe. For example: vanilla-os/desktop
This will be replaced by the github workflow to what is set in the recipe. For example: vanilla-os/desktop.

View file

@ -1 +1 @@
This will be replaced by the github workflow to what is set in the workflow. For example: taukakao/custom
This will be replaced by the github workflow to what is set in the workflow. For example: taukakao/custom.