Skip to content

KaaS Image creation

KaaS Image creation #2

name: Build and publish a Docker image
on:
push:
branches:
- '*'
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches:
- '*'
jobs:
build:
name: Build & push docker image
runs-on: ubuntu-latest
env:
IMG_NAME: ${{ github.repository }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Debug
run: |
echo "github.ref -> {{ github.ref }}"
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v3
with:
images: ${{ env.IMG_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value={{sha}},enable=${{ github.ref_type != 'tag' }}
- name: Log in to Docker Hub
uses: docker/login-action@v1
if: ${{ github.ref_type == 'tag' }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: ${{ github.event.base_ref =='refs/heads/main' && github.ref_type == 'tag' && !startsWith(github.ref, 'refs/tags/v0.')}}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}