This commit is contained in:
@@ -6,41 +6,45 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-save:
|
# Solo tenemos un job que lo hace todo.
|
||||||
|
build-and-deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
# ===================================================================
|
||||||
|
# PASO 1: PREPARACIÓN
|
||||||
|
# ===================================================================
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# ===================================================================
|
||||||
|
# PASO 2: CONSTRUIR IMÁGENES Y GUARDARLAS COMO FICHEROS
|
||||||
|
# ===================================================================
|
||||||
- name: Build Backend Image and Save as Tar
|
- name: Build Backend Image and Save as Tar
|
||||||
run: |
|
run: |
|
||||||
docker run --rm -v ${{ gitea.workspace }}:/workspace gcr.io/kaniko-project/executor:v1.9.0 --context=/workspace --dockerfile=/workspace/Backend/GestionIntegral.Api/Dockerfile --no-push --destination=${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:latest --tarPath=/workspace/backend.tar
|
docker run --rm -v ${{ gitea.workspace }}:/workspace gcr.io/kaniko-project/executor:v1.9.0 \
|
||||||
|
--context=/workspace \
|
||||||
|
--dockerfile=/workspace/Backend/GestionIntegral.Api/Dockerfile \
|
||||||
|
--no-push \
|
||||||
|
--destination=${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:latest \
|
||||||
|
--tarPath=/workspace/backend.tar
|
||||||
|
|
||||||
- name: Build Frontend Image and Save as Tar
|
- name: Build Frontend Image and Save as Tar
|
||||||
run: |
|
run: |
|
||||||
docker run --rm -v ${{ gitea.workspace }}:/workspace gcr.io/kaniko-project/executor:v1.9.0 --context=/workspace --dockerfile=/workspace/Frontend/Dockerfile --no-push --destination=${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:latest --tarPath=/workspace/frontend.tar
|
docker run --rm -v ${{ gitea.workspace }}:/workspace gcr.io/kaniko-project/executor:v1.9.0 \
|
||||||
|
--context=/workspace \
|
||||||
- name: Upload Image Artifacts
|
--dockerfile=/workspace/Frontend/Dockerfile \
|
||||||
uses: actions/upload-artifact@v2
|
--no-push \
|
||||||
with:
|
--destination=${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:latest \
|
||||||
name: docker-images
|
--tarPath=/workspace/frontend.tar
|
||||||
path: |
|
|
||||||
${{ gitea.workspace }}/backend.tar
|
|
||||||
${{ gitea.workspace }}/frontend.tar
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: build-and-save
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Download Image Artifacts
|
|
||||||
uses: actions/download-artifact@v2
|
|
||||||
with:
|
|
||||||
name: docker-images
|
|
||||||
|
|
||||||
|
# ===================================================================
|
||||||
|
# PASO 3: DESPLEGAR (COPIAR FICHEROS, CARGAR IMÁGENES Y LEVANTAR)
|
||||||
|
# ===================================================================
|
||||||
- name: Deploy to Production via SCP and SSH
|
- name: Deploy to Production via SCP and SSH
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e # Fallar inmediatamente si algo sale mal
|
||||||
|
|
||||||
echo "Preparing SSH client..."
|
echo "Preparing SSH client..."
|
||||||
apt-get update && apt-get install -y openssh-client
|
apt-get update && apt-get install -y openssh-client
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -49,7 +53,8 @@ jobs:
|
|||||||
ssh-keyscan -H ${{ secrets.PROD_SERVER_HOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan -H ${{ secrets.PROD_SERVER_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
echo "Copying image files to production server..."
|
echo "Copying image files to production server..."
|
||||||
scp backend.tar frontend.tar ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }}:/opt/gestion-integral/
|
# Ahora los ficheros .tar están disponibles en el workspace
|
||||||
|
scp ${{ gitea.workspace }}/backend.tar ${{ gitea.workspace }}/frontend.tar ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }}:/opt/gestion-integral/
|
||||||
|
|
||||||
echo "Connecting to host to load images and deploy..."
|
echo "Connecting to host to load images and deploy..."
|
||||||
ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << 'EOF'
|
ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << 'EOF'
|
||||||
|
|||||||
Reference in New Issue
Block a user