Docker #730
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
on: | |
schedule: | |
- cron: '41 9 * * *' # Ejecuta todos los días a las 9:41 UTC | |
push: | |
branches: [ "main" ] # Rama principal | |
tags: [ 'v*.*.*' ] # Desencadena el flujo de trabajo en push de etiquetas que siguen el patrón semver | |
pull_request: | |
branches: [ "main" ] # Rama principal | |
env: | |
REGISTRY: ghcr.io # Registro de imágenes Docker | |
IMAGE_NAME: ${{ github.repository }} # Nombre de la imagen basado en el repositorio | |
jobs: | |
build: | |
runs-on: ubuntu-latest # Ejecuta una máquina virtual Ubuntu con la última versión disponible | |
permissions: # Permisos | |
contents: read # Leer el contenido del repositorio | |
packages: write # Escribir en los paquetes | |
id-token: write # Escribir en el token de identidad | |
steps: | |
- name: Checkout repository | |
uses: actions/[email protected] # Clona el repositorio | |
- name: Install cosign | |
if: github.event_name != 'pull_request' # Instala cosign solo si no es un pull request | |
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0 | |
with: | |
cosign-release: 'v2.1.1' | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0 | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' # Inicia sesión en el registro de Docker solo si no es un pull request | |
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract Docker metadata | |
id: meta # Asigna un ID al paso para su posterior referencia | |
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} # Especifica las imágenes Docker | |
- name: Build and push Docker image | |
id: build-and-push # Asigna un ID al paso para su posterior referencia | |
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0 | |
with: | |
context: . # Especifica el contexto | |
push: ${{ github.event_name != 'pull_request' }} # Indica si se debe realizar el push | |
tags: ${{ steps.meta.outputs.tags }} # Especifica las etiquetas de la imagen | |
labels: ${{ steps.meta.outputs.labels }} # Especifica las etiquetas de la imagen | |
cache-from: type=gha # Especifica el tipo de caché | |
cache-to: type=gha,mode=max # Especifica el tipo de caché en el que se guardará | |
# - name: Sign the published Docker image | |
# if: ${{ github.event_name != 'pull_request' }} | |
# env: | |
# TAGS: ${{ steps.meta.outputs.tags }} | |
# DIGEST: ${{ steps.build-and-push.outputs.digest }} | |
# run: | | |
# for tag in ${TAGS}; do | |
# cosign sign --yes "${tag}@${DIGEST}" | |
# done | |