Docker - NextJS GHA cache by @juttayaya from main #20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker - NextJS GHA cache | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
## GitHub Actions need '**' to match branches with '/' in their name | |
- '**' | |
paths: | |
- "nextjs-blog/**" | |
tags: | |
- '*' | |
pull_request: | |
branches: | |
- 'main' | |
permissions: | |
id-token: write | |
contents: read | |
defaults: | |
run: | |
shell: bash | |
run-name: ${{ github.workflow }} by @${{ github.actor }} from ${{ github.ref_name }} | |
jobs: | |
build: | |
name: Build and Push Image | |
runs-on: ubuntu-latest | |
env: | |
ECR_FULL_REPO: ${{ vars.ECR_REGISTRY }}/${{ vars.ECR_REPOSITORY }} | |
steps: | |
- | |
name: Check out code | |
uses: actions/checkout@v3 | |
- | |
name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- | |
name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- | |
name: Docker meta | |
id: dockermeta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.ECR_FULL_REPO }} | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- | |
name: Build Tag and Push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
file: nextjs-blog/docker/Dockerfile | |
context: nextjs-blog | |
tags: ${{ steps.dockermeta.outputs.tags }} | |
labels: ${{ steps.dockermeta.outputs.labels }} | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |