Skip to content

Merge pull request #113 from SmartPotTech/dependabot/maven/org.spring… #46

Merge pull request #113 from SmartPotTech/dependabot/maven/org.spring…

Merge pull request #113 from SmartPotTech/dependabot/maven/org.spring… #46

Workflow file for this run

name: Publish Docker Images
on:
push:
branches: [ "main" ]
tags: [ "v*.*.*" ]
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build-and-publish:
name: Build and Push Docker Image
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Resolve registries
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_APP_NAME: ${{ secrets.DOCKER_APP_NAME }}
run: |
images="ghcr.io/${GITHUB_REPOSITORY,,}"
if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then
images="$images"$'\n'"docker.io/$DOCKER_USERNAME/${DOCKER_APP_NAME:-api-smartpot}"
echo "DOCKERHUB=true" >> "$GITHUB_ENV"
else
echo "::notice::Sin DOCKER_USERNAME y DOCKER_PASSWORD la imagen solo se publica en GHCR."
fi
{ echo "IMAGES<<EOF"; echo "$images"; echo "EOF"; } >> "$GITHUB_ENV"
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.IMAGES }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=short
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
if: env.DOCKERHUB == 'true'
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: mode=max
sbom: true