Update docker-publish.yml
This commit is contained in:
@@ -1,124 +1,68 @@
|
|||||||
name: Docker Hub Release
|
name: Docker Hub Release
|
||||||
|
|
||||||
# Trigger the workflow when a release is published
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: 'Version to build (optional)'
|
description: 'Versión del release'
|
||||||
required: false
|
required: false
|
||||||
default: '0.1.0-rc1'
|
default: '0.1.0-rc1'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Preparar matrices de compilación
|
build-and-push:
|
||||||
prepare:
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
|
||||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
|
||||||
version: ${{ steps.get-version.outputs.version }}
|
|
||||||
steps:
|
|
||||||
- id: set-matrix
|
|
||||||
run: echo "matrix={\"arch\":[\"amd64\",\"arm64\"]}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- id: get-version
|
|
||||||
run: |
|
|
||||||
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
|
|
||||||
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
|
|
||||||
else
|
|
||||||
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Compilar por separado para cada arquitectura
|
|
||||||
build:
|
|
||||||
needs: prepare
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
|
matrix:
|
||||||
fail-fast: false
|
arch: [amd64, arm64]
|
||||||
runs-on: ${{ matrix.arch == 'arm64' && 'arm64' || 'ubuntu-latest' }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# Configurar Docker
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
# Login a DockerHub
|
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
# Cargar caché de dependencias de Rust
|
- name: Set version tag
|
||||||
- name: Cache Cargo registry
|
id: version
|
||||||
uses: actions/cache@v3
|
run: |
|
||||||
with:
|
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
|
||||||
path: |
|
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
|
||||||
~/.cargo/registry
|
else
|
||||||
~/.cargo/git
|
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||||
key: ${{ runner.os }}-cargo-${{ matrix.arch }}-${{ hashFiles('**/Cargo.lock') }}
|
fi
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-cargo-${{ matrix.arch }}-
|
|
||||||
|
|
||||||
# Extraer metadatos
|
|
||||||
- name: Extract metadata
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: ${{ secrets.DOCKERHUB_USERNAME }}/oxicloud
|
|
||||||
flavor: |
|
|
||||||
latest=false
|
|
||||||
tags: |
|
|
||||||
type=raw,value=${{ needs.prepare.outputs.version }}
|
|
||||||
type=raw,value=sha-${{ github.sha }}
|
|
||||||
|
|
||||||
# Construir y publicar imagen para esta arquitectura específica
|
- name: Build and Push Docker Image
|
||||||
- name: Build and push by digest
|
|
||||||
id: build
|
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/${{ matrix.arch }}
|
platforms: linux/${{ matrix.arch }}
|
||||||
push: true
|
push: true
|
||||||
provenance: false
|
tags: |
|
||||||
|
diocrafts/oxicloud:${{ env.VERSION }}
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
build-args: |
|
build-args: |
|
||||||
VERSION=${{ needs.prepare.outputs.version }}
|
VERSION=${{ env.VERSION }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
outputs: type=image,name=${{ secrets.DOCKERHUB_USERNAME }}/oxicloud,push-by-digest=true,name-canonical=true
|
|
||||||
|
|
||||||
# Guardar el digest para el paso de manifiesto
|
|
||||||
- name: Export digest
|
|
||||||
run: |
|
|
||||||
mkdir -p /tmp/digests
|
|
||||||
digest="${{ steps.build.outputs.digest }}"
|
|
||||||
touch "/tmp/digests/${digest#sha256:}"
|
|
||||||
echo ${{ matrix.arch }} > "/tmp/digests/${digest#sha256:}"
|
|
||||||
|
|
||||||
# Subir los digests para el siguiente trabajo
|
# Crear el manifiesto multi-arch una vez todas las imágenes estén listas
|
||||||
- name: Upload digest
|
manifest:
|
||||||
uses: actions/upload-artifact@v3
|
needs: build-and-push
|
||||||
with:
|
|
||||||
name: digests-${{ matrix.arch }}
|
|
||||||
path: /tmp/digests/*
|
|
||||||
if-no-files-found: error
|
|
||||||
retention-days: 1
|
|
||||||
|
|
||||||
# Crear manifiesto multi-arquitectura
|
|
||||||
merge:
|
|
||||||
needs: [prepare, build]
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Download digests
|
- name: Set version tag
|
||||||
uses: actions/download-artifact@v3
|
run: |
|
||||||
with:
|
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
|
||||||
path: /tmp/digests
|
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
|
||||||
pattern: digests-*
|
else
|
||||||
merge-multiple: true
|
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
@@ -129,29 +73,9 @@ jobs:
|
|||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Create and push manifest lists
|
- name: Create and Push Manifest
|
||||||
working-directory: /tmp/digests
|
|
||||||
run: |
|
run: |
|
||||||
VERSION="${{ needs.prepare.outputs.version }}"
|
docker buildx imagetools create \
|
||||||
SHA_TAG="sha-${{ github.sha }}"
|
-t diocrafts/oxicloud:${{ env.VERSION }} \
|
||||||
|
diocrafts/oxicloud:${{ env.VERSION }}@linux/amd64 \
|
||||||
# Crear la lista de digest para la manifestación
|
diocrafts/oxicloud:${{ env.VERSION }}@linux/arm64
|
||||||
DIGEST_ARGS=""
|
|
||||||
for digest_file in $(ls -1); do
|
|
||||||
ARCH=$(cat "$digest_file")
|
|
||||||
DIGEST_ARGS="$DIGEST_ARGS ${{ secrets.DOCKERHUB_USERNAME }}/oxicloud@sha256:$digest_file"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Crear los manifiestos para version específica y sha
|
|
||||||
docker buildx imagetools create -t ${{ secrets.DOCKERHUB_USERNAME }}/oxicloud:${VERSION} ${DIGEST_ARGS}
|
|
||||||
docker buildx imagetools create -t ${{ secrets.DOCKERHUB_USERNAME }}/oxicloud:${SHA_TAG} ${DIGEST_ARGS}
|
|
||||||
|
|
||||||
# Si es una versión de lanzamiento, también etiquetar como latest
|
|
||||||
if [[ "${VERSION}" != *"-"* ]]; then
|
|
||||||
docker buildx imagetools create -t ${{ secrets.DOCKERHUB_USERNAME }}/oxicloud:latest ${DIGEST_ARGS}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Post successful build notification
|
|
||||||
- name: Post Success Notification
|
|
||||||
run: |
|
|
||||||
echo "🚢 Docker multi-arch image for version ${{ needs.prepare.outputs.version }} has been successfully pushed to Docker Hub!"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user