Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/willnewby/kshell.
Something went wrong. Try again.
YAML
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081name: Docker Build and Push
on: pull_request: branches: - main push: branches: - main
env: REGISTRY: ghcr.io IMAGE_NAME: willnewby/kshell
jobs: build: runs-on: ubuntu-latest permissions: contents: read packages: write
steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata id: meta run: | # Get commit timestamp and format as DATE COMMIT_TIMESTAMP=$(git show -s --format=%ct) DATE=$(date -u -d @${COMMIT_TIMESTAMP} +%Y%m%d%H%M)
# Get short git SHA GITSHA=$(git rev-parse --short HEAD)
echo "date=${DATE}" >> $GITHUB_OUTPUT echo "gitsha=${GITSHA}" >> $GITHUB_OUTPUT
- name: Build Docker image (PR) if: github.event_name == 'pull_request' uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 push: false tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.date }}-${{ steps.meta.outputs.gitsha }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest cache-from: type=gha cache-to: type=gha,mode=max
- name: Build and push Docker image (main) if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: docker/build-push-action@v5 with: context: . platforms: linux/amd64,linux/arm/v7,linux/arm64/v8 push: true tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.date }}-${{ steps.meta.outputs.gitsha }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest labels: | org.opencontainers.image.source=https://github.com/${{ github.repository }} org.opencontainers.image.description=Lightweight troubleshooting container for Kubernetes org.opencontainers.image.licenses=MIT cache-from: type=gha cache-to: type=gha,mode=max