Skip to content

Commit fbf5fb8

Browse files
committed
test(docker): install an add-on and a backend in each container user setup
A container that starts cleanly can still be unable to install anything: in #13507 the signature check of every add-on failed because the user LocalAI ran as could not write its home folder. No test booted the image as that user. Add tests/e2e-container-users, which starts the image with testcontainers in five setups: the default, LOCALAI_UID and LOCALAI_GID, docker --user with named volumes, bind mounts owned by the user of the test, and a read-only root with a tmpfs /tmp. In each setup it waits for /readyz, checks the uid LocalAI runs as, checks that the warning about unwritable folders is logged only where it is expected, and installs the signed add-on talk and the backend local-store from the official libraries. A setup whose installs must fail must name the reason. Network errors are tried once more; any other failure fails the setup. The workflow builds the CPU image from the commit with the build arguments and the registry cache of image_build.yml, then runs the setups one after another. It runs nightly, on demand (optionally on a published image), and on pull requests and master pushes that touch the entrypoint, the Dockerfile, the signature check, the add-on service, the gallery or pkg/system. Assisted-by: Claude:claude-sonnet-5-5 go testcontainers Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 9333361 commit fbf5fb8

4 files changed

Lines changed: 670 additions & 0 deletions

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
# Boots the CPU container image, built from the commit under test, in the user
3+
# setups people run it with (default, LOCALAI_UID, docker --user, bind mounts
4+
# of the host user, read-only root) and checks in each one that LocalAI starts,
5+
# logs the folders it cannot write, and installs a signed add-on and a backend
6+
# from the official libraries. This catches a container that starts cleanly
7+
# but cannot install anything, as in #13507.
8+
#
9+
# The image is built here with the same build arguments and the same registry
10+
# cache as the CPU image of image_build.yml, so an unchanged base costs only
11+
# the Go build. Set the `image` input of a manual run to test a published image
12+
# instead (for example quay.io/go-skynet/local-ai:master).
13+
#
14+
# Concurrency: see .agents/ci-caching.md, section "Concurrency".
15+
name: 'tests-container-users'
16+
17+
on:
18+
schedule:
19+
- cron: '30 3 * * *'
20+
workflow_dispatch:
21+
inputs:
22+
image:
23+
description: 'Published image to test instead of building one (empty: build from this commit)'
24+
required: false
25+
default: ''
26+
type: string
27+
pull_request:
28+
paths:
29+
- 'entrypoint.sh'
30+
- 'Dockerfile*'
31+
- 'pkg/oci/cosignverify/**'
32+
- 'pkg/system/**'
33+
- 'core/services/addons/**'
34+
- 'core/gallery/**'
35+
- 'tests/e2e-container-users/**'
36+
- '.github/workflows/tests-container-users.yml'
37+
push:
38+
branches:
39+
- master
40+
paths:
41+
- 'entrypoint.sh'
42+
- 'Dockerfile*'
43+
- 'pkg/oci/cosignverify/**'
44+
- 'pkg/system/**'
45+
- 'core/services/addons/**'
46+
- 'core/gallery/**'
47+
- 'tests/e2e-container-users/**'
48+
- '.github/workflows/tests-container-users.yml'
49+
50+
concurrency:
51+
group: ci-tests-container-users-${{ github.event.pull_request.number || (github.event_name == 'push' && github.ref) || github.sha }}-${{ github.repository }}
52+
cancel-in-progress: ${{ github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/master') }}
53+
54+
permissions:
55+
contents: read
56+
57+
jobs:
58+
container-users:
59+
runs-on: ubuntu-latest
60+
timeout-minutes: 90
61+
env:
62+
LOCALAI_USERMODES_LOG_DIR: ${{ github.workspace }}/container-users-logs
63+
steps:
64+
- name: Clone
65+
uses: actions/checkout@v7
66+
67+
- name: Configure apt mirror on runner
68+
id: apt_mirror
69+
if: inputs.image == ''
70+
uses: ./.github/actions/configure-apt-mirror
71+
72+
- name: Free disk space
73+
if: inputs.image == ''
74+
uses: ./.github/actions/free-disk-space
75+
with:
76+
mode: hosted
77+
78+
- name: Set up build disk
79+
if: inputs.image == ''
80+
uses: ./.github/actions/setup-build-disk
81+
82+
- name: Set up Docker Buildx
83+
if: inputs.image == ''
84+
uses: docker/setup-buildx-action@master
85+
86+
# The build arguments and the cache match the CPU image of
87+
# image_build.yml, so the cache that the master builds write is reused.
88+
- name: Build the CPU image
89+
if: inputs.image == ''
90+
uses: docker/build-push-action@v7
91+
with:
92+
context: .
93+
file: ./Dockerfile
94+
build-args: |
95+
BUILD_TYPE=
96+
CUDA_MAJOR_VERSION=
97+
CUDA_MINOR_VERSION=
98+
BASE_IMAGE=ubuntu:24.04
99+
MAKEFLAGS=--jobs=4 --output-sync=target
100+
SKIP_DRIVERS=false
101+
UBUNTU_VERSION=2404
102+
UBUNTU_CODENAME=noble
103+
APT_MIRROR=${{ steps.apt_mirror.outputs.effective-mirror }}
104+
APT_PORTS_MIRROR=${{ steps.apt_mirror.outputs.effective-ports-mirror }}
105+
cache-from: type=registry,ref=quay.io/go-skynet/ci-cache:cache-localai-amd64
106+
platforms: linux/amd64
107+
load: true
108+
tags: local-ai:container-users
109+
110+
- name: Pull the published image
111+
if: inputs.image != ''
112+
env:
113+
IMAGE: ${{ inputs.image }}
114+
run: docker pull "$IMAGE"
115+
116+
- name: Set up Go
117+
uses: actions/setup-go@v6
118+
with:
119+
go-version-file: go.mod
120+
cache: false
121+
122+
- name: Test
123+
env:
124+
LOCALAI_IMAGE: ${{ inputs.image != '' && inputs.image || 'local-ai:container-users' }}
125+
run: |
126+
id
127+
make test-e2e-container-users
128+
129+
- name: Upload the container logs
130+
if: always()
131+
uses: actions/upload-artifact@v7
132+
with:
133+
name: container-users-logs
134+
path: ${{ env.LOCALAI_USERMODES_LOG_DIR }}
135+
if-no-files-found: ignore
136+
retention-days: 7

‎Makefile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,17 @@ run-e2e-aio: protogen-go
395395
@echo 'Running e2e AIO tests'
396396
$(GOCMD) run github.com/onsi/ginkgo/v2/ginkgo --flake-attempts $(TEST_FLAKES) -v -r ./tests/e2e-aio
397397

398+
## Boots the container image LOCALAI_IMAGE (name:tag) in each user setup of
399+
## tests/e2e-container-users and installs a signed add-on and a backend in
400+
## each one. Needs Docker and network access to the official registries. Pick
401+
## setups with CONTAINER_USERS_LABELS, for example read-only-root.
402+
## No flake attempts: a failure must show, and the suite retries network
403+
## errors only.
404+
CONTAINER_USERS_LABELS?=
405+
.PHONY: test-e2e-container-users
406+
test-e2e-container-users:
407+
$(GOCMD) run github.com/onsi/ginkgo/v2/ginkgo -v --timeout 80m $(if $(CONTAINER_USERS_LABELS),--label-filter='$(CONTAINER_USERS_LABELS)') ./tests/e2e-container-users
408+
398409
# Distributed architecture e2e (PostgreSQL + NATS via testcontainers).
399410
# Includes NatsJWT specs (JWT-enabled NATS). Requires Docker.
400411
# VLLMMultinode is excluded here; use test-e2e-vllm-multinode for that.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Package e2econtainerusers boots the real container image under the user
2+
// setups that people run it with, and checks in each one that LocalAI starts,
3+
// reports the folders it cannot write, and can install a signed add-on and a
4+
// backend from the official libraries.
5+
//
6+
// It needs Docker and network access to the official registries. Set
7+
// LOCALAI_IMAGE to the image to test (for example local-ai:usermodes).
8+
package e2econtainerusers_test
9+
10+
import (
11+
"os"
12+
"testing"
13+
14+
. "github.com/onsi/ginkgo/v2"
15+
. "github.com/onsi/gomega"
16+
)
17+
18+
var (
19+
// image is the container image under test, as name:tag.
20+
image = os.Getenv("LOCALAI_IMAGE")
21+
// logDir, when set, receives the full log of each container.
22+
logDir = os.Getenv("LOCALAI_USERMODES_LOG_DIR")
23+
)
24+
25+
func TestContainerUsers(t *testing.T) {
26+
RegisterFailHandler(Fail)
27+
RunSpecs(t, "LocalAI container user setups")
28+
}
29+
30+
var _ = BeforeSuite(func() {
31+
Expect(image).NotTo(BeEmpty(), "set LOCALAI_IMAGE to the image to test")
32+
if logDir != "" {
33+
Expect(os.MkdirAll(logDir, 0o755)).To(Succeed())
34+
}
35+
})

0 commit comments

Comments
 (0)