Skip to content

Build and Push Docker Image to GHCR #3

Build and Push Docker Image to GHCR

Build and Push Docker Image to GHCR #3

name: Build and Push Docker Image to GHCR
on:
push:
branches: ['main']
paths: ['.devcontainer/Dockerfile']
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: set repository to lowercase for image tag
run: |
echo "IMAGE_NAME=${REPO,,}" >>${GITHUB_ENV}
env:
REPO: '${{ github.repository }}'
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./.devcontainer
push: true
tags: |
ghcr.io/${ IMAGE_NAME }:latest
ghcr.io/${ IMAGE_NAME }:${{ github.sha }}