Skip to content

Server Deployment Documentation

This document provides an overview of the deployment process for the development server using GitHub Actions and Docker. It includes the configuration of the GitHub Actions workflow and the start_service.sh script for automating deployment steps.


GitHub Actions Workflow: server_deploy.yml

Overview

The workflow automates the process of building, testing, and deploying the application when changes are pushed to the dev branch or when pull requests target the dev branch.

Triggers

  • Push to the dev branch
  • Pull Request to the dev branch

Jobs

1. build-and-test

  • Runs on: ubuntu-latest
  • Steps:
  • Checkout the code.
  • Set up Python 3.11.
  • Install dependencies using pip.

2. deploy

  • Runs on: ubuntu-latest
  • Needs: build-and-test
  • Environment: dev-server
  • Environment Variables:
  • ENVIRONMENT: Specifies the environment (e.g., dev-server).
  • DOCKER_USERNAME and DOCKER_PASSWORD: Used for Docker authentication.
  • AZURE_SERVER_SSH_KEY, AZURE_SERVER_USER, AZURE_SERVER_IP: SSH credentials for accessing the Azure server.

  • Steps:

  • Checkout Code: Fetches the code from the repository.
  • Set up SSH Key: Configures SSH access to the Azure server using the private key stored in secrets.
  • Test Remote Server Accessibility: Verifies the ability to connect to the Azure server.
  • Deploy to Server:
    • SSH into the server.
    • Navigate to the project directory.
    • Pull the latest code from the dev branch.
    • Execute the start_service.sh script to deploy the application.

Deployment Script: start_service.sh

Overview

This script automates the deployment process on the server by managing Docker containers and running essential Django commands.

Steps

  1. Stop Existing Containers: Shuts down any running Docker containers.
  2. Start Services: Uses docker-compose to bring up the required containers in detached mode.
  3. Apply Migrations: Executes makemigrations and migrate commands within the ks_backend_container Docker container.

Notes

  • Ensure docker-compose.yml is properly configured.
  • The script will fail and terminate if makemigrations or migrate commands fail.

Conclusion

By combining the GitHub Actions workflow and the start_service.sh script, the deployment process is streamlined and automated, reducing manual intervention and ensuring consistency in deployment.