Skip to content

Build, Test, and Push Services #24

Build, Test, and Push Services

Build, Test, and Push Services #24

Workflow file for this run

name: Build and Deploy
on:
push:
branches:
- deploy
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# 1. Checkout репозиторий
- name: Checkout code
uses: actions/checkout@v4
# 2. Сборка Docker-образа
- name: Build Docker Images
run: |
docker compose -f docker-compose.yml build
# 3. Экспорт образа в tar-файл
- name: Save Docker Images to Tar
run: |
docker save -o images.tar $(docker-compose -f docker-compose.yml config | grep 'image:' | awk '{print $2}')
# 4. Передача образа на виртуалку
- name: Transfer Docker Image to Virtual Machine
uses: appleboy/[email protected]
with:
host: 37.139.41.110
username: ubuntu
password: ${{ secrets.VM_PASSWORD }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: ./images.tar
target: /tmp/images.tar
# Передача docker-compose.yml
- name: Transfer Docker Compose to Virtual Machine
uses: appleboy/[email protected]
with:
host: 37.139.41.110
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: ./docker-compose.yml
target: /tmp/docker-compose.yml
# 5. Развертывание на виртуалке
- name: Deploy on Virtual Machine
uses: appleboy/[email protected]
with:
host: 37.139.41.110
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker load -i /tmp/images.tar
docker-compose -f /tmp/docker-compose.yml up -d