In this blog post, I will walk you through my project to automate Akamai property deployment using GitHub Actions with an external runner hosted on Linode. This project automates the process of creating property versions, updating the rule tree, and deploying to staging and production environments.
This guide will show you how to set up a similar workflow for Akamai deployments, where each step is managed automatically, from development to production.
Project Structure
The project is designed to automate the entire deployment lifecycle. Here's an overview of the directory structure and files used in this project:
.github/workflows/: Contains the GitHub Actions workflow configuration.
src/: Python scripts for managing Akamai property versions, activating changes, and updating rules.
tests/: Unit tests for verifying deployments on staging and production environments.
requirements.txt: Specifies Python dependencies.
├── .github
│ └── workflows
│ └── update_akamai_config.yml # GitHub Actions workflow file
├── .venv # Virtual environment for Python dependencies
├── src # Contains the Python deployment scripts
│ ├── activate_on_prod.py
│ ├── activate_on_stage.py
│ ├── create_a_new_property_version.py
│ ├── update_property_rule_tree.py
│ └── credentials.py
├── tests # Contains pytest scripts for staging and prod
│ ├── test_stage.py
│ └── test_prod.py
├── README.md
└── requirements.txt
The automation is split into multiple jobs that build on each other in a pipeline. Each step is important for ensuring seamless and automated deployments. Below, I break down the workflow configuration and provide explanations for each job.
Step 1: GitHub Actions Workflow Configuration
I’ve set up a GitHub Actions workflow (update_akamai_config.yml) to automate the deployment process. The workflow has jobs to handle property version creation, rule tree updates, deployments to Akamai staging and production environments, and testing.
Here’s the complete workflow:
name: Deploy Akamai Config
on:
push:
branches:
- main # Trigger when code is pushed to the main branch
jobs:
update-rule-tree:
runs-on: [self-hosted, demo_workflow] # Use self-hosted runner
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create .edgerc file
run: |
echo "${{ secrets.AKAMAI_EDGERC }}" > ~/.edgerc
- name: Install dependencies
run: |
pip3 install -r requirements.txt
- name: Create a new Property Version
run: |
python3 src/create_a_new_property_version.py
- name: Update Property Rule Tree
run: |
python3 src/update_property_rule_tree.py
deploy-to-stage:
needs: update-rule-tree
runs-on: [self-hosted, demo_workflow]
steps:
- name: Install dependencies
run: |
pip3 install -r requirements.txt
- name: Checkout code
uses: actions/checkout@v3
- name: Deploy to Akamai Staging
run: |
python3 src/activate_on_stage.py
test-on-stage:
needs: deploy-to-stage
runs-on: [self-hosted, demo_workflow]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
run: |
pip3 install -r requirements.txt
- name: Run pytest on staging environment
run: |
pytest tests/test_stage.py
deploy-to-prod:
needs: deploy-to-stage
runs-on: [self-hosted, demo_workflow]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
run: |
pip3 install -r requirements.txt
- name: Deploy to Akamai Production
run: |
python3 src/activate_on_prod.py
test-on-prod:
needs: deploy-to-prod
runs-on: [self-hosted, demo_workflow]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
run: |
pip3 install -r requirements.txt
- name: Run pytest on production environment
run: |
pytest tests/test_prod.py
To run the pipeline, I’m using a self-hosted runner on Linode. This offers more control over the runtime environment, and can handle long-running processes better than GitHub's default runners.
Create a Linode instance and configure it with basic dependencies:
Install Python, Git, and Docker (optional, but useful for managing isolated environments).
Install the GitHub Actions runner as detailed earlier.
Register the runner with your GitHub repository by following GitHub’s instructions.
Job 1: Update Rule Tree
This job is responsible for creating a new property version and updating the Akamai property rule tree. This is an important part of any Akamai deployment, as changes need to be managed in a controlled versioning system.
Checkout Code: Fetches the latest code from the GitHub repository.
Create .edgerc: Writes the Akamai EdgeRC configuration file from a GitHub secret.
Install Dependencies: Installs the necessary Python packages (defined in requirements.txt).
Create New Property Version: Executes the Python script to create a new property version in Akamai.
Update Rule Tree: Runs the script to update the property’s rule tree with the latest configurations.
Job 2: Deploy to Akamai Staging
This job activates the updated property on Akamai’s staging environment, allowing you to test it before deploying to production.
Install Dependencies: Ensures all required Python packages are installed.
Deploy to Staging: Activates the new Akamai configuration on the staging environment using the activate_on_stage.py script.
Job 3: Test on Staging
This job ensures that the newly activated configuration on staging is tested using pytest.
Run Pytest: Executes the staging tests (test_stage.py) to verify that the new configuration behaves as expected.
Job 4: Deploy to Akamai Production
If the tests on staging pass successfully, the deployment proceeds to the production environment.
Install Dependencies: Same as before, to ensure the correct environment is prepared.
Deploy to Production: Activates the configuration on the production environment using the activate_on_prod.py script.
Job 5: Test on Production
The final job ensures that the new configuration is working as expected in production.
Run Pytest: Executes the production tests (test_prod.py) to validate the deployment.
You’ll need to store Akamai credentials in GitHub Secrets to enable the pipeline to authenticate and deploy to Akamai. Make sure you set the following secrets in your repository:
AKAMAI_EDGERC: Stores your EdgeRC configuration for Akamai.
This setup ensures that every change to the main branch triggers an automated pipeline that manages Akamai configurations, deploys them to staging and production, and runs tests to verify the deployment. By leveraging GitHub Actions and a self-hosted runner on Linode, I’ve been able to automate and scale this process effectively.