Skip to content

Build and Push

Build and Push #29

name: Build and Push
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
# Login to GitHub Container Registry (GHCR)
- name: Docker Login to GHCR
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: Build and push to GHCR
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
file: ./Dockerfile
context: .
tags: |
ghcr.io/${{ secrets.GHCR_USERNAME}}/liberando-productos-practica:${{ env.COMPONENT_VERSION }}
ghcr.io/${{ secrets.GHCR_USERNAME }}/liberando-productos-practica:latest
labels: ${{ steps.meta.outputs.labels }}
build-args:
VERSION=${{ env.COMPONENT_VERSION }}
- name: Build and push to Docker Hub
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
file: ./Dockerfile
context: .
tags: |
${{ secrets.DOCKER_USERNAME }}/liberando-productos-practica:${{ env.COMPONENT_VERSION }}
${{ secrets.DOCKER_USERNAME }}/liberando-productos-practica:latest
labels: ${{ steps.meta.outputs.labels }}
build-args:
VERSION=${{ env.COMPONENT_VERSION }}