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
devbranch - Pull Request to the
devbranch
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_USERNAMEandDOCKER_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
devbranch. - Execute the
start_service.shscript 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
- Stop Existing Containers: Shuts down any running Docker containers.
- Start Services: Uses
docker-composeto bring up the required containers in detached mode. - Apply Migrations: Executes
makemigrationsandmigratecommands within theks_backend_containerDocker container.
Notes
- Ensure
docker-compose.ymlis properly configured. - The script will fail and terminate if
makemigrationsormigratecommands 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.