adding features

This commit is contained in:
DioCrafts
2025-04-02 23:14:12 +02:00
parent a79c335b73
commit 01c81bfb1a
10 changed files with 2450 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
# Configuración para Docker Hub y GitHub Actions
Este documento explica cómo configurar los secretos necesarios para publicar imágenes de Docker en Docker Hub usando GitHub Actions.
## Requisitos previos
1. Una cuenta en [Docker Hub](https://hub.docker.com/)
2. Un repositorio en Docker Hub donde subir la imagen
3. Un token de acceso personal (PAT) de Docker Hub
## Pasos para configurar los secretos en GitHub
1. Genera un token de acceso en Docker Hub
- Inicia sesión en [Docker Hub](https://hub.docker.com/)
- Ve a tu perfil (esquina superior derecha) → Account Settings → Security
- Haz clic en "New Access Token"
- Proporciona una descripción como "GitHub Actions"
- Selecciona los permisos apropiados (normalmente "Read, Write, Delete")
- Haz clic en "Generate"
- **IMPORTANTE**: Copia el token generado, ya que no podrás verlo de nuevo
2. Configura los secretos en tu repositorio de GitHub
- Ve a tu repositorio en GitHub
- Haz clic en "Settings" → "Secrets and variables" → "Actions"
- Haz clic en "New repository secret"
- Añade los siguientes secretos:
- Nombre: `DOCKERHUB_USERNAME`
Valor: Tu nombre de usuario de Docker Hub
- Nombre: `DOCKERHUB_TOKEN`
Valor: El token de acceso que generaste en el paso anterior
## Uso
Una vez configurados los secretos, los flujos de trabajo de GitHub Actions podrán autenticarse con Docker Hub y publicar imágenes.
Cuando crees una nueva [release en GitHub](https://docs.github.com/es/repositories/releasing-projects-on-github/managing-releases-in-a-repository#creating-a-release), el flujo de trabajo `docker-publish.yml` se activará automáticamente y:
1. Construirá la imagen de Docker
2. La etiquetará con el número de versión de la release
3. La subirá a Docker Hub
## Verificación
Para verificar que la configuración está correcta:
1. Crea una nueva release en GitHub
2. Ve a la pestaña "Actions" y observa el progreso del flujo de trabajo
3. Una vez completado, verifica que la imagen aparezca en tu repositorio de Docker Hub
## Notas adicionales
- Para entornos de producción, considera usar un usuario de servicio en Docker Hub en lugar de tu cuenta personal
- Rota regularmente los tokens de acceso para mayor seguridad
- Considera agregar escaneo de vulnerabilidades en las imágenes como parte del flujo de trabajo
+56
View File
@@ -0,0 +1,56 @@
name: Docker Build and Test
# Trigger on push to main branch or on pull requests
on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]
jobs:
# Build and test Docker image but don't push
build-and-test:
name: Build and Test Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Extract metadata (tags, labels) for Docker
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: test/oxicloud
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
# Build Docker image but don't push
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
load: true
tags: test/oxicloud:test
cache-from: type=gha
cache-to: type=gha,mode=max
# Run some basic tests against the built image
- name: Test Docker image
run: |
docker run --rm test/oxicloud:test --version || true
docker run --rm test/oxicloud:test --help || true
# Verify the image structure
echo "✅ Checking Docker image layers and size"
docker image inspect test/oxicloud:test
echo "✅ Docker build and test completed successfully"
+63
View File
@@ -0,0 +1,63 @@
name: Docker Hub Release
# Trigger the workflow when a release is published
on:
release:
types: [published]
jobs:
# Build and publish Docker image
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# Set up Docker Buildx for efficient builds
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Login to Docker Hub
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/oxicloud
# Generate Docker tags based on release tag, commit SHA, and latest
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=sha
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
# Build and push Docker image
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
# Build args if needed
build-args: |
VERSION=${{ github.ref_name }}
# Post successful build notification
- name: Post Success Notification
if: success()
run: |
echo "🚢 Docker image for version ${{ github.ref_name }} has been successfully pushed to Docker Hub!"