Use Cases
Common Use Cases
- Automated container builds
- Containerized testing
- Multi-stage deployments
- Image vulnerability scanning
Before You Begin
Prerequisites
- GitHub repository
- Docker Hub or container registry account
- GitHub Actions enabled
Walkthrough
Step-by-Step Guide
1
Set Up GitHub Actions Workflow
Create a workflow file that triggers on push to main.
2
Build Docker Image
Configure the workflow to build a multi-stage Docker image.
name: CI/CD Pipeline
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build -t myapp:${{ github.sha }} .3
Run Tests in Container
Execute the test suite inside the built container.
4
Push and Deploy
Push the image to the registry and trigger a deployment.
async function triggerDeploy(image, sha) {
await githubActions.triggerWorkflow({
workflow: "deploy.yml",
ref: "main",
inputs: { image, sha, environment: "production" }
});
await slack.sendMessage({ channel: "#deploys", text: `🚀 Deploying ${image} (${sha.slice(0,7)})` });
}5
Monitor Deployment
Watch the workflow run and alert on success or failure.
Examples
Code Examples
typescript
Pipeline Monitor
async function monitorPipeline(runId) {
let status = "in_progress";
while (status === "in_progress") {
const run = await githubActions.getWorkflowRun({ run_id: runId });
status = run.status;
await sleep(10000);
}
return status;
}Help
Troubleshooting
How do I cache Docker layers?+
How do I handle secrets in the build?+
Quick Info
DifficultyIntermediate
Time Estimate1.5 hours
Tools
GitHub Actions MCP ServerDocker MCP Server