name: Build, Push, and Deploy to GHCR
on:
push:
branches:
- "main"
workflow_dispatch:
env:
DOCKER_BUILDKIT: 1
IMAGE_NAME: ghcr.io/000volk000/v_name_generator
jobs:
build-and-push:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.repository == '000volk000/v_name_generator'
permissions:
contents: read
packages: write
outputs:
sha_short: ${{ steps.vars.outputs.sha_short }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Get short commit SHA
id: vars
run: echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
target: v_name_generator
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:main
${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.sha_short }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max