DEV Community

abelh
abelh

Posted on

4 1

Automatización de tareas

En algunos proyectos que tengo a cargo tengo que realizar tareas repetitivas como deploy, reconstruir docker incluso backup de bases de datos.

Entonces para esto desarrolle un pequeño script que me ayuda a realizar estas tareas de forma más rápida.

Tasks spark

Automatización de tareas repetitivas. deploy, backups. etc.

Paquetes y ambiente 📋

  • Python 3.7
  • Pipenv
  • Fabric
  • Pyyaml

Creación de archivo hosts.yml y agregar configuración 🔧

hosts:
- host: XX.XX.XX.XX
  name: Landing prod
  user: app
  steps:
  - cd: landing
    steps:
    - run: git reset --hard
    - run: git checkout master
    - run: git pull
    - run: npm i
    - run: npm run build


- host: XX.XX.XX.XX
  name: App Diseño
  user: app
  steps:
  - cd: app-diseno
    folder: true
    steps:
    - run: git pull
    - run: npm i
    - run: npm run prod
  - cd: docker-app-diseno
    steps:
    - run: docker-compose up --build --force-recreate -d
  - run: 'docker exec -i docker-app-diseno_app_1 bash -c
   "cd /var/www/ && php artisan migrate --force"'

Ejecución 🔧

$ python3 main.py

alt text




Consiste en tener un archivo hosts.yml donde tenemos configuradas nuestras instrucciones a ejecutar, ejemplo:

hosts:
- host: XX.XX.XX.XX #ip
  name: Landing prod #simple name
  user: app #user
  steps:
  - cd: landing
    steps:
    - run: git reset --hard
    - run: git checkout master
    - run: git pull
    - run: npm i
    - run: npm run build
Enter fullscreen mode Exit fullscreen mode

Con estas instrucciones lo que yo hago es hacer deploy de un sitio estático.

Al ejecutar el script de la siguiente forma:

python3 main.py
Enter fullscreen mode Exit fullscreen mode

Obtendremos un listado de los hosts, al seleccionar uno nos pedira la contraseña para conectarnos e inmediatamente se ejecutaran los comandos y eso es todo.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (2)

Collapse
 
titanhero profile image
Lex

Jajajajaja genial, primer post que veo por aqui en español....genial.

Collapse
 
abelhorihuela profile image
abelh • Edited

Yo ya vi varios y quiero apoyar a compartir también

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs