Skip to content

update

update #26

Workflow file for this run

name: Build and Push Docker image to GHCR
on:
push:
branches: [main]
paths:
- 'Dockerfile'
- 'docker/**'
- '**/*.rs'
- '**/*.toml'
- '.github/workflows/**'
permissions:
contents: read
packages: write # パッケージへの書き込み権限を指定:contentReference[oaicite:3]{index=3}
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/synpage
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU for multi-arch
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
platforms: linux/amd64,linux/arm64
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:cache,mode=max
cleanup:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Cleanup untagged versions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
PACKAGE: synpage
ORG_PAT: ${{ secrets.ORG_PAT }}
run: |
VERSIONS=$(gh api -H "Accept: application/vnd.github+json" \
"/users/${OWNER}/packages/container/${PACKAGE}/versions" \
--paginate | jq '.[] | select(.metadata.container.tags | length == 0) | .id')
gh auth login --with-token <<< "$ORG_PAT"
# 確認 & 削除
for VERSION_ID in ${VERSIONS}; do
echo "Deleting version ID: ${VERSION_ID}"
gh api -X DELETE -H "Accept: application/vnd.github+json" \
"/users/${OWNER}/packages/container/${PACKAGE}/versions/${VERSION_ID}"
done