Sn1per/.github/workflows/build-push-ghcr.yml

56 lines
1.3 KiB
YAML

name: Build and Push Docker Image
on:
push:
branches:
- main
- gh-action
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Setting parameters
run: |-
REPO_NAME=${{ github.repository }}
echo ${REPO_NAME}
echo ${REPO_NAME,,}
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile.base
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
- name: Docker image metadata
id: image_meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
flavor: latest=true
tags: |
type=sha
- name: Login to ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push metadata to image
run: docker push ghcr.io/${{ github.repository }}
- name: Push tags to image
run: docker push ${{ steps.image_meta.outputs.tags }}