Skip to content

Publish Docker Images #19

Publish Docker Images

Publish Docker Images #19

name: Publish Docker Images
on:
push:
branches: [ "main" ]
tags: [ "v*.*.*" ]
workflow_run:
workflows: ["Auto-merge Dependabot PRs"]
types:
- completed
env:
REGISTRY: docker.io
FRONTEND_IMAGE_NAME: mbakgun/dockerflex-frontend
BACKEND_IMAGE_NAME: mbakgun/dockerflex-backend
jobs:
build-and-push:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: mbakgun
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.FRONTEND_IMAGE_NAME }}
${{ env.BACKEND_IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=long
- name: Build and push Frontend image
uses: docker/build-push-action@v5
with:
context: ./frontend
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.FRONTEND_IMAGE_NAME }}:latest
cache-to: type=inline
- name: Build and push Backend image
uses: docker/build-push-action@v5
with:
context: ./backend
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.BACKEND_IMAGE_NAME }}:latest
cache-to: type=inline