Skip to content

Commit

Permalink
Merge branch 'main' into build-config-env
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Bustamante <[email protected]>
  • Loading branch information
jjbustamante authored Oct 31, 2023
2 parents 064f25e + 25deaf6 commit 1ffbc10
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 70 deletions.
12 changes: 8 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
interval: "weekly"
groups:
# Group all minor/patch go dependencies into a single PR.
go-dependencies:
update-types:
- "minor"
- "patch"
labels:
- "dependencies"
- "go"
Expand All @@ -15,8 +20,7 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
interval: "weekly"
labels:
- "dependencies"
- "github_actions"
Expand Down
30 changes: 17 additions & 13 deletions .github/workflows/delivery-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ on:
default: false

env:
BUILDER: "paketobuildpacks/builder-jammy-tiny"
IMG_NAME: 'pack'
USERNAME: 'buildpacksio'

jobs:
deliver-docker:
strategy:
matrix:
config: [tiny, base]
include:
- config: tiny
base_image: gcr.io/distroless/static
suffix:
- config: base
base_image: ubuntu:jammy
suffix: -base
runs-on: ubuntu-latest
steps:
- name: Determine version
Expand All @@ -42,16 +51,6 @@ jobs:
uses: actions/checkout@v4
with:
ref: v${{ steps.version.outputs.result }}
# This has to come after the first checkout, so it isn't clobbered
- name: Checkout delivery configuration
uses: actions/checkout@v4
with:
path: ./head
- name: Setup Working Dir
shell: bash
run: |
rm project.toml || true
cp head/.github/workflows/delivery/docker/project.toml project.toml
- name: Determine App Name
run: 'echo "IMG_NAME=${{ env.USERNAME }}/${{ env.IMG_NAME }}" >> $GITHUB_ENV'
- name: Login to Dockerhub
Expand All @@ -65,12 +64,17 @@ jobs:
- name: Buildx Build/Publish
run: |
docker buildx build . \
--tag ${{ env.IMG_NAME }}:${{ steps.version.outputs.result }} \
--tag ${{ env.IMG_NAME }}:${{ steps.version.outputs.result }}${{ matrix.suffix }} \
--platform linux/amd64,linux/arm64 \
--build-arg pack_version=${{ steps.version.outputs.result }} \
--build-arg base_image=${{ matrix.base_image }} \
--provenance=false \
--push
- name: Tag Image as Base
if: ${{ (github.event.release != '' || github.event.inputs.tag_latest) && matrix.config == 'base' }}
run: |
crane copy ${{ env.IMG_NAME }}:${{ steps.version.outputs.result }} ${{ env.IMG_NAME }}:base
- name: Tag Image as Latest
if: ${{ github.event.release != '' || github.event.inputs.tag_latest }}
if: ${{ (github.event.release != '' || github.event.inputs.tag_latest) && matrix.config != 'base' }}
run: |
crane copy ${{ env.IMG_NAME }}:${{ steps.version.outputs.result }} ${{ env.IMG_NAME }}:latest
7 changes: 0 additions & 7 deletions .github/workflows/delivery/docker/project.toml

This file was deleted.

6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ARG base_image=gcr.io/distroless/static

FROM golang:1.20 as builder
ARG pack_version
ENV PACK_VERSION=$pack_version
WORKDIR /app
COPY . .
RUN make build

FROM scratch
FROM ${base_image}
COPY --from=builder /app/out/pack /usr/local/bin/pack
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /tmp /tmp
ENTRYPOINT [ "/usr/local/bin/pack" ]
2 changes: 1 addition & 1 deletion acceptance/testdata/pack_fixtures/report_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pack:
Version: {{ .Version }}
OS/Arch: {{ .OS }}/{{ .Arch }}

Default Lifecycle Version: 0.17.1
Default Lifecycle Version: 0.17.2

Supported Platform APIs: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Microsoft/go-winio v0.6.1
github.com/apex/log v1.9.0
github.com/buildpacks/imgutil v0.0.0-20230626185301-726f02e4225c
github.com/buildpacks/lifecycle v0.17.1
github.com/buildpacks/lifecycle v0.17.2
github.com/docker/cli v24.0.6+incompatible
github.com/docker/docker v24.0.6+incompatible
github.com/docker/go-connections v0.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20230522190001-
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I=
github.com/buildpacks/imgutil v0.0.0-20230626185301-726f02e4225c h1:HlRuSz+JGAzudNtNCfHIzXe0AEuHX6Vx8uZgmjvX02o=
github.com/buildpacks/imgutil v0.0.0-20230626185301-726f02e4225c/go.mod h1:mBG5M3GJW5nknCEOOqtmMHyPYnSpw/5GEiciuYU/COw=
github.com/buildpacks/lifecycle v0.17.1 h1:sCNj83TH1YE8Z3+CKHoFx/HK+llCVF1RlQUbj3xdNBQ=
github.com/buildpacks/lifecycle v0.17.1/go.mod h1:WFzcNp1WG4bwgHuXtKxMg4tdU3AguL44ZlP3knANeVs=
github.com/buildpacks/lifecycle v0.17.2 h1:CfJYWHIC5v996idgjDamYHBTk+G+c1Qt7Yk80MlbWpw=
github.com/buildpacks/lifecycle v0.17.2/go.mod h1:h8MrqltqMM+HQnn2F2JOQaKWmeybZ54qvlNV3pAiAqw=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 h1:krfRl01rzPzxSxyLyrChD+U+MzsBXbm0OwYYB67uF+4=
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589/go.mod h1:OuDyvmLnMCwa2ep4Jkm6nyA0ocJuZlGyk2gGseVzERM=
Expand Down
2 changes: 1 addition & 1 deletion internal/builder/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// A snapshot of the latest tested lifecycle version values
const (
DefaultLifecycleVersion = "0.17.1"
DefaultLifecycleVersion = "0.17.2"
DefaultBuildpackAPIVersion = "0.2"
)

Expand Down
15 changes: 13 additions & 2 deletions pkg/buildpack/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ type DownloadOptions struct {
// The OS of the builder image
ImageOS string

// The OS/Architecture to download
Platform string

// Deprecated: the older alternative to buildpack URI
ImageName string

Expand Down Expand Up @@ -102,7 +105,11 @@ func (c *buildpackDownloader) Download(ctx context.Context, moduleURI string, op
case PackageLocator:
imageName := ParsePackageLocator(moduleURI)
c.logger.Debugf("Downloading %s from image: %s", kind, style.Symbol(imageName))
mainBP, depBPs, err = extractPackaged(ctx, kind, imageName, c.imageFetcher, image.FetchOptions{Daemon: opts.Daemon, PullPolicy: opts.PullPolicy})
mainBP, depBPs, err = extractPackaged(ctx, kind, imageName, c.imageFetcher, image.FetchOptions{
Daemon: opts.Daemon,
PullPolicy: opts.PullPolicy,
Platform: opts.Platform,
})
if err != nil {
return nil, nil, errors.Wrapf(err, "extracting from registry %s", style.Symbol(moduleURI))
}
Expand All @@ -113,7 +120,11 @@ func (c *buildpackDownloader) Download(ctx context.Context, moduleURI string, op
return nil, nil, errors.Wrapf(err, "locating in registry: %s", style.Symbol(moduleURI))
}

mainBP, depBPs, err = extractPackaged(ctx, kind, address, c.imageFetcher, image.FetchOptions{Daemon: opts.Daemon, PullPolicy: opts.PullPolicy})
mainBP, depBPs, err = extractPackaged(ctx, kind, address, c.imageFetcher, image.FetchOptions{
Daemon: opts.Daemon,
PullPolicy: opts.PullPolicy,
Platform: opts.Platform,
})
if err != nil {
return nil, nil, errors.Wrapf(err, "extracting from registry %s", style.Symbol(moduleURI))
}
Expand Down
24 changes: 15 additions & 9 deletions pkg/buildpack/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
downloadOptions = buildpack.DownloadOptions{ImageOS: "linux"}
)

shouldFetchPackageImageWith := func(demon bool, pull image.PullPolicy) {
mockImageFetcher.EXPECT().Fetch(gomock.Any(), packageImage.Name(), image.FetchOptions{Daemon: demon, PullPolicy: pull}).Return(packageImage, nil)
shouldFetchPackageImageWith := func(demon bool, pull image.PullPolicy, platform string) {
mockImageFetcher.EXPECT().Fetch(gomock.Any(), packageImage.Name(), image.FetchOptions{
Daemon: demon,
PullPolicy: pull,
Platform: platform,
}).Return(packageImage, nil)
}

when("package image lives in cnb registry", func() {
Expand All @@ -141,11 +145,12 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
downloadOptions = buildpack.DownloadOptions{
RegistryName: "some-registry",
ImageOS: "linux",
Platform: "linux/amd64",
Daemon: true,
PullPolicy: image.PullAlways,
}

shouldFetchPackageImageWith(true, image.PullAlways)
shouldFetchPackageImageWith(true, image.PullAlways, "linux/amd64")
mainBP, _, err := buildpackDownloader.Download(context.TODO(), "urn:cnb:registry:example/[email protected]", downloadOptions)
h.AssertNil(t, err)
h.AssertEq(t, mainBP.Descriptor().Info().ID, "example/foo")
Expand All @@ -161,7 +166,7 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
PullPolicy: image.PullAlways,
}

shouldFetchPackageImageWith(true, image.PullAlways)
shouldFetchPackageImageWith(true, image.PullAlways, "")
mainBP, _, err := buildpackDownloader.Download(context.TODO(), "example/[email protected]", downloadOptions)
h.AssertNil(t, err)
h.AssertEq(t, mainBP.Descriptor().Info().ID, "example/foo")
Expand All @@ -185,10 +190,11 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
Daemon: true,
PullPolicy: image.PullAlways,
ImageOS: "linux",
Platform: "linux/amd64",
ImageName: "some/package:tag",
}

shouldFetchPackageImageWith(true, image.PullAlways)
shouldFetchPackageImageWith(true, image.PullAlways, "linux/amd64")
mainBP, _, err := buildpackDownloader.Download(context.TODO(), "", downloadOptions)
h.AssertNil(t, err)
h.AssertEq(t, mainBP.Descriptor().Info().ID, "example/foo")
Expand All @@ -204,7 +210,7 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
PullPolicy: image.PullAlways,
}

shouldFetchPackageImageWith(true, image.PullAlways)
shouldFetchPackageImageWith(true, image.PullAlways, "")
mainBP, _, err := buildpackDownloader.Download(context.TODO(), "", downloadOptions)
h.AssertNil(t, err)
h.AssertEq(t, mainBP.Descriptor().Info().ID, "example/foo")
Expand All @@ -220,7 +226,7 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
PullPolicy: image.PullAlways,
}

shouldFetchPackageImageWith(false, image.PullAlways)
shouldFetchPackageImageWith(false, image.PullAlways, "")
mainBP, _, err := buildpackDownloader.Download(context.TODO(), "", downloadOptions)
h.AssertNil(t, err)
h.AssertEq(t, mainBP.Descriptor().Info().ID, "example/foo")
Expand All @@ -234,7 +240,7 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
Daemon: false,
PullPolicy: image.PullAlways,
}
shouldFetchPackageImageWith(false, image.PullAlways)
shouldFetchPackageImageWith(false, image.PullAlways, "")
mainBP, _, err := buildpackDownloader.Download(context.TODO(), packageImage.Name(), downloadOptions)
h.AssertNil(t, err)
h.AssertEq(t, mainBP.Descriptor().Info().ID, "example/foo")
Expand All @@ -250,7 +256,7 @@ func testBuildpackDownloader(t *testing.T, when spec.G, it spec.S) {
PullPolicy: image.PullNever,
}

shouldFetchPackageImageWith(false, image.PullNever)
shouldFetchPackageImageWith(false, image.PullNever, "")
mainBP, _, err := buildpackDownloader.Download(context.TODO(), "", downloadOptions)
h.AssertNil(t, err)
h.AssertEq(t, mainBP.Descriptor().Info().ID, "example/foo")
Expand Down
49 changes: 32 additions & 17 deletions pkg/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,28 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
return errors.Wrapf(err, "failed to fetch builder image '%s'", builderRef.Name())
}

builderOS, err := rawBuilderImage.OS()
if err != nil {
return errors.Wrapf(err, "getting builder OS")
}

builderArch, err := rawBuilderImage.Architecture()
if err != nil {
return errors.Wrapf(err, "getting builder architecture")
}

bldr, err := c.getBuilder(rawBuilderImage)
if err != nil {
return errors.Wrapf(err, "invalid builder %s", style.Symbol(opts.Builder))
}

runImageName := c.resolveRunImage(opts.RunImage, imgRegistry, builderRef.Context().RegistryStr(), bldr.DefaultRunImage(), opts.AdditionalMirrors, opts.Publish)

fetchOptions := image.FetchOptions{Daemon: !opts.Publish, PullPolicy: opts.PullPolicy}
fetchOptions := image.FetchOptions{
Daemon: !opts.Publish,
PullPolicy: opts.PullPolicy,
Platform: fmt.Sprintf("%s/%s", builderOS, builderArch),
}
if opts.Layout() {
targetRunImagePath, err := layout.ParseRefToPath(runImageName)
if err != nil {
Expand Down Expand Up @@ -361,11 +375,6 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
return err
}

imgOS, err := rawBuilderImage.OS()
if err != nil {
return errors.Wrapf(err, "getting builder OS")
}

// Default mode: if the TrustBuilder option is not set, trust the suggested builders.
if opts.TrustBuilder == nil {
opts.TrustBuilder = IsSuggestedBuilderFunc
Expand Down Expand Up @@ -396,15 +405,14 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
lifecycleImageName = fmt.Sprintf("%s:%s", internalConfig.DefaultLifecycleImageRepo, lifecycleVersion.String())
}

imgArch, err := rawBuilderImage.Architecture()
if err != nil {
return errors.Wrapf(err, "getting builder architecture")
}

lifecycleImage, err := c.imageFetcher.Fetch(
ctx,
lifecycleImageName,
image.FetchOptions{Daemon: true, PullPolicy: opts.PullPolicy, Platform: fmt.Sprintf("%s/%s", imgOS, imgArch)},
image.FetchOptions{
Daemon: true,
PullPolicy: opts.PullPolicy,
Platform: fmt.Sprintf("%s/%s", builderOS, builderArch),
},
)
if err != nil {
return fmt.Errorf("fetching lifecycle image: %w", err)
Expand Down Expand Up @@ -455,7 +463,7 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
if !c.experimental {
return fmt.Errorf("experimental features must be enabled when builder contains image extensions")
}
if imgOS == "windows" {
if builderOS == "windows" {
return fmt.Errorf("builder contains image extensions which are not supported for Windows builds")
}
if !(opts.PullPolicy == image.PullAlways) {
Expand All @@ -467,7 +475,7 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
opts.ContainerConfig.Volumes = appendLayoutVolumes(opts.ContainerConfig.Volumes, pathsConfig)
}

processedVolumes, warnings, err := processVolumes(imgOS, opts.ContainerConfig.Volumes)
processedVolumes, warnings, err := processVolumes(builderOS, opts.ContainerConfig.Volumes)
if err != nil {
return err
}
Expand Down Expand Up @@ -1024,13 +1032,19 @@ func (c *Client) fetchBuildpack(ctx context.Context, bp string, relativeBaseDir
Version: version,
}
default:
imageOS, err := builderImage.OS()
builderOS, err := builderImage.OS()
if err != nil {
return nil, nil, errors.Wrapf(err, "getting builder OS")
}

builderArch, err := builderImage.Architecture()
if err != nil {
return nil, nil, errors.Wrapf(err, "getting OS from %s", style.Symbol(builderImage.Name()))
return nil, nil, errors.Wrapf(err, "getting builder architecture")
}
downloadOptions := buildpack.DownloadOptions{
RegistryName: registry,
ImageOS: imageOS,
ImageOS: builderOS,
Platform: fmt.Sprintf("%s/%s", builderOS, builderArch),
RelativeBaseDir: relativeBaseDir,
Daemon: !publish,
PullPolicy: pullPolicy,
Expand Down Expand Up @@ -1068,6 +1082,7 @@ func (c *Client) fetchBuildpackDependencies(ctx context.Context, bp string, pack
mainBP, deps, err := c.buildpackDownloader.Download(ctx, dep.URI, buildpack.DownloadOptions{
RegistryName: downloadOptions.RegistryName,
ImageOS: downloadOptions.ImageOS,
Platform: downloadOptions.Platform,
Daemon: downloadOptions.Daemon,
PullPolicy: downloadOptions.PullPolicy,
RelativeBaseDir: filepath.Join(bp, packageCfg.Buildpack.URI),
Expand Down
Loading

0 comments on commit 1ffbc10

Please sign in to comment.