Skip to content

Commit 30976dd

Browse files
authored
feat: add finch-daemon (runfinch#1181)
* feat: add finch-daemon Signed-off-by: Justin Alvarez <[email protected]> * cleanup service file Signed-off-by: Justin Alvarez <[email protected]> * fix submodule Signed-off-by: Justin Alvarez <[email protected]> * add e2e smoke-test for finch-daemon Signed-off-by: Justin Alvarez <[email protected]> * match submodule commit in main branch Signed-off-by: Justin Alvarez <[email protected]> * add newline Signed-off-by: Justin Alvarez <[email protected]> * go mod tidy Signed-off-by: Justin Alvarez <[email protected]> * fix lint Signed-off-by: Justin Alvarez <[email protected]> * replace broken go.openconcensus.io package Signed-off-by: Justin Alvarez <[email protected]> * temporary fix for go.opencensus.io issue Signed-off-by: Justin Alvarez <[email protected]> * remove go.openconcensus.io workarounds Signed-off-by: Justin Alvarez <[email protected]> * remove custom DefaultLimitNOFILE Signed-off-by: Justin Alvarez <[email protected]> * add daemon test target Signed-off-by: Justin Alvarez <[email protected]> * fix test command Signed-off-by: Justin Alvarez <[email protected]> * update finch-core Signed-off-by: Justin Alvarez <[email protected]> * temporarily update finch-daemon remote tracking branch Signed-off-by: Justin Alvarez <[email protected]> * ensure vm state Signed-off-by: Justin Alvarez <[email protected]> * typo Signed-off-by: Justin Alvarez <[email protected]> * typo Signed-off-by: Justin Alvarez <[email protected]> * add "force" flag so commands exit silently Signed-off-by: Justin Alvarez <[email protected]> * make vm logic smarter Signed-off-by: Justin Alvarez <[email protected]> * temporarily disable non-daemon CI Signed-off-by: Justin Alvarez <[email protected]> * fix vm logic Signed-off-by: Justin Alvarez <[email protected]> * update finch-core Signed-off-by: Justin Alvarez <[email protected]> * update test command to use new finch-daemon variables Signed-off-by: Justin Alvarez <[email protected]> * temporarily switch tracking branch until finch-daemon changes are merged Signed-off-by: Justin Alvarez <[email protected]> * update finch-core to track latest finch-daemon commit Signed-off-by: Justin Alvarez <[email protected]> * remove create-report-dir (naming scheme is broken) Signed-off-by: Justin Alvarez <[email protected]> * re-add temporarily removed tests Signed-off-by: Justin Alvarez <[email protected]> * re-add macOS tests Signed-off-by: Justin Alvarez <[email protected]> * remove extra whitespace Signed-off-by: Justin Alvarez <[email protected]> * resolve finch-core conflict Signed-off-by: Justin Alvarez <[email protected]> * fix the conditional addition of the daemon mount Signed-off-by: Justin Alvarez <[email protected]> * increase test timeout Signed-off-by: Justin Alvarez <[email protected]> --------- Signed-off-by: Justin Alvarez <[email protected]>
1 parent 89ad42b commit 30976dd

File tree

12 files changed

+190
-7
lines changed

12 files changed

+190
-7
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ jobs:
173173
fail-fast: false
174174
matrix:
175175
version: ['13', '14']
176-
test-command: ['test-e2e-vm-serial', 'test-e2e-container']
176+
test-command: ['test-e2e-vm-serial', 'test-e2e-container', 'test-e2e-daemon']
177177
arch: ['X64', 'arm64']
178178
runner-type: ['test']
179179
uses: ./.github/workflows/e2e-macos.yaml

.github/workflows/e2e-macos.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
"${{ inputs.version }}",
3636
"${{ inputs.runner-type }}",
3737
]
38-
timeout-minutes: 60
38+
timeout-minutes: 80
3939
outputs:
4040
has_creds: ${{ steps.vars.outputs.has_creds}}
4141
vm_report: ${{ steps.set-multiple-vars.outputs.VM_REPORT }}

Makefile

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ VERSION_INJECTION += -X $(PACKAGE)/pkg/version.GitCommit=$(GITCOMMIT)
3636
LDFLAGS = "-w $(VERSION_INJECTION)"
3737
MIN_MACOS_VERSION ?= 11.0
3838

39+
FINCH_DAEMON_LOCATION_ROOT ?= $(FINCH_OS_IMAGE_LOCATION_ROOT)/finch-daemon
40+
FINCH_DAEMON_LOCATION ?= $(FINCH_DAEMON_LOCATION_ROOT)/finch-daemon
41+
3942
GOOS ?= $(shell $(GO) env GOOS)
4043
ifeq ($(GOOS),windows)
4144
BINARYNAME := $(addsuffix .exe, $(BINARYNAME))
@@ -75,7 +78,7 @@ endif
7578

7679
FINCH_CORE_DIR := $(CURDIR)/deps/finch-core
7780

78-
remote-all: arch-test finch install.finch-core-dependencies finch.yaml networks.yaml config.yaml
81+
remote-all: arch-test finch install.finch-core-dependencies finch.yaml networks.yaml config.yaml $(OUTDIR)/finch-daemon/[email protected]
7982

8083
ifeq ($(BUILD_OS), Windows_NT)
8184
include Makefile.windows
@@ -168,6 +171,9 @@ finch-all:
168171
.PHONY: release
169172
release: check-licenses all download-licenses
170173

174+
$(OUTDIR)/finch-daemon/[email protected]:
175+
cp [email protected] $(OUTDIR)/finch-daemon/[email protected]
176+
171177
.PHONY: coverage
172178
coverage:
173179
go test $(shell go list ./... | grep -v e2e | grep -v benchmark | grep -v mocks) -coverprofile=test-coverage.out
@@ -303,6 +309,32 @@ test-e2e-container: create-report-dir
303309
test-e2e-vm: create-report-dir
304310
go test -ldflags $(LDFLAGS) -timeout 2h ./e2e/vm -test.v -ginkgo.v -ginkgo.timeout=2h -ginkgo.flake-attempts=3 -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-vm-report.json --installed="$(INSTALLED)" --registry="$(REGISTRY)"
305311

312+
GINKGO = go run github.com/onsi/ginkgo/v2/ginkgo
313+
# Common ginkgo options: -v for verbose mode, --focus="test name" for running single tests
314+
GFLAGS ?= --race --randomize-all --randomize-suites
315+
316+
ifeq ($(INSTALLED),true)
317+
DAEMON_DOCKER_HOST := "unix:///Applications/Finch/lima/data/finch/sock/finch.sock"
318+
else
319+
DAEMON_DOCKER_HOST := "unix://$(OUTDIR)/lima/data/finch/sock/finch.sock"
320+
endif
321+
322+
.PHONY: test-e2e-daemon
323+
test-e2e-daemon:
324+
-@$(OUTDIR)/bin/$(BINARYNAME) vm stop -f || true
325+
-@$(OUTDIR)/bin/$(BINARYNAME) vm remove -f
326+
-@$(OUTDIR)/bin/$(BINARYNAME) vm init
327+
328+
cd $(FINCH_CORE_DIR)/src/finch-daemon && \
329+
STATIC=1 GOOS=linux GOARCH=$(GOARCH) make && \
330+
DOCKER_HOST=$(DAEMON_DOCKER_HOST) \
331+
DOCKER_API_VERSION="v1.41" \
332+
TEST_E2E=1 \
333+
go test ./e2e -test.v -ginkgo.v -ginkgo.randomize-all -ginkgo.json-report=$(REPORT_DIR)/$(RUN_ID)-$(RUN_ATTEMPT)-e2e-daemon-report.json \
334+
--subject="$(OUTDIR)/bin/$(BINARYNAME)" \
335+
--daemon-context-subject-prefix="$(OUTDIR)/lima/bin/limactl shell finch sudo" \
336+
--daemon-context-subject-env="LIMA_HOME=$(OUTDIR)/lima/data"
337+
306338
.PHONY: test-benchmark
307339
test-benchmark:
308340
cd benchmark/all && go test -ldflags $(LDFLAGS) -bench=. -benchmem --installed="$(INSTALLED)"

Makefile.darwin

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@ FINCH_OS_IMAGE_LOCATION_ROOT ?= $(DEST)
1818
FINCH_IMAGE_LOCATION ?= $(FINCH_OS_IMAGE_LOCATION_ROOT)/os/$(FINCH_OS_BASENAME)
1919
FINCH_IMAGE_DIGEST ?= "sha512:$(FINCH_OS_DIGEST)"
2020

21+
# check if finch-daemon socket is in a default path
22+
SHOULD_ADD_DAEMON_MOUNT = $(shell if echo "$(FINCH_DAEMON_LOCATION_ROOT)" | grep -q \/Users\/ ; then echo "0"; else echo "1"; fi)
23+
24+
.PHONY: finch.yaml
25+
finch.yaml: $(OS_OUTDIR)/finch.yaml
26+
27+
# only add the finch-daemon mount when its not in a default path
28+
# this scenario is common in dev, where the typical path is /Users/...
29+
ifeq ($(SHOULD_ADD_DAEMON_MOUNT),1)
30+
finch.yaml: add-daemon-mount
31+
endif
32+
2133
$(OS_OUTDIR)/finch.yaml: $(OS_OUTDIR) finch.yaml.d/common.yaml finch.yaml.d/mac.yaml
2234
# 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
35+
cd finch.yaml.d && yq eval-all '. as $$item ireduce ({}; . *+ $$item)' common.yaml mac.yaml > ./../finch.yaml.temp
2436

2537
# using -i.bak is very intentional, it allows the following commands to succeed for both GNU / BSD sed
2638
# this sed command uses the alternative separator of "|" because the image location uses "/"
@@ -31,8 +43,19 @@ $(OS_OUTDIR)/finch.yaml: $(OS_OUTDIR) finch.yaml.d/common.yaml finch.yaml.d/mac.
3143
sed -i.bak -e "s/<container_runtime_archive_aarch64_digest>/$(CONTAINER_RUNTIME_ARCHIVE_AARCH64_DIGEST)/g" finch.yaml.temp
3244
sed -i.bak -e "s|<container_runtime_archive_x86_64_location>|$(CONTAINER_RUNTIME_ARCHIVE_X86_64_LOCATION)|g" finch.yaml.temp
3345
sed -i.bak -e "s/<container_runtime_archive_x86_64_digest>/$(CONTAINER_RUNTIME_ARCHIVE_X86_64_DIGEST)/g" finch.yaml.temp
46+
sed -i.bak -e "s|<finch_daemon_root>|$(FINCH_DAEMON_LOCATION_ROOT)|g" finch.yaml.temp
47+
sed -i.bak -e "s|<finch_daemon_location>|$(FINCH_DAEMON_LOCATION)|g" finch.yaml.temp
3448

3549
# Replacement was successful, so cleanup .bak
3650
@rm finch.yaml.temp.bak
3751

3852
mv finch.yaml.temp $@
53+
54+
.PHONY: add-daemon-mount
55+
add-daemon-mount:
56+
cd finch.yaml.d && yq eval-all '. as $$item ireduce ({}; . *+ $$item)' $(OS_OUTDIR)/finch.yaml finch-daemon-mount.yaml > ./../finch.yaml.temp
57+
sed -i.bak -e "s|<finch_daemon_root>|$(FINCH_DAEMON_LOCATION_ROOT)|g" finch.yaml.temp
58+
# Replacement was successful, so cleanup .bak
59+
@rm finch.yaml.temp.bak
60+
61+
mv finch.yaml.temp $(OS_OUTDIR)/finch.yaml

e2e/vm/daemon_darwin_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//go:build darwin
5+
6+
package vm
7+
8+
import (
9+
"context"
10+
"path/filepath"
11+
"sync"
12+
"time"
13+
14+
"github.com/docker/docker/api/types/image"
15+
"github.com/docker/docker/client"
16+
"github.com/onsi/ginkgo/v2"
17+
"github.com/onsi/gomega"
18+
"github.com/runfinch/common-tests/option"
19+
)
20+
21+
var testDaemon = func(_ *option.Option, installed bool) {
22+
imageRef := "public.ecr.aws/docker/library/alpine:latest"
23+
ginkgo.Describe("Daemon smoke test", func() {
24+
ginkgo.It("docker client should be able to pull and list images", func(gCtx ginkgo.SpecContext) {
25+
// create a context which is cancelled with the ginkgo test timeout
26+
testCtx, cancelCtx := context.WithCancel(context.Background())
27+
defer cancelCtx()
28+
go func() {
29+
defer cancelCtx()
30+
<-gCtx.Done()
31+
}()
32+
33+
daemonSocketPath := filepath.Join(limaDataDirPath(installed), "finch", "sock", "finch.sock")
34+
apiClient, err := client.NewClientWithOpts(
35+
client.WithHost("unix://"+daemonSocketPath),
36+
client.WithVersion("v1.43"),
37+
)
38+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
39+
defer func() {
40+
gomega.Expect(apiClient.Close()).ShouldNot(gomega.HaveOccurred())
41+
}()
42+
43+
_, err = apiClient.ImagePull(testCtx, imageRef, image.PullOptions{})
44+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
45+
46+
// ImagePull is asynchronous -- poll to check that the image has been pulled every second
47+
imagePulled := false
48+
wg := sync.WaitGroup{}
49+
wg.Add(1)
50+
go func(wg *sync.WaitGroup) {
51+
for {
52+
time.Sleep(1 * time.Second)
53+
images, err := apiClient.ImageList(testCtx, image.ListOptions{})
54+
if err != nil {
55+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
56+
}
57+
for _, img := range images {
58+
for _, tag := range img.RepoTags {
59+
if tag == imageRef {
60+
imagePulled = true
61+
wg.Done()
62+
return
63+
}
64+
}
65+
}
66+
}
67+
}(&wg)
68+
wg.Wait()
69+
70+
gomega.Expect(imagePulled).Should(gomega.BeTrue())
71+
})
72+
})
73+
}

e2e/vm/vm_darwin_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func TestVM(t *testing.T) {
7272
testCredHelper(o, *e2e.Installed, *e2e.Registry)
7373
testSoci(o, *e2e.Installed)
7474
testVMNetwork(o, *e2e.Installed)
75+
testDaemon(o, *e2e.Installed)
7576
testVMDisk(o)
7677
})
7778

finch.yaml.d/common.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ provision:
8989
printf '[Unit]\nDescription=Delete hanging data on boot\nDefaultDependencies=no\nBefore=basic.target\n\n[Service]\nType=oneshot\nExecStart=/bin/bash -c "sudo rm -rf /var/lib/cni/networks/bridge/**; sudo rm -rf /var/lib/cni/results/bridge-finch-*"\n\n[Install]\nWantedBy=basic.target\n' | sudo tee /usr/local/lib/systemd/system/finch-cleanup-on-boot.service
9090
sudo systemctl enable --now finch-cleanup-on-boot.service
9191
92-
sudo systemctl restart containerd.service
92+
sudo systemctl daemon-reload
9393
94+
sudo systemctl restart containerd.service
9495
env:
9596
# Containerd namespace is used by the lima cidata script
9697
# 40-install-containerd.sh. Specifically this variable is defining the

finch.yaml.d/finch-daemon-mount.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mounts:
2+
- location: "<finch_daemon_root>"
3+
writable: true

finch.yaml.d/mac.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ provision:
77
- mode: boot
88
script: |
99
modprobe virtiofs
10+
# port this to common.yaml after windows socket forwarding is added
11+
- mode: user
12+
script: |
13+
sudo cp <finch_daemon_location> /usr/local/bin/finch-daemon
14+
sudo cp <finch_daemon_root>/[email protected] /usr/local/lib/systemd/system/[email protected]
15+
16+
sudo systemctl daemon-reload
17+
sudo systemctl enable --now finch@${UID}
1018
mounts:
1119
- location: "~"
1220
mountPoint: null
@@ -22,9 +30,9 @@ mounts:
2230
cache: "fscache"
2331
- location: "/tmp/lima"
2432
writable: true
25-
- location: "/var/folders"
33+
- location: "/private"
2634
writable: true
27-
- location: "/private/var/folders"
35+
- location: "/var/folders"
2836
writable: true
2937

3038
ssh:
@@ -44,3 +52,7 @@ hostResolver:
4452
hosts:
4553
host.finch.internal: host.lima.internal
4654
host.docker.internal: host.lima.internal
55+
56+
portForwards:
57+
- guestSocket: "/run/finch.sock"
58+
hostSocket: "{{.Dir}}/sock/finch.sock"

[email protected]

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
Description=Finch daemon %I
3+
Documentation=https://runfinch.com https://github.com/runfinch/finch-daemon
4+
After=network.target local-fs.target containerd.service buildkit.service
5+
6+
[Service]
7+
ExecStart=/usr/local/bin/finch-daemon --socket-owner %i
8+
ExecStartPost=-rm -rf /var/run/docker.sock
9+
ExecStartPost=ln -s /run/finch.sock /var/run/docker.sock
10+
Type=notify
11+
Delegate=yes
12+
Restart=always
13+
RestartSec=5
14+
15+
[Install]
16+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)