39 lines
1.3 KiB
YAML
39 lines
1.3 KiB
YAML
name: Build and Push to GitHub Container Registry
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Build the Docker image
|
|
run: docker build . --file Dockerfile --tag ${{ github.event.repository.name }}:${{ github.sha }}
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Tag images
|
|
run: |
|
|
docker tag ${{ github.event.repository.name }}:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}
|
|
docker tag ${{ github.event.repository.name }}:${{ github.sha }} ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
|
|
|
|
- name: Push images to GitHub Container Registry
|
|
run: |
|
|
docker push ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}
|
|
docker push ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
|