Skip to content

Build and Push

Build and Push #15

name: Build and Push
#on:
# release:
# types:
# - published
on:
workflow_run:
workflows: ["Release"] # Nombre exacto del workflow release.yml
types:
- completed
permissions:
contents: write
packages: write
jobs:
build:
name: Build & Push
runs-on: ubuntu-latest
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Cache de dependencias de pip
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Get the latest release tag
id: get_latest_tag
run: |
TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "COMPONENT_VERSION=${TAG}" >> $GITHUB_ENV
echo "COMPONENT_NAME=liberando-productos-practica" >> $GITHUB_ENV
- name: Fetch all tags
run: git fetch --tags
- name: Check component version and name
run: |
echo "COMPONENT_NAME: ${{ env.COMPONENT_NAME }}"
echo "COMPONENT_VERSION: ${{ env.COMPONENT_VERSION }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker Login
uses: docker/login-action@v1
id: configure-login-ghcr
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PAT }}
# Login to Docker Hub
- name: Docker Login to Docker Hub
uses: docker/login-action@v1
id: configure-login-dockerhub
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository }}/${{ env.COMPONENT_NAME }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.COMPONENT_NAME }}
tags: |
type=semver,pattern={{raw}},value=${{ env.COMPONENT_VERSION }}
type=raw,value=latest
- name: Build and push to GHCR and Docker Hub
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
file: ./Dockerfile # Apunta al Dockerfile en la raíz
context: . # Usa la raíz como contexto
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args:
VERSION=${{ env.COMPONENT_VERSION }}