Fix Kaniko
This commit is contained in:
@@ -6,52 +6,53 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push: # Renombramos el job para que sea más claro
|
build-and-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Ya no necesitamos login ni build por separado. Kaniko lo hace todo.
|
- name: Create Kaniko config file
|
||||||
- name: Build and Push Backend with Kaniko
|
run: |
|
||||||
uses: gcr.io/kaniko-project/executor:v1.9.0
|
echo '{"auths":{"${{ secrets.REGISTRY_URL }}":{"username":"${{ secrets.REGISTRY_USER }}","password":"${{ secrets.ACTIONS_PAT }}"}}}' > /kaniko/config.json
|
||||||
with:
|
# Este comando crea el fichero de credenciales que Kaniko necesita.
|
||||||
# NOTA: Kaniko no usa "with:". Pasamos los argumentos directamente.
|
# Lo creamos en un directorio que montaremos en el siguiente paso.
|
||||||
# Esta es la sintaxis correcta para Gitea Actions.
|
|
||||||
# ¡¡IMPORTANTE!! Pasamos los secretos como variables de entorno al contenedor.
|
|
||||||
kaniko-args: >-
|
|
||||||
--context=${{ gitea.workspace }}
|
|
||||||
--dockerfile=${{ gitea.workspace }}/Backend/GestionIntegral.Api/Dockerfile
|
|
||||||
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:latest
|
|
||||||
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:${{ gitea.sha_short }}
|
|
||||||
--insecure
|
|
||||||
env:
|
|
||||||
# Kaniko necesita las credenciales como un archivo de configuración.
|
|
||||||
# Esta es la forma estándar de crearlo al vuelo.
|
|
||||||
REGISTRY_AUTH: '{"auths":{"${{ secrets.REGISTRY_URL }}":{"username":"${{ secrets.REGISTRY_USER }}","password":"${{ secrets.ACTIONS_PAT }}"}}}'
|
|
||||||
|
|
||||||
- name: Build and Push Frontend with Kaniko
|
- name: Build and Push Backend
|
||||||
uses: gcr.io/kaniko-project/executor:v1.9.0
|
run: |
|
||||||
with:
|
docker run --rm \
|
||||||
kaniko-args: >-
|
-v ${{ gitea.workspace }}:/workspace \
|
||||||
--context=${{ gitea.workspace }}
|
-v /kaniko/config.json:/kaniko/.docker/config.json \
|
||||||
--dockerfile=${{ gitea.workspace }}/Frontend/Dockerfile
|
gcr.io/kaniko-project/executor:v1.9.0 \
|
||||||
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:latest
|
--context=/workspace \
|
||||||
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:${{ gitea.sha_short }}
|
--dockerfile=/workspace/Backend/GestionIntegral.Api/Dockerfile \
|
||||||
|
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:latest \
|
||||||
|
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:${{ gitea.sha_short }} \
|
||||||
|
--insecure
|
||||||
|
|
||||||
|
- name: Build and Push Frontend
|
||||||
|
run: |
|
||||||
|
docker run --rm \
|
||||||
|
-v ${{ gitea.workspace }}:/workspace \
|
||||||
|
-v /kaniko/config.json:/kaniko/.docker/config.json \
|
||||||
|
gcr.io/kaniko-project/executor:v1.9.0 \
|
||||||
|
--context=/workspace \
|
||||||
|
--dockerfile=/workspace/Frontend/Dockerfile \
|
||||||
|
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:latest \
|
||||||
|
--destination=${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:${{ gitea.sha_short }} \
|
||||||
--insecure
|
--insecure
|
||||||
env:
|
|
||||||
REGISTRY_AUTH: '{"auths":{"${{ secrets.REGISTRY_URL }}":{"username":"${{ secrets.REGISTRY_USER }}","password":"${{ secrets.ACTIONS_PAT }}"}}}'
|
|
||||||
|
|
||||||
# Creamos un segundo job para el despliegue, que depende del primero.
|
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build-and-push # Este job no se ejecuta hasta que el anterior termine con éxito.
|
needs: build-and-push
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Deploy to Production
|
- name: Deploy to Production
|
||||||
run: |
|
run: |
|
||||||
echo "Deploying to production server..."
|
# Este paso no necesita cambios, pero para mantenerlo simple,
|
||||||
|
# lo ejecutaremos directamente sin la acción de checkout,
|
||||||
|
# ya que no necesita los ficheros del repositorio.
|
||||||
apk add --no-cache openssh-client
|
apk add --no-cache openssh-client
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.PROD_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa
|
echo "${{ secrets.PROD_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa
|
||||||
|
|||||||
Reference in New Issue
Block a user