Skip to content

Instantly share code, notes, and snippets.

@micahyoung
Last active January 25, 2021 19:08
Show Gist options
  • Save micahyoung/c93eeedbfc0f23670fedefcca39ac6ee to your computer and use it in GitHub Desktop.
Save micahyoung/c93eeedbfc0f23670fedefcca39ac6ee to your computer and use it in GitHub Desktop.
pack using samples on Apple Silicon M1

Pre-requisites

  • Docker Desktop preview
  • Golang, coreutils (from homebrew)
  • Git, make (from Command Line Tools (CLT) for Xcode: xcode-select --install)

Steps

  1. Clone pack, build arm binary, put on PATH

    git clone https://github.com/buildpacks/pack
    pushd pack
    
    git checkout v0.16.0
    
    make build
    
    export PATH=$PATH:$PWD/out
    
    popd
    
    file $(which pack)   # Mach-O 64-bit executable arm64 
    pack version   # 0.0.0+git-e0f6c50
    
  2. Clone lifecycle, build arm binary, create a lifecycle package tgz

    git clone https://github.com/buildpacks/lifecycle
    pushd lifecycle
    
    git checkout v0.10.1
    
    # Override amd64 default GOARCH
    GOARCH=arm64 make build-linux
    
    make package-linux
    
    # Fix inaccurate package name
    mv out/lifecycle-v0.0.0+linux.{x86-64,arm64}.tgz
    
    # Confirm correct binary
    tar xOf out/lifecycle-v0.0.0+linux.arm64.tgz lifecycle | file -   # ... ELF 64-bit LSB executable, ARM aarch64 ...
    
    popd
    
  3. Clone samples, patch sample builder with lifecycle package tgz

    git clone https://github.com/buildpacks/samples
    pushd samples
    
    git checkout bd35978
    
    # Patch builder with local lifecycle package
    cat >> builders/alpine/builder.toml <<EOF
    [lifecycle]
    uri = "../../../lifecycle/out/lifecycle-v0.0.0+linux.arm64.tgz"
    EOF
    
    # Build stacks and builder (which will all be arm64 images)
    make build-stack-alpine build-builder-alpine
    
    docker inspect cnbs/sample-builder:alpine
    
    # confirm all images are "arm64"
    docker inspect \
       cnbs/sample-builder:alpine \
       cnbs/sample-stack-run:alpine \
       cnbs/sample-stack-build:alpine \
         -f '{{.Architecture}}'
    
    popd
    
  4. Test the sample builder

    pack build hello-arm --builder cnbs/sample-builder:alpine --pull-policy=never --trust-builder --verbose --path /var/empty
    

    Output

    Builder cnbs/sample-builder:alpine is trusted
    Selected run image cnbs/sample-stack-run:alpine
    Creating builder with the following buildpacks:
    -> samples/java-maven@0.0.1
    -> samples/kotlin-gradle@0.0.1
    -> samples/hello-universe@0.0.1
    -> samples/hello-moon@0.0.1
    -> samples/hello-world@0.0.1
    Using build cache volume pack-cache-d13341c5fe82.build
    ===> DETECTING
    [detector] ======== Results ========
    [detector] fail: samples/java-maven@0.0.1
    [detector] ======== Results ========
    [detector] fail: samples/kotlin-gradle@0.0.1
    [detector] ======== Results ========
    [detector] pass: samples/hello-world@0.0.1
    [detector] pass: samples/hello-moon@0.0.1
    [detector] Resolving plan... (try #1)
    [detector] samples/hello-world 0.0.1
    [detector] samples/hello-moon  0.0.1
    ===> ANALYZING
    [analyzer] Analyzing image "1f27b4e881679a5a6f7de03bd6c1923473663834a7fbd3a9185ee132c35e465c"
    ===> RESTORING
    ===> BUILDING
    [builder] ---> Hello World buildpack
    [builder]      platform_dir files:
    [builder]        /platform:
    [builder]        total 12
    [builder]        drwxr-xr-x    1 root     root          4096 Jan  1  1980 .
    [builder]        drwxr-xr-x    1 root     root          4096 Jan 23 23:45 ..
    [builder]        drwxr-xr-x    1 root     root          4096 Jan  1  1980 env
    [builder]
    [builder]        /platform/env:
    [builder]        total 8
    [builder]        drwxr-xr-x    1 root     root          4096 Jan  1  1980 .
    [builder]        drwxr-xr-x    1 root     root          4096 Jan  1  1980 ..
    [builder]      env_dir: /platform/env
    [builder]      env vars:
    [builder]        declare -x CNB_BUILDPACK_DIR="/cnb/buildpacks/samples_hello-world/0.0.1"
    [builder]        declare -x CNB_STACK_ID="io.buildpacks.samples.stacks.alpine"
    [builder]        declare -x HOME="/home/cnb"
    [builder]        declare -x HOSTNAME="d1a8948737a0"
    [builder]        declare -x OLDPWD
    [builder]        declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    [builder]        declare -x PWD="/workspace"
    [builder]        declare -x SHLVL="1"
    [builder]      layers_dir: /layers/samples_hello-world
    [builder]      plan_path: /tmp/samples_hello-world-708964433/samples_hello-world/plan.toml
    [builder]      plan contents:
    [builder]        [[entries]]
    [builder]          name = "some-world"
    [builder]
    [builder]        [[entries]]
    [builder]          name = "some-world"
    [builder]          version = "0.1"
    [builder]          [entries.metadata]
    [builder]            version = "0.1"
    [builder]            world = "Earth-616"
    [builder]
    [builder] ---> Done
    [builder] ---> Hello Moon buildpack
    [builder]      env_dir: /platform/env
    [builder]      env vars:
    [builder]        declare -x CNB_BUILDPACK_DIR="/cnb/buildpacks/samples_hello-moon/0.0.1"
    [builder]        declare -x CNB_STACK_ID="io.buildpacks.samples.stacks.alpine"
    [builder]        declare -x HOME="/home/cnb"
    [builder]        declare -x HOSTNAME="d1a8948737a0"
    [builder]        declare -x OLDPWD
    [builder]        declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    [builder]        declare -x PWD="/workspace"
    [builder]        declare -x SHLVL="1"
    [builder]      layers_dir: /layers/samples_hello-moon
    [builder]      plan_path: /tmp/samples_hello-moon-527527292/samples_hello-moon/plan.toml
    [builder]      plan contents:
    [builder]
    [builder] ---> Done
    ===> EXPORTING
    [exporter] no project metadata found at path 'project-metadata.toml', project metadata will not be exported
    [exporter] Reusing layers from image with id '1f27b4e881679a5a6f7de03bd6c1923473663834a7fbd3a9185ee132c35e465c'
    [exporter] Layer 'slice-1' SHA: sha256:ebe5fb8f72ed7022a20cc0109ca55d336af4e4928341b066c643dbd22ce3af2f
    [exporter] Reusing 1/1 app layer(s)
    [exporter] Reusing tarball for layer "launcher" with SHA: sha256:25c360f59ad65fc067d3511c0a5017297a7fae301e76ceaffa20771b7b8b610f
    [exporter] Reusing layer 'launcher'
    [exporter] Layer 'launcher' SHA: sha256:25c360f59ad65fc067d3511c0a5017297a7fae301e76ceaffa20771b7b8b610f
    [exporter] Reusing tarball for layer "config" with SHA: sha256:86950ad9833c91e2d225b588c53113cd89e8d3a59cb6720050a8fbafea70bb16
    [exporter] Reusing layer 'config'
    [exporter] Layer 'config' SHA: sha256:86950ad9833c91e2d225b588c53113cd89e8d3a59cb6720050a8fbafea70bb16
    [exporter] Adding label 'io.buildpacks.lifecycle.metadata'
    [exporter] Adding label 'io.buildpacks.build.metadata'
    [exporter] Adding label 'io.buildpacks.project.metadata'
    [exporter] Setting CNB_LAYERS_DIR=/layers
    [exporter] Setting CNB_APP_DIR=/workspace
    [exporter] Setting CNB_PLATFORM_API=0.4
    [exporter] Setting CNB_DEPRECATION_MODE=quiet
    [exporter] Prepending /cnb/process and /cnb/lifecycle to PATH
    [exporter] Warning: default process type 'web' not present in list []
    [exporter] Setting ENTRYPOINT: '/cnb/lifecycle/launcher'
    [exporter] *** Images (1f27b4e88167):
    [exporter]       hello-arm
    [exporter]
    [exporter] *** Image ID: 1f27b4e881679a5a6f7de03bd6c1923473663834a7fbd3a9185ee132c35e465c
    Successfully built image hello-arm    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment