From d86ddfcc6f77e095cd1599178c9da46396722b0a Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Thu, 9 May 2024 19:50:18 +0530 Subject: [PATCH] feat: add support for image caching Signed-off-by: K.B.Dharun Krishna --- .github/workflows/differ.yml | 1 + .github/workflows/vib-build.yml | 65 ++++++++++++++++++++++++++------- .github/workflows/vib-pr.yml | 27 -------------- 3 files changed, 53 insertions(+), 40 deletions(-) delete mode 100644 .github/workflows/vib-pr.yml diff --git a/.github/workflows/differ.yml b/.github/workflows/differ.yml index 868caab..ad76e92 100644 --- a/.github/workflows/differ.yml +++ b/.github/workflows/differ.yml @@ -11,6 +11,7 @@ jobs: runs-on: ubuntu-latest container: image: ghcr.io/vanilla-os/core:main + if: github.repository == 'vanilla-os/core-image' steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/vib-build.yml b/.github/workflows/vib-build.yml index 711d367..432f660 100644 --- a/.github/workflows/vib-build.yml +++ b/.github/workflows/vib-build.yml @@ -2,17 +2,19 @@ name: Vib Build on: push: - branches: [ "main" ] + branches: + - 'main' + tags: + - '*' workflow_dispatch: + pull_request: -env: - REGISTRY_USER: ${{ github.actor }} - REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} +permissions: + contents: write # Allow actions to create release + packages: write # Allow pushing images to GHCR jobs: - build: - runs-on: ubuntu-latest steps: @@ -23,12 +25,49 @@ jobs: recipe: 'recipe.yml' plugins: 'Vanilla-OS/vib-fsguard:v1.4' - - name: Build the Docker image - run: docker image build -f Containerfile --tag ghcr.io/vanilla-os/core:main . + - uses: actions/upload-artifact@v4 + with: + name: Containerfile + path: Containerfile - # Push the image to GHCR (Image Registry) - - name: Push To GHCR - if: github.repository == 'vanilla-os/core-image' + - name: Generate image name run: | - docker login ghcr.io -u ${{ env.REGISTRY_USER }} -p ${{ env.REGISTRY_PASSWORD }} - docker image push "ghcr.io/vanilla-os/core:main" + REPO_OWNER_LOWERCASE="$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" + echo "REPO_OWNER_LOWERCASE=$REPO_OWNER_LOWERCASE" >> "$GITHUB_ENV" + echo "IMAGE_NAME=ghcr.io/$REPO_OWNER_LOWERCASE/core" >> "$GITHUB_ENV" + + - name: Docker meta + id: docker_meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env. IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{raw}} + type=semver,pattern=v{{major}} + type=ref,event=branch + + - 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 diff --git a/.github/workflows/vib-pr.yml b/.github/workflows/vib-pr.yml deleted file mode 100644 index 893069e..0000000 --- a/.github/workflows/vib-pr.yml +++ /dev/null @@ -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 vanillaos/core:validation . - - - uses: actions/upload-artifact@v4 - with: - name: Containerfile - path: Containerfile