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

♻️ci: add no-cache option #542

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
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
27 changes: 17 additions & 10 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ on:
- "*config.*"
workflow_dispatch:
inputs:
no-cache:
description: "Build docker images with no cache"
default: false
required: false
type: boolean
push:
description: 'whether to push image'
required: true
default: false
required: false
type: boolean

permissions:
Expand All @@ -43,12 +48,13 @@ env:
REPOSITORY: marukome0743/homepage
GHCR_REGISTRY: ghcr.io
GHCR_REPOSITORY: openup-labtakizawa/homepage
SHA: ${{ github.event.pull_request.head.sha || github.event.after }}
IS_PUSH: ${{ inputs.push || github.event_name == 'push' || github.ref_type == 'tag' }}
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
IS_PUSH: ${{ github.event_name == 'push' || github.ref_type == 'tag' || inputs.push == true }}

jobs:
build:
runs-on: ubuntu-24.04
timeout-minutes: 30
if: github.repository_owner == 'openup-labtakizawa'

steps:
Expand Down Expand Up @@ -96,17 +102,18 @@ jobs:
uses: docker/build-push-action@v6
id: push
with:
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
labels: ${{ steps.meta.outputs.labels }}
load: ${{ !fromJSON(env.IS_PUSH) }}
no-cache: ${{ inputs.no-cache == true }}
platforms: ${{ fromJSON(env.IS_PUSH) && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
provenance: ${{ fromJSON(env.IS_PUSH) && 'mode=max' }}
push: ${{ fromJSON(env.IS_PUSH) }}
load: ${{ !fromJSON(env.IS_PUSH) }}
sbom: ${{ fromJSON(env.IS_PUSH) }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: ${{ fromJSON(env.IS_PUSH) && 'mode=max' || false }}
sbom: ${{ fromJSON(env.IS_PUSH) && true || false }}

- name: Attest
if: fromJSON(env.IS_PUSH)
Expand Down
22 changes: 17 additions & 5 deletions .github/workflows/lambda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ on:
- "package.json"
- "*config.*"
workflow_dispatch:
inputs:
no-cache:
description: "Build docker images with no cache"
default: false
required: false
type: boolean

permissions:
contents: read
id-token: write

env:
AWS_REGION: ap-northeast-1
Expand All @@ -24,6 +34,7 @@ env:
jobs:
lambda:
runs-on: ubuntu-24.04
timeout-minutes: 30
if: github.repository_owner == 'openup-labtakizawa'

steps:
Expand All @@ -48,21 +59,22 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2

- name: Get an old ImageTag
id: get-old-image-tag
id: old-image-tag
run: |
echo "OLD_IMAGE_TAG=$(aws ecr list-images --repository-name $ECR_REPOSITORY \
--query 'imageIds[0].imageTag' --output text)" >> $GITHUB_OUTPUT

- name: Build and Push
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
no-cache: ${{ inputs.no-cache == true }}
platforms: linux/arm64
provenance: false
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false

- name: Update Lambda Function
env:
Expand All @@ -74,7 +86,7 @@ jobs:

- name: Delete an old Image
env:
OLD_IMAGE_TAG: ${{ steps.get-old-image-tag.outputs.OLD_IMAGE_TAG }}
OLD_IMAGE_TAG: ${{ steps.old-image-tag.outputs.OLD_IMAGE_TAG }}
run: |
aws ecr batch-delete-image --repository-name $ECR_REPOSITORY \
--image-ids imageTag=$OLD_IMAGE_TAG
Binary file modified bun.lockb
Binary file not shown.
Loading