Skip to content

Commit 9d85f25

Browse files
fix: verify shasum for finch dependencies (runfinch#969)
Issue #, if available: Finch dependencies must be verified against known good shasum at pull time. *Description of changes:* This change refactors Finch to use the dependency mechanism in `finch-core` for pulling and verifying core dependencies such as the OS image and Lima bundle for macOS and the rootfs archive for Windows platforms. As a side effect of this change, dependency updates are now 1-to-1 with finch-core updates. This is a simplification on the current mechanism which duplicated the effort for updates. *Testing done:* Ran `make` on macOS. - [x] I've reviewed the guidance in CONTRIBUTING.md #### License Acceptance By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. Signed-off-by: Austin Vazquez <[email protected]>
1 parent 0244698 commit 9d85f25

File tree

6 files changed

+90
-158
lines changed

6 files changed

+90
-158
lines changed

Diff for: .github/bin/update-os-image.sh

-24
This file was deleted.

Diff for: .github/workflows/sync-submodules-and-deps.yaml

+3-15
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ jobs:
3434
run: |
3535
git submodule update --remote
3636
37-
- name: Update OS image
38-
run: |
39-
./.github/bin/update-os-image.sh
40-
41-
- name: Update lima dependencies url
42-
run: |
43-
./deps/finch-core/bin/update-deps.sh -d ${{ secrets.DEPENDENCY_BUCKET_NAME }}
44-
45-
- name: Update rootfs
46-
run: |
47-
./deps/finch-core/bin/update-rootfs.sh -d ${{ secrets.DEPENDENCY_BUCKET_NAME }}
48-
4937
- name: Create PR
5038
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6.1.0
5139
with:
@@ -55,9 +43,9 @@ jobs:
5543
body: >
5644
Bump for Finch's dependencies.
5745
58-
Currently, this updates values based on artifacts defined in the finch-core repository,
59-
such as: operating system images, and the version of Lima (and it's dependencies),
60-
which are bundled as `lima-and-qemu.macos-*.*.tar.gz` archives.
46+
Updates finch-core submodule which defines the core dependencies for Finch on each respective
47+
platform such as: operating system images and Lima bundle (Lima version and it's dependencies)
48+
as `lima-and-qemu.macos-*.*.tar.gz` archives.
6149
6250
Since updating the Lima version may also update the default version of the `nerdctl-full`
6351
archive (which contains nerdctl, containerd, buildkit, etc.), this may require a manual

Diff for: Makefile

+20-118
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ PREFIX ?= $(CURDIR)/_output
77
DEST := $(shell echo "$(DESTDIR)/$(PREFIX)" | sed 's:///*:/:g; s://*$$::')
88
BINDIR ?= /usr/local/bin
99
OUTDIR ?= $(CURDIR)/_output
10+
OS_OUTDIR ?= $(OUTDIR)/os
11+
12+
OUTPUT_DIRECTORIES := $(OUTDIR) $(OS_OUTDIR)
13+
$(OUTPUT_DIRECTORIES):
14+
@mkdir -p $@
15+
1016
PACKAGE := github.com/runfinch/finch
1117
BINARYNAME := finch
1218
LIMA_FILENAME := lima
1319
LIMA_EXTENSION := .tar.gz
1420

15-
LIMA_HOME := $(DEST)/lima/data
1621
# Created by the CLI after installation, only used in uninstall step
1722
LIMA_VDE_SUDOERS_FILE := /etc/sudoers.d/finch-lima
1823
# Final installation prefix for vde created by CLI after installation, only used in uninstall step
1924
VDE_INSTALL ?= /opt/finch
2025
UNAME := $(shell uname -m)
2126
ARCH ?= $(UNAME)
2227
SUPPORTED_ARCH = false
23-
CORE_VDE_PREFIX ?= $(OUTDIR)/dependencies/vde/opt/finch
2428
LICENSEDIR := $(OUTDIR)/license-files
2529
VERSION := $(shell git describe --match 'v[0-9]*' --dirty='.modified' --always --tags)
2630
GITCOMMIT := $(shell git rev-parse HEAD)$(shell test -z "$(git status --porcelain)" || echo .m)
@@ -30,9 +34,6 @@ MIN_MACOS_VERSION ?= 11.0
3034
GOOS ?= $(shell $(GO) env GOOS)
3135
ifeq ($(GOOS),windows)
3236
BINARYNAME := $(addsuffix .exe, $(BINARYNAME))
33-
sha = sha256sum
34-
else
35-
sha = shasum -a 256
3637
endif
3738

3839
.DEFAULT_GOAL := all
@@ -42,129 +43,31 @@ REGISTRY ?= ""
4243
ifneq (,$(findstring arm64,$(ARCH)))
4344
SUPPORTED_ARCH = true
4445
LIMA_ARCH = aarch64
45-
# From https://dl.fedoraproject.org/pub/fedora/linux/releases/40/Cloud/aarch64/images/
46-
FINCH_OS_BASENAME ?= Fedora-Cloud-Base-40-1.14.aarch64-20240514214641.qcow2
47-
LIMA_URL ?= https://deps.runfinch.com/aarch64/lima-and-qemu.macos-aarch64.1715678889.tar.gz
4846
else ifneq (,$(findstring x86_64,$(ARCH)))
4947
SUPPORTED_ARCH = true
5048
LIMA_ARCH = x86_64
51-
# From https://dl.fedoraproject.org/pub/fedora/linux/releases/40/Cloud/x86_64/images/
52-
FINCH_OS_BASENAME ?= Fedora-Cloud-Base-40-1.14.x86_64-20240514214655.qcow2
53-
LIMA_URL ?= https://deps.runfinch.com/x86-64/lima-and-qemu.macos-x86_64.1715678889.tar.gz
54-
FINCH_ROOTFS_URL ?= https://deps.runfinch.com/common/x86-64/finch-rootfs-production-amd64-1715724303.tar.gz
55-
FINCH_ROOTFS_BASENAME := $(notdir $(FINCH_ROOTFS_URL))
5649
endif
5750

58-
FINCH_OS_HASH := `$(sha) $(OUTDIR)/os/$(FINCH_OS_BASENAME) | cut -d ' ' -f 1`
59-
FINCH_OS_DIGEST := "sha256:$(FINCH_OS_HASH)"
60-
FINCH_OS_IMAGE_LOCATION_ROOT ?= $(DEST)
61-
FINCH_OS_IMAGE_LOCATION ?= $(FINCH_OS_IMAGE_LOCATION_ROOT)/os/$(FINCH_OS_BASENAME)
62-
63-
# TODO: Windows PoC extracting rootfs...
64-
FINCH_ROOTFS_HASH := `$(sha) $(OUTDIR)/os/$(FINCH_ROOTFS_BASENAME) | cut -d ' ' -f 1`
65-
FINCH_ROOTFS_DIGEST := "sha256:$(FINCH_ROOTFS_HASH)"
66-
FINCH_ROOTFS_LOCATION_ROOT ?= $(DEST)/
67-
FINCH_ROOTFS_LOCATION ?= $(FINCH_ROOTFS_LOCATION_ROOT)os/$(FINCH_ROOTFS_BASENAME)
68-
6951
.PHONY: arch-test
7052
arch-test:
7153
@if [ $(SUPPORTED_ARCH) != "true" ]; then echo "Unsupported architecture: $(ARCH)"; exit "1"; fi
7254

73-
.PHONY: all
74-
ifeq ($(GOOS),windows)
75-
all: arch-test finch finch-core-local finch.windows.yaml networks.yaml config.yaml
55+
BUILD_OS ?= $(OS)
56+
FINCH_CORE_DIR := $(CURDIR)/deps/finch-core
57+
ifeq ($(BUILD_OS), Windows_NT)
58+
include Makefile.windows
7659
else
77-
all: arch-test finch finch-core finch.yaml networks.yaml config.yaml lima-and-qemu
60+
include Makefile.darwin
7861
endif
7962

80-
.PHONY: all-local
81-
all-local: arch-test networks.yaml config.yaml lima-and-qemu local-core finch.yaml
82-
83-
.PHONY: finch-core
84-
finch-core:
85-
cd deps/finch-core && \
86-
FINCH_OS_AARCH64_URL="$(FINCH_OS_AARCH64_URL)" \
87-
VDE_TEMP_PREFIX=$(CORE_VDE_PREFIX) \
88-
"$(MAKE)"
89-
90-
mkdir -p _output
91-
cd deps/finch-core/_output && tar -cf - * | tar -xvf - -C $(OUTDIR)
92-
rm -rf $(OUTDIR)/lima-template
93-
94-
.PHONY: finch-core-local
95-
finch-core-local:
96-
cd deps/finch-core && \
97-
FINCH_OS_x86_URL="$(FINCH_OS_x86_URL)" \
98-
FINCH_OS_AARCH64_URL="$(FINCH_OS_AARCH64_URL)" \
99-
VDE_TEMP_PREFIX=$(CORE_VDE_PREFIX) \
100-
"$(MAKE)" all lima
101-
102-
mkdir -p _output
103-
cd deps/finch-core/_output && tar -cf - * | tar -xvf - -C $(OUTDIR)
104-
rm -rf $(OUTDIR)/lima-template
105-
106-
.PHONY: local-core
107-
local-core:
108-
cd deps/finch-core && \
109-
FINCH_OS_x86_URL="$(FINCH_OS_x86_URL)" \
110-
FINCH_OS_AARCH64_URL="$(FINCH_OS_AARCH64_URL)" \
111-
VDE_TEMP_PREFIX=$(CORE_VDE_PREFIX) \
112-
"$(MAKE)" lima lima-socket-vmnet
113-
114-
mkdir -p _output
115-
cd deps/finch-core/_output && tar -cf - * | tar -xvf - -C $(OUTDIR)
116-
cd deps/finch-core/src/lima/_output && tar -cf - * | tar -xvf - -C $(OUTDIR)/lima
117-
cd deps/finch-core/_output && tar -cf - * | tar -xvf - -C $(OUTDIR)
118-
cd deps/finch-core/src/lima/_output && tar -cf - * | tar -xvf - -C $(OUTDIR)/lima
119-
rm -rf $(OUTDIR)/lima-template
120-
121-
.PHONY: lima-and-qemu
122-
lima-and-qemu: networks.yaml
123-
mkdir -p $(OUTDIR)/downloads
124-
# download artifacts
125-
curl -L $(LIMA_URL) > $(OUTDIR)/downloads/lima-and-qemu.tar.gz
126-
127-
# Untar LIMA
128-
tar -xvf $(OUTDIR)/downloads/lima-and-qemu.tar.gz -C $(OUTDIR)/lima/
129-
130-
# Delete downloads
131-
rm -rf $(OUTDIR)/downloads
132-
133-
134-
FINCH_IMAGE_LOCATION ?=
135-
FINCH_IMAGE_DIGEST ?=
136-
ifeq ($(GOOS),windows)
137-
# Because the path in windows /C:/<some-path> is not an Absolute path, prefix with file:/ which is handled by lima https://github.com/lima-vm/lima/blob/da1260dc87fb30345c3ee7bfb131c29646e26d10/pkg/downloader/downloader.go#L266
138-
FINCH_IMAGE_LOCATION := "file:/$(FINCH_ROOTFS_LOCATION)"
139-
FINCH_IMAGE_DIGEST := $(FINCH_ROOTFS_DIGEST)
140-
else
141-
FINCH_IMAGE_LOCATION := $(FINCH_OS_IMAGE_LOCATION)
142-
FINCH_IMAGE_DIGEST := $(FINCH_OS_DIGEST)
143-
endif
144-
.PHONY: finch.yaml
145-
finch.yaml: finch-core
146-
mkdir -p $(OUTDIR)/os
147-
# merge the appropriate YAMLs
148-
cd finch.yaml.d && yq eval-all '. as $$item ireduce ({}; . *+ $$item)' mac.yaml common.yaml > ../finch.yaml
149-
cp finch.yaml $(OUTDIR)/os
150-
# using -i.bak is very intentional, it allows the following commands to succeed for both GNU / BSD sed
151-
# this sed command uses the alternative separator of "|" because the image location uses "/"
152-
sed -i.bak -e "s|<finch_image_location>|$(FINCH_IMAGE_LOCATION)|g" $(OUTDIR)/os/finch.yaml
153-
sed -i.bak -e "s/<finch_image_arch>/$(LIMA_ARCH)/g" $(OUTDIR)/os/finch.yaml
154-
sed -i.bak -e "s/<finch_image_digest>/$(FINCH_IMAGE_DIGEST)/g" $(OUTDIR)/os/finch.yaml
155-
156-
# TODO: Windows PoC - clean this up / consolidate
63+
all: arch-test finch install.finch-core-dependencies finch.yaml networks.yaml config.yaml
64+
65+
.PHONY: install.finch-core-dependencies
66+
install.finch-core-dependencies:
67+
OUTDIR=$(OUTDIR) "$(MAKE)" -C $(FINCH_CORE_DIR) install.dependencies
68+
15769
.PHONY: finch.yaml
158-
finch.windows.yaml: finch-core-local
159-
mkdir -p $(OUTDIR)/os
160-
# merge the appropriate YAMLs
161-
cd finch.yaml.d && yq eval-all '. as $$item ireduce ({}; . *+ $$item)' windows.yaml common.yaml > ../finch.windows.yaml
162-
cp finch.windows.yaml $(OUTDIR)/os/finch.yaml
163-
# using -i.bak is very intentional, it allows the following commands to succeed for both GNU / BSD sed
164-
# this sed command uses the alternative separator of "|" because the image location uses "/"
165-
sed -i.bak -e "s|<finch_image_location>|$(FINCH_IMAGE_LOCATION)|g" $(OUTDIR)/os/finch.yaml
166-
sed -i.bak -e "s/<finch_image_arch>/$(LIMA_ARCH)/g" $(OUTDIR)/os/finch.yaml
167-
sed -i.bak -e "s/<finch_image_digest>/$(FINCH_IMAGE_DIGEST)/g" $(OUTDIR)/os/finch.yaml
70+
finch.yaml: $(OS_OUTDIR)/finch.yaml
16871

16972
.PHONY: networks.yaml
17073
networks.yaml:
@@ -402,7 +305,7 @@ mdlint-ctr:
402305
ifeq ($(GOOS),windows)
403306
clean:
404307
-@rm -rf $(OUTDIR) 2>/dev/null || true
405-
-@rm -rf ./deps/finch-core/_output || true
308+
-@"$(MAKE)" -C $(FINCH_CORE_DIR) clean
406309
-@rm ./*.tar.gz 2>/dev/null || true
407310
-@rm ./*.qcow2 2>/dev/null || true
408311
-@rm ./test-coverage.* 2>/dev/null || true
@@ -415,8 +318,7 @@ clean:
415318
-sudo rm -rf "/private/var/run/finch-lima"
416319
-sudo rm -rf "/private/etc/sudoers.d/finch-lima"
417320
-@rm -rf $(OUTDIR) 2>/dev/null || true
418-
-@rm -rf ./deps/finch-core/_output || true
419-
-@rm -rf ./deps/finch-core/downloads/os/$(FINCH_OS_BASENAME) || true
321+
-@$(MAKE) -C $(FINCH_CORE_DIR) clean
420322
-@rm ./*.tar.gz 2>/dev/null || true
421323
-@rm ./*.qcow2 2>/dev/null || true
422324
-@rm ./test-coverage.* 2>/dev/null || true

Diff for: Makefile.darwin

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# For Finch on macOS, the base OS location and digest are set
5+
# based on the values set in deps/finch-core/deps/full-os.conf
6+
-include $(FINCH_CORE_DIR)/deps/full-os.conf
7+
ifeq ($(ARCH),x86_64)
8+
FINCH_OS_BASENAME=$(X86_64_ARTIFACT)
9+
FINCH_OS_DIGEST=$(X86_64_512_DIGEST)
10+
else
11+
FINCH_OS_BASENAME=$(AARCH64_ARTIFACT)
12+
FINCH_OS_DIGEST=$(AARCH64_512_DIGEST)
13+
endif
14+
15+
FINCH_IMAGE_LOCATION:=$(OS_OUTDIR)/$(FINCH_OS_BASENAME)
16+
FINCH_IMAGE_DIGEST:="sha512:$(FINCH_OS_DIGEST)"
17+
18+
.PHONY: finch.yaml
19+
finch.yaml: $(OS_OUTDIR)/finch.yaml
20+
21+
$(OS_OUTDIR)/finch.yaml: $(OS_OUTDIR) finch.yaml.d/common.yaml finch.yaml.d/mac.yaml
22+
# merge the appropriate YAMLs into a temporary finch.yaml file on the current working directory
23+
cd finch.yaml.d && yq eval-all '. as $$item ireduce ({}; . *+ $$item)' mac.yaml common.yaml > ../finch.yaml.temp
24+
25+
# using -i.bak is very intentional, it allows the following commands to succeed for both GNU / BSD sed
26+
# this sed command uses the alternative separator of "|" because the image location uses "/"
27+
sed -i.bak -e "s|<finch_image_location>|$(FINCH_IMAGE_LOCATION)|g" finch.yaml.temp
28+
sed -i.bak -e "s/<finch_image_arch>/$(LIMA_ARCH)/g" finch.yaml.temp
29+
sed -i.bak -e "s/<finch_image_digest>/$(FINCH_IMAGE_DIGEST)/g" finch.yaml.temp
30+
31+
# Replacement was successful, so cleanup .bak
32+
@rm finch.yaml.temp.bak
33+
34+
mv finch.yaml.temp $@

Diff for: Makefile.windows

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# For Finch on Windows, the rootfs location and digest are set
5+
# based on the values in deps/finch-core/deps/rootfs.conf
6+
-include $(FINCH_CORE_DIR)/deps/rootfs.conf
7+
ifeq ($(ARCH),x86_64)
8+
FINCH_ROOTFS_BASENAME ?= $(X86_64_ARTIFACT)
9+
FINCH_ROOTFS_DIGEST ?= $(X86_64_512_DIGEST)
10+
else
11+
$(error Finch on Windows ARM not supported)
12+
endif
13+
14+
FINCH_IMAGE_LOCATION := $(OS_OUTDIR)/$(FINCH_ROOTFS_BASENAME)
15+
FINCH_IMAGE_DIGEST := "sha512:$(FINCH_ROOTFS_DIGEST)"
16+
17+
$(OS_OUTDIR)/finch.yaml: $(OS_OUTDIR) finch.yaml.d/common.yaml finch.yaml.d/windows.yaml
18+
# merge the appropriate YAMLs into a temporary finch.yaml file on the current working directory
19+
cd finch.yaml.d && yq eval-all '. as $$item ireduce ({}; . *+ $$item)' windows.yaml common.yaml > ../finch.yaml.temp
20+
21+
# using -i.bak is very intentional, it allows the following commands to succeed for both GNU / BSD sed
22+
# this sed command uses the alternative separator of "|" because the image location uses "/"
23+
# Because the path in windows /C:/<some-path> is not an Absolute path, prefix with file:/ which is handled by lima
24+
# https://github.com/lima-vm/lima/blob/da1260dc87fb30345c3ee7bfb131c29646e26d10/pkg/downloader/downloader.go#L266
25+
sed -i.bak -e "s|<finch_image_location>|file://$(FINCH_IMAGE_LOCATION)|g" finch.yaml.temp
26+
sed -i.bak -e "s/<finch_image_arch>/$(LIMA_ARCH)/g" finch.yaml.temp
27+
sed -i.bak -e "s/<finch_image_digest>/$(FINCH_IMAGE_DIGEST)/g" finch.yaml.temp
28+
29+
# Replacement was successful, so cleanup .bak
30+
@rm finch.yaml.temp.bak
31+
32+
mv finch.yaml.temp $@

0 commit comments

Comments
 (0)