🗂

GHCRにpush

2025/01/15に公開

内容

name: Push Docker Image to GitHub Container Registry

on:
  push:
    branches:
      - main

jobs:
  build-and-push:
    runs-on: ubuntu-latest

    steps:
    - name: Check out the repository
      uses: actions/checkout@v2

    - name: "Setup Docker Buildx"
      uses: docker/setup-buildx-action@v3

    - name: Log in to GitHub Container Registry
      uses: docker/login-action@v3
      with:
        registry: ghcr.io
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}

    - name: "Prepare metadata"
      id: meta
      uses: docker/metadata-action@v5
      with:
        images: ghcr.io/${{ github.repository }}
        tags: |
            type=raw,value=latest
            type=sha,prefix=,suffix=,format=short

    - name: "Build and Push"
      uses: docker/build-push-action@v5
      with:
        file: ./Dockerfile
        push: true
        tags: ${{ steps.meta.outputs.tags }}
        labels: ${{ steps.meta.outputs.labels }}

すると

docker pull ghcr.io/YOUR_ORG/YOUR_REPO:HASH
docker pull ghcr.io/YOUR_ORG/YOUR_REPO:latest

Discussion