From 72f55b72d8725bf18adb706c8f1153fde3c1d24b Mon Sep 17 00:00:00 2001 From: dmolinari Date: Mon, 16 Jun 2025 20:08:53 -0300 Subject: [PATCH] Vuelta a Runners de Gitea. --- .drone.yml | 82 ------------------------------------- .gitea/workflows/deploy.yml | 61 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 82 deletions(-) delete mode 100644 .drone.yml create mode 100644 .gitea/workflows/deploy.yml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 52b97f1..0000000 --- a/.drone.yml +++ /dev/null @@ -1,82 +0,0 @@ -kind: pipeline -type: docker -name: Build y Deploy - -trigger: - branch: - - main - event: - - push - -steps: -- name: build-and-publish-backend - image: plugins/kaniko - settings: - repo: host.docker.internal:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-backend - tags: - - latest - - ${DRONE_COMMIT_SHA:0:8} - dockerfile: Backend/GestionIntegral.Api/Dockerfile - context: . - username: - from_secret: GITEA_USER - password: - from_secret: ACTIONS_PAT - insecure: true - -- name: build-and-publish-frontend - image: plugins/kaniko - settings: - repo: host.docker.internal:5000/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME,,}-frontend - tags: - - latest - - ${DRONE_COMMIT_SHA:0:8} - dockerfile: Frontend/Dockerfile - context: . - username: - from_secret: GITEA_USER - password: - from_secret: ACTIONS_PAT - insecure: true - depends_on: - - build-and-publish-backend - -- name: deploy-to-production - image: alpine:latest - environment: - SSH_KEY: - from_secret: PROD_SERVER_SSH_KEY - PROD_HOST: - from_secret: PROD_SERVER_HOST - PROD_USER: - from_secret: PROD_SERVER_USER - DB_PASSWORD: - from_secret: DB_SA_PASSWORD_SECRET - JWT_KEY: - from_secret: JWT_KEY_SECRET - REGISTRY: - from_secret: REGISTRY_URL - GITEA_USER: - from_secret: GITEA_USER - GITEA_PAT: - from_secret: ACTIONS_PAT - commands: - - apk add --no-cache openssh-client - - mkdir -p ~/.ssh - - echo "$SSH_KEY" > ~/.ssh/id_rsa - - chmod 600 ~/.ssh/id_rsa - - ssh-keyscan -H $PROD_HOST >> ~/.ssh/known_hosts - - | - ssh $PROD_USER@$PROD_HOST << 'EOF' - echo "--- CONECTADO AL SERVIDOR DE PRODUCCIÓN ---" - cd /opt/gestion-integral - export DB_SA_PASSWORD="${DB_PASSWORD}" - export JWT_KEY="${JWT_KEY}" - docker login ${REGISTRY} -u ${GITEA_USER} -p ${GITEA_PAT} - docker compose pull - docker compose up -d - docker image prune -af - echo "--- DESPLIEGUE COMPLETADO ---" - EOF - depends_on: - - build-and-publish-frontend \ No newline at end of file diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..f3cf523 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,61 @@ +name: Build and Deploy + +on: + push: + branches: + - main + +jobs: + build-and-deploy: + runs-on: ubuntu-latest # Esta etiqueta coincide con la que definimos en el runner + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Login to Gitea Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ secrets.REGISTRY_URL }} # ej: 192.168.4.128:5000 + username: ${{ secrets.GITEA_USER }} + password: ${{ secrets.ACTIONS_PAT }} + + - name: Build and Push Backend Image + uses: docker/build-push-action@v4 + with: + context: . + file: Backend/GestionIntegral.Api/Dockerfile + push: true + tags: ${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:latest,${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-backend:${{ gitea.sha_short }} + + - name: Build and Push Frontend Image + uses: docker/build-push-action@v4 + with: + context: . + file: Frontend/Dockerfile + push: true + tags: ${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:latest,${{ secrets.REGISTRY_URL }}/${{ gitea.actor }}/${{ toLower(gitea.repository_name) }}-frontend:${{ gitea.sha_short }} + + - name: Deploy to Production + run: | + echo "Deploying to production server..." + apk add --no-cache openssh-client + mkdir -p ~/.ssh + echo "${{ secrets.PROD_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan -H ${{ secrets.PROD_SERVER_HOST }} >> ~/.ssh/known_hosts + + ssh ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_HOST }} << 'EOF' + echo "--- CONECTADO AL SERVIDOR DE PRODUCCIÓN ---" + cd /opt/gestion-integral + + export DB_SA_PASSWORD="${{ secrets.DB_SA_PASSWORD_SECRET }}" + export JWT_KEY="${{ secrets.JWT_KEY_SECRET }}" + + docker login ${{ secrets.REGISTRY_URL }} -u ${{ secrets.GITEA_USER }} -p ${{ secrets.ACTIONS_PAT }} + docker compose pull + docker compose up -d + docker image prune -af + + echo "--- DESPLIEGUE COMPLETADO ---" + EOF \ No newline at end of file