This documentation outlines the architecture, setup steps, and maintenance practices for a CI/CD pipeline that automates the deployment of a Jekyll site hosted in an Amazon S3 bucket, using AWS CodePipeline and GitHub as the source repository.
The pipeline automates:
- Source Management: Fetching code from a GitHub repository.
- Build Process: Running Jekyll to generate static files.
- Deployment: Uploading the generated static files to an S3 bucket under a specified folder.
+-----------------+ +------------------+ +---------------------+
| GitHub Repo | | AWS CodeBuild | | S3 |
| (Source Code) | ---> | (Generate Site) | ---> | (Host /resume) |
+-----------------+ +------------------+ +---------------------+
Webhook Buildspec Static Site- CodePipeline: Orchestrates the pipeline workflow.
- CodeBuild: Builds the Jekyll site and organizes files.
- S3: Hosts the static website and serves it publicly.
- Log in to the AWS Management Console.
- Navigate to S3.
- Create a bucket (e.g.,
my-jekyll-site-bucket). - Enable Static Website Hosting under the bucket's Properties.
- Set the Index Document to
resume/index.html.
Configure the bucket policy to allow public read access for objects:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-jekyll-site-bucket/*"
}
]
}Create a service role for CodePipeline:
- Attach the managed policy
AWSCodePipelineFullAccess.
Create a service role for CodeBuild:
- Attach the managed policies:
AWSCodeBuildDeveloperAccessAmazonS3FullAccess
- Navigate to CodePipeline in the AWS Management Console.
- Click Create Pipeline and provide a name (e.g.,
JekyllPipeline).
- Source Provider: Select GitHub Version 2.
- Connect to GitHub: Authenticate and select the repository and branch (e.g.,
main). - Set up a webhook for automatic triggers.
- Build Provider: Select AWS CodeBuild.
- Create a CodeBuild Project:
- Environment:
- Runtime: Ubuntu with Ruby support.
- Image:
aws/codebuild/standard:5.0(or latest).
- Buildspec File: Select "Use a buildspec file."
- Environment:
- Deploy Provider: Select Amazon S3.
- Specify the target bucket (e.g.,
my-jekyll-site-bucket) and folder (resume).
Add the following buildspec.yml file to your GitHub repository root:
version: 0.2
phases:
install:
runtime-versions:
ruby: 2.7
commands:
- gem install bundler
- bundle install
build:
commands:
- bundle exec jekyll build
- mkdir -p build_output/resume
- mv _site/* build_output/resume
artifacts:
files:
- '**/*'
base-directory: 'build_output'-
Push changes to the GitHub repository.
-
Monitor the pipeline in the AWS Console.
-
Access the site:
http://your-bucket-name.s3-website-region.amazonaws.com/resume/resume.html
- Use the CodePipeline Console to monitor each stage.
- Check logs for failed builds in the CodeBuild Console.
- Source Changes:
- Modify the GitHub branch or repository in the pipeline source stage.
- Build Changes:
- Update the
buildspec.ymlfile to include new build steps.
- Update the
- Deployment Changes:
- Adjust S3 bucket or folder configurations in the deployment stage.
-
Periodically update Ruby gems in your project by running:
bundle update
- Enable CloudFront for faster content delivery.
- Add caching policies for S3 objects.
- Monitor usage costs using the AWS Cost Explorer.
- Enable S3 Object Expiration to clean up old files.
- Regularly review and limit IAM roles’ permissions.
- Enable S3 Server Access Logging for audit purposes.
| Issue | Cause | Solution |
|---|---|---|
| Build fails in CodeBuild | Missing dependencies or incorrect commands | Check the logs in CodeBuild and verify the buildspec.yml. |
| Deployment to S3 fails | Insufficient permissions for the S3 bucket | Ensure CodeBuild and CodePipeline roles have AmazonS3FullAccess. |
| Site not accessible publicly | S3 bucket permissions are misconfigured | Update the bucket policy to allow public s3:GetObject access. |
| Changes not reflecting | Old files cached by CloudFront | Invalidate the CloudFront cache or use a versioned URL for static assets. |
- Hosted Website
- Version Control System
- CI/CD Pipeline Setup
- Documentation
- Add Testing:
- Integrate testing tools (e.g., HTML validation) into the pipeline.
- CloudFront with SSL:
- Use Amazon CloudFront for HTTPS and faster delivery.
- Multi-Environment Support:
- Set up separate pipelines for staging and production.
- Automate Pipeline Updates:
- Use AWS CloudFormation to define and manage the pipeline as code.