Skip to content

feat(cd): add github job to preview deploy#409

Open
okt-limonikas wants to merge 1 commit into
ts-factory:mainfrom
okt-limonikas:preview-env
Open

feat(cd): add github job to preview deploy#409
okt-limonikas wants to merge 1 commit into
ts-factory:mainfrom
okt-limonikas:preview-env

Conversation

@okt-limonikas

@okt-limonikas okt-limonikas commented Oct 6, 2025

Copy link
Copy Markdown
Collaborator

See also ts-factory/bublik-docker#28


Problem

We need an automated way to deploy and test different branches for review purposes without manual infrastructure setup.

Solution

This PR adds Ansible-based automation for deploying ephemeral environments to a shared VM using Traefik for routing.

Requirements

OS: Ubuntu 24.04 LTS
CPU: At least 4 cores
RAM: At least 16 GB
SSH Access: Required for Ansible deployment

What are Ephemeral Environments?

Ephemeral environments are temporary, isolated deployment instances that allow developers to test changes before merging. Each environment runs independently with its own subdomain.

Deployment Types

The system supports three deployment types, automatically triggered by GitHub Actions:

  1. Production (bublik-preview-example.com) - Deployed when commits on main branch are tagged
  2. Staging (staging.bublik-preview-example.com) - Deployed on every push to main branch
  3. Ephemeral/PR environments (pr-123.bublik-preview-example.com) - Deployed for pull requests

How to Use

Specifying Branches for PR Deployments

By default, PR environments deploy the PR branch for frontend and main for other components. To customize which branches to deploy, add a comment to your PR with the following format:

backend: test-for-pr
docker: main

Available components:

  • backend - bublik repository branch
  • frontend - bublik-ui repository branch (defaults to PR branch)
  • docker - bublik-docker repository branch

Required GitHub Secrets

The following secrets must be configured in your repository settings for the automation to work:

PREVIEW_ANSIBLE_HOST          # IP or hostname of the preview VM
PREVIEW_ANSIBLE_PORT          # SSH port for the preview VM
PREVIEW_DJANGO_SUPERUSER_EMAIL    # Admin email for Django
PREVIEW_DJANGO_SUPERUSER_PASSWORD # Admin password for Django
PREVIEW_SSH_PRIVATE_KEY       # SSH private key for VM access

Required GitHub Variables

PREVIEW_ANSIBLE_USER # VM User (default bublik)
PREVIEW_BACKEND_REPO # https://github.com/ts-factory/bublik.git 
PREVIEW_DOCKER_REPO # https://github.com/ts-factory/bublik.git 
PREVIEW_FRONTEND_REPO # https://github.com/ts-factory/bublik.git 
PREVIEW_TRAEFIK_DOMAIN # bublik-preview.ru

Manual Deployment

You can also deploy manually using the provided Ansible playbooks:

1. Setup VM

ansible-playbook -i ./inventory/inventory.yml setup.yml \
  -e traefik_domain=bublik-preview-example.com \
  -e ssh_public_key_path=<path_to_public_ssh_key>

2. Deploy Environment

ansible-playbook -i ./inventory/inventory.yml deploy.yml \
  --extra-vars "environment_domain=<env_name>.bublik-preview-example.com" \
  --extra-vars "environment_name=staging" \
  --extra-vars "run_bootstrap=true" \
  --extra-vars "docker_repo=https://github.com/ts-factory/bublik-docker.git" \
  --extra-vars "docker_branch=main" \
  --extra-vars "frontend_repo=https://github.com/ts-factory/bublik-ui.git" \
  --extra-vars "frontend_branch=main" \
  --extra-vars "backend_repo=https://github.com/ts-factory/bublik.git" \
  --extra-vars "backend_branch=main" \
  --extra-vars "django_superuser_email=<admin_email>" \
  --extra-vars "django_superuser_password=<admin_password>" \
  -vv

Signed-off-by: Danil Kostromin <danil.kostromin@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants