Skip to content

About

Multi-architecture (linux/amd64 + linux/arm64) container image builds on Jenkins using native AWS Graviton agents, decoupled from any specific source-code repository platform.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

graviton-multiarch-build (Jenkins)

English | 中文

A Jenkins + AWS Graviton pipeline for multi-architecture container image builds, decoupled from the source-code repository platform.

Audience: Solutions Architects / DevOps / Platform Engineers

Goal: For customers who have already pre-built a Graviton build AMI, produce and publish multi-architecture (linux/amd64 + linux/arm64) container images to Amazon ECR through Jenkins without depending on any specific source-code repository platform (GitHub Enterprise / Bitbucket Data Center / GitLab / CodeCommit are all fine).

For the full design and decision rationale, see graviton-multiarch-build-jenkins-design.md. This README is a quick index for customer adoption.


What this is / is not

  • ✅ A multi-arch image build solution that drops directly into an existing Jenkins, with the source repository platform completely transparent to the build logic.
  • ✅ Reuses the work customers have already done: a Graviton build AMI (Docker / Buildx / Java / agent.jar baked in).
  • ✅ Native linux/arm64 builds (no QEMU emulation) — wall-clock time ≈ the slowest single architecture.
  • ❌ Not another "fully managed" service; customers still own patching of the Jenkins controller and agents.
  • ❌ Image signing (cosign) / SBOM is not built into the base pipeline — these are listed as optional add-ons.

Two core decouplings (where the value comes from)

This solution can "adapt to any Git repository" and "maintain build logic in one place" because of two independent mechanisms — understand these two and you understand the whole design:

Mechanism What it solves How it is implemented
① SCM abstraction layer Makes the pipeline agnostic to "which Git repository" — repository-platform decoupling Jenkins multibranch / Branch Source plugins (one each for Bitbucket DC / GitHub Enterprise / GitLab / CodeCommit); once checked out, the source is fully transparent to the layers above
② Shared Library Lets build logic be "maintained in one place, referenced everywhere" — logic reuse + version control vars/gravitonMultiarchBuild.groovy; a service repo only needs ~12 lines of Jenkinsfile referencing @v1, and bumping the library tag rolls out fleet-wide

⚠️ These two are often conflated, but they are separate things:

  • "Works with every Git repository platform" is the achievement of ① the SCM abstraction layer — it has nothing to do with the Shared Library.
  • "12-line Jenkinsfile + versioned upgrades" is the achievement of ② the Shared Library.

Stacked together, they deliver "the source repository platform is fully transparent to the build logic, and that logic is maintained in a single place".

💡 Portability: The Shared Library is only the top-most "Jenkins orchestration adapter." The real core — scripts/ (native fan-out builds + fan-in merge) and terraform/ (Graviton agent) — is platform-agnostic. When switching to GitHub Actions / GitLab CI / Bamboo, you only rewrite that thin orchestration adapter; scripts/ and terraform/ can be reused as-is (see "Three-layer architecture" and "Single source of truth" below).


Three-layer architecture

┌─ Orchestration layer (pluggable, one per platform)──────────┐
│  vars/gravitonMultiarchBuild.groovy    ← Jenkins entry point (Shared Library) ★ │
│  .github/workflows/multiarch-build.yml ← GitHub Actions entry point (existing) │
└────────────────────────┬───────────────────────────────────┘
                         │ both call the same
┌─ Core layer (platform-agnostic, 100% reused)───────────────┐
│  scripts/ensure-ecr.sh      ← ECR login / ensure repository exists            │
│  scripts/build-arch.sh      ← single-arch build + push-by-digest, return digest │
│  scripts/merge-manifest.sh  ← buildx imagetools merge + retry + multi-platform assert │
└────────────────────────┬───────────────────────────────────┘
                         │ runs on
┌─ Infrastructure layer (platform-agnostic, reused)──────────┐
│  terraform/graviton-agent/  ← Graviton EC2 as Jenkins agent                    │
│                                (ASG + Spot + scale-to-zero, instance role)     │
└──────────────────────────────────────────────────────────────┘

Single source of truth: the orchestration layer only schedules; all build logic lives in scripts/. GitHub Actions and this Jenkins solution share the exact same scripts, eliminating implementation drift.


Topology: fan-out → native build → fan-in merge

   Any repository (private Bitbucket / GitHub Enterprise / GitLab / CodeCommit)
            │ webhook trigger
            ▼
     Jenkins controller (inside VPC)
            │ dispatch parallel stages
   ┌────────┴──────────────────┐
   ▼ node('amd64')              ▼ node('graviton-arm64')  ← customer Graviton AMI
┌───────────────────────┐   ┌───────────────────────────┐
│ build-amd64           │   │ build-arm64               │
│  ensure-ecr.sh        │   │  ensure-ecr.sh            │
│  build-arch.sh        │   │  build-arch.sh            │
│   --platform amd64    │   │   --platform arm64        │  ← native, no QEMU
│  → return digest      │   │  → return digest          │
└──────────┬────────────┘   └──────────────┬────────────┘
           │ digest-amd64                   │ digest-arm64
           └──────────────┬─────────────────┘
                          ▼  after both digests succeed
              ┌───────────────────────────────────┐
              │ merge-manifest                    │
              │  docker buildx imagetools create  │
              │   -t repo:sha-abc123 / v1.2.3 ... │
              │   repo@digest-amd64               │
              │   repo@digest-arm64               │
              │  → OCI image index, pushed to ECR │
              │  → post-merge assert both plats   │
              └───────────────────────────────────┘

amd64 / arm64 run as two independent parallel stages — independent failure domains + native parallelism. The merge stage only runs after both digests are obtained — it will never reference a missing digest.


Three integration options

Option What the customer does Friction Upgrade path Best for
A. Shared Library ⭐ recommended Add the library's Git URL to Jenkins global config; put ~12 lines of Jenkinsfile in each service repo Lowest Bump the library tag — rolls out fleet-wide Standard Jenkins with admin access
B. Template Jenkinsfile Copy the full jenkinsfiles/Jenkinsfile.template into each repo, tweak a few variables Medium Each repo must be updated manually Cannot / does not want to touch global config
C. load script In Jenkinsfile, checkout the library then load groovy Medium Change the checkout ref Restricted environments

For detailed configuration see docs/shared-library-setup.md.


End-user usage (Option A, ~12-line Jenkinsfile)

@Library('graviton-multiarch@v1') _

gravitonMultiarchBuild(
    imageName:    'my-service',
    ecrAccountId: '111122223333',
    ecrRegion:    'ap-northeast-1',
    dockerfile:   'Dockerfile',
    buildContext: '.',
    amdAgentLabel: 'amd64',           // existing x86 agent label in your Jenkins
    armAgentLabel: 'graviton-arm64',  // label of your Graviton AMI agent
    pushLatest:   env.BRANCH_NAME == 'main'
)

The repository platform is determined by Jenkins' multibranch / SCM configuration, and is completely transparent to the Jenkinsfile above.


Repository layout

graviton-multiarch-build/
├── README.md                            # this file
├── LICENSE                              # MIT-0
├── vars/gravitonMultiarchBuild.groovy   # ⭐ Shared Library entry point (orchestration layer)
├── scripts/                             # ⭐ core layer (platform-agnostic, reused across orchestrators)
│   ├── ensure-ecr.sh                    # ECR login + ensure repository exists
│   ├── build-arch.sh                    # single-arch build + push-by-digest
│   ├── merge-manifest.sh                # buildx imagetools merge + assert
│   └── tag-strategy.sh                  # ref → tag set (sha / semver / latest)
├── jenkinsfiles/Jenkinsfile.template    # Option B: template Jenkinsfile
├── terraform/graviton-agent/            # Graviton EC2 as Jenkins agent
├── examples/
│   ├── bitbucket-dc/                    # private Bitbucket Data Center integration example
│   ├── github-enterprise/               # GitHub Enterprise integration example
│   └── languages/                       # Java/Go/Python/Node Dockerfile snippets
├── docs/
│   ├── shared-library-setup.md          # one-time global library configuration
│   ├── agent-provisioning.md            # Graviton agent provisioning
│   └── integration-guide.md             # end-to-end integration guide
└── test/manifest-assert.sh              # verify the index contains both platforms

Authentication model: EC2 instance role (no keys, no OIDC)

The Graviton agent is a Jenkins node running on an EC2 instance inside the customer's VPC, so it attaches an EC2 instance role directly for ECR access — simpler than the OIDC flow used by the GitHub Actions solution.

GitHub Actions solution This Jenkins solution
Auth mechanism GitHub OIDC EC2 instance role
IAM OIDC provider required? Yes No
AWS credentials stored anywhere? No (short-lived tokens) No (instance role)
ECR permission source AssumeRoleWithWebIdentity Instance role attached to the agent

The least-privilege policy is created by the terraform/graviton-agent module: ecr:GetAuthorizationToken + push/pull/create on ECR repositories in the account + ASG lifecycle heartbeats. What the agent reads from SSM is only the connection secret for joining the Jenkins controller — not AWS credentials.


Documentation index

Document Purpose
docs/shared-library-setup.md Configure the Global Pipeline Library in Jenkins (one-time setup for Option A)
docs/agent-provisioning.md Create a Graviton fleet with the terraform/graviton-agent module
docs/integration-guide.md End-to-end: onboard any repository into Jenkins → produce multi-arch images
examples/bitbucket-dc/ Private Bitbucket Data Center integration example
examples/github-enterprise/ GitHub Enterprise integration example
examples/languages/ Java / Go / Python / Node Dockerfile snippets
graviton-multiarch-build-jenkins-design.md Full design document (single source of truth)

License

MIT No Attribution (MIT-0)

About

Multi-architecture (linux/amd64 + linux/arm64) container image builds on Jenkins using native AWS Graviton agents, decoupled from any specific source-code repository platform.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages