mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-28 16:58:31 +01:00
Compile only the target server architecture for Core E2E
The same-run E2E producer builds a Linux amd64 image, but the old shared backend step also queued an unused arm64 server compile. Give the test image a target-architecture builder and use the same embedded inputs and linker recipe there and for the normal pair. Keep both shipped downloads, the release-assets dependency, image admission and the browser checks. Change-source: pulse-maintainer Contract-Neutral: The E2E runtime inputs and source/run/image admission, the shipped server pair, signing rules and required CI journeys are unchanged; only the unused E2E cross-compile is removed.
This commit is contained in:
75
Dockerfile
75
Dockerfile
@@ -63,11 +63,11 @@ COPY VERSION ./
|
||||
# Copy the synced embed artifact from the frontend builder stage.
|
||||
COPY --from=frontend-builder /app/internal/api/frontend-modern/dist ./internal/api/frontend-modern/dist
|
||||
|
||||
# Build the main pulse binary for all target architectures
|
||||
RUN --mount=type=cache,id=pulse-go-mod,target=/go/pkg/mod \
|
||||
--mount=type=cache,id=pulse-go-build,target=/root/.cache/go-build \
|
||||
--mount=type=secret,id=pulse_license_public_key,required=false \
|
||||
--mount=type=secret,id=pulse_update_signing_key,required=false \
|
||||
# Both server targets use the same embedded inputs and linker/signing rules.
|
||||
COPY <<'PULSE_BUILD_SERVER' /usr/local/bin/pulse-build-server
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
VERSION="${VERSION:-v$(cat VERSION | tr -d '\n')}" && \
|
||||
BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") && \
|
||||
GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") && \
|
||||
@@ -90,22 +90,45 @@ RUN --mount=type=cache,id=pulse-go-mod,target=/go/pkg/mod \
|
||||
if [ -n "${PULSE_UPDATE_SIGNING_PUBLIC_KEY:-}" ] && [ -z "${UPDATE_PUBLIC_KEYS}" ]; then echo "Error: PULSE_UPDATE_SIGNING_PUBLIC_KEY was provided but no update signing key was mounted." >&2; exit 1; fi && \
|
||||
if [ -n "${PULSE_UPDATE_SIGNING_PUBLIC_KEY:-}" ] && [ "${UPDATE_PUBLIC_KEYS}" != "${PULSE_UPDATE_SIGNING_PUBLIC_KEY}" ]; then echo "Error: mounted update signing key does not match PULSE_UPDATE_SIGNING_PUBLIC_KEY." >&2; echo "Expected public key: ${PULSE_UPDATE_SIGNING_PUBLIC_KEY}" >&2; echo "Actual public key: ${UPDATE_PUBLIC_KEYS}" >&2; exit 1; fi && \
|
||||
SERVER_LDFLAGS="$(./scripts/release_ldflags.sh server --version "${VERSION}" --build-time "${BUILD_TIME}" --git-commit "${GIT_COMMIT}" $(if [ -n "${LICENSE_PUBLIC_KEY}" ]; then printf '%s %s' --license-public-key "${LICENSE_PUBLIC_KEY}"; fi) $(if [ -n "${UPDATE_PUBLIC_KEYS}" ]; then printf '%s %s' --update-public-keys "${UPDATE_PUBLIC_KEYS}"; fi))" && \
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
||||
-tags "${GO_BUILD_TAGS}" \
|
||||
-ldflags="${SERVER_LDFLAGS}" \
|
||||
-buildvcs=false \
|
||||
-trimpath \
|
||||
-o pulse-linux-amd64 ./cmd/pulse && \
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build \
|
||||
-tags "${GO_BUILD_TAGS}" \
|
||||
-ldflags="${SERVER_LDFLAGS}" \
|
||||
-buildvcs=false \
|
||||
-trimpath \
|
||||
-o pulse-linux-arm64 ./cmd/pulse
|
||||
for arch in "$@"; do
|
||||
case "$arch" in
|
||||
amd64|arm64) ;;
|
||||
*) echo "Unsupported Pulse server build architecture: $arch" >&2; exit 1 ;;
|
||||
esac
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH="$arch" go build \
|
||||
-tags "${GO_BUILD_TAGS}" \
|
||||
-ldflags="${SERVER_LDFLAGS}" \
|
||||
-buildvcs=false \
|
||||
-trimpath \
|
||||
-o "pulse-linux-$arch" ./cmd/pulse || exit $?
|
||||
done
|
||||
PULSE_BUILD_SERVER
|
||||
|
||||
# The full runtime carries both server downloads, even in a single-platform
|
||||
# image. Keep the paired build for the regular source-built server paths.
|
||||
FROM backend-builder AS backend-server-pair
|
||||
RUN --mount=type=cache,id=pulse-go-mod,target=/go/pkg/mod \
|
||||
--mount=type=cache,id=pulse-go-build,target=/root/.cache/go-build \
|
||||
--mount=type=secret,id=pulse_license_public_key,required=false \
|
||||
--mount=type=secret,id=pulse_update_signing_key,required=false \
|
||||
sh /usr/local/bin/pulse-build-server amd64 arm64
|
||||
|
||||
# The disposable E2E image never contains the cross-architecture downloads.
|
||||
FROM backend-builder AS backend-e2e-server
|
||||
ARG TARGETARCH
|
||||
RUN --mount=type=cache,id=pulse-go-mod,target=/go/pkg/mod \
|
||||
--mount=type=cache,id=pulse-go-build,target=/root/.cache/go-build \
|
||||
--mount=type=secret,id=pulse_license_public_key,required=false \
|
||||
--mount=type=secret,id=pulse_update_signing_key,required=false \
|
||||
sh /usr/local/bin/pulse-build-server "${TARGETARCH:-amd64}"
|
||||
|
||||
|
||||
FROM backend-builder AS release-assets-builder
|
||||
|
||||
# Bind the installer/agent assembly to the same version and completed
|
||||
# paired-server build as before. This dependency is not on the E2E path.
|
||||
COPY --from=backend-server-pair /app/VERSION ./VERSION
|
||||
|
||||
# Build unified agent binaries for all platforms (for download endpoint)
|
||||
RUN --mount=type=cache,id=pulse-go-mod,target=/go/pkg/mod \
|
||||
--mount=type=cache,id=pulse-go-build,target=/root/.cache/go-build \
|
||||
@@ -322,8 +345,8 @@ ARG TARGETARCH
|
||||
|
||||
# Assign metadata while copying: a later chown/chmod layer carries the large
|
||||
# binary again even though its contents have not changed.
|
||||
COPY --from=backend-builder --chown=pulse:pulse --chmod=0755 /app/pulse-linux-${TARGETARCH:-amd64} ./pulse
|
||||
COPY --from=backend-builder --chown=pulse:pulse /app/VERSION .
|
||||
COPY --from=backend-server-pair --chown=pulse:pulse --chmod=0755 /app/pulse-linux-${TARGETARCH:-amd64} ./pulse
|
||||
COPY --from=backend-server-pair --chown=pulse:pulse /app/VERSION .
|
||||
|
||||
# Exact-candidate runtime base. release_payload is a named BuildKit context
|
||||
# produced from the verified linux-amd64 and linux-arm64 release archives.
|
||||
@@ -341,9 +364,13 @@ FROM pulse-runtime-base AS hosted_runtime
|
||||
|
||||
# Core browser integration tests exercise the running Pulse application and
|
||||
# mock remote update downloads. They do not serve production installer or agent
|
||||
# artifacts, so keep their image on the canonical runtime base instead of
|
||||
# rebuilding the release packet once per Playwright shard.
|
||||
FROM pulse-runtime-base AS e2e_runtime
|
||||
# artifacts, so use the same runtime foundation with just the target server.
|
||||
FROM pulse-runtime-foundation AS e2e_runtime
|
||||
|
||||
ARG TARGETARCH
|
||||
|
||||
COPY --from=backend-e2e-server --chown=pulse:pulse --chmod=0755 /app/pulse-linux-${TARGETARCH:-amd64} ./pulse
|
||||
COPY --from=backend-e2e-server --chown=pulse:pulse /app/VERSION .
|
||||
|
||||
# Final stage (Pulse server runtime)
|
||||
FROM pulse-runtime-base AS runtime
|
||||
@@ -363,8 +390,8 @@ COPY --chown=pulse:pulse --from=release-assets-builder /app/rendered-installers/
|
||||
# Copy all binaries for download endpoint
|
||||
|
||||
# Main pulse server binary (for validation) - copy both architectures
|
||||
COPY --chown=pulse:pulse --from=backend-builder /app/pulse-linux-amd64 /opt/pulse/bin/pulse-linux-amd64
|
||||
COPY --chown=pulse:pulse --from=backend-builder /app/pulse-linux-arm64 /opt/pulse/bin/pulse-linux-arm64
|
||||
COPY --chown=pulse:pulse --from=backend-server-pair /app/pulse-linux-amd64 /opt/pulse/bin/pulse-linux-amd64
|
||||
COPY --chown=pulse:pulse --from=backend-server-pair /app/pulse-linux-arm64 /opt/pulse/bin/pulse-linux-arm64
|
||||
RUN if [ "$TARGETARCH" = "arm64" ]; then \
|
||||
ln -s pulse-linux-arm64 /opt/pulse/bin/pulse; \
|
||||
else \
|
||||
|
||||
@@ -7,6 +7,7 @@ import hashlib
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
@@ -159,24 +160,94 @@ class DownloadConsumerTests(unittest.TestCase):
|
||||
class DockerfileTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
text = (ROOT/'Dockerfile').read_text().replace('\\\n', '')
|
||||
cls.dockerfile = (ROOT/'Dockerfile').read_text()
|
||||
text = cls.dockerfile.replace('\\\n', '')
|
||||
cls.stages = {}
|
||||
cls.parents = {}
|
||||
current = None
|
||||
for line in text.splitlines():
|
||||
if line.startswith('FROM '):
|
||||
current = line.split(' AS ')[1]
|
||||
source, current = line.split(' AS ')
|
||||
cls.parents[current] = source.split()[-1]
|
||||
cls.stages[current] = []
|
||||
elif current and line.strip() and not line.startswith('#'):
|
||||
cls.stages[current].append(line)
|
||||
|
||||
def test_final_server_copies_assign_metadata_before_any_runtime_layer(self):
|
||||
for stage in ['pulse-runtime-base', 'prebuilt-runtime-base']:
|
||||
for stage in ['pulse-runtime-base', 'prebuilt-runtime-base', 'e2e_runtime']:
|
||||
commands = self.stages[stage]
|
||||
pulse = next(c for c in commands if c.startswith('COPY ') and c.endswith(' ./pulse'))
|
||||
self.assertIn('--chown=pulse:pulse', pulse)
|
||||
self.assertIn('--chmod=0755', pulse)
|
||||
self.assertFalse(any(c.startswith('RUN ') for c in commands))
|
||||
|
||||
def run_server_recipe(self, stage, *, target, tags, failing_arch=''):
|
||||
# Execute the Dockerfile's shared shell recipe and actual stage
|
||||
# arguments. Only the compiler and empty secret-mount paths are
|
||||
# doubled; no host secrets or Docker daemon are read.
|
||||
start = "COPY <<'PULSE_BUILD_SERVER' /usr/local/bin/pulse-build-server\n"
|
||||
recipe = self.dockerfile.split(start, 1)[1].split('\nPULSE_BUILD_SERVER\n', 1)[0]
|
||||
call = next(line.split('sh /usr/local/bin/pulse-build-server', 1)[1]
|
||||
for line in self.stages[stage] if 'sh /usr/local/bin/pulse-build-server' in line)
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
script = root/'compile.sh'
|
||||
script.write_text(recipe.replace('/run/secrets/', str(root/'empty')+'/'))
|
||||
(root/'scripts').mkdir()
|
||||
(root/'scripts'/'release_ldflags.sh').symlink_to(ROOT/'scripts'/'release_ldflags.sh')
|
||||
(root/'VERSION').write_text('1.2.3\n')
|
||||
compiler = root/'go'
|
||||
compiler.write_text(
|
||||
"#!/bin/sh\n"
|
||||
"printf '<%s>' \"$GOOS/$GOARCH/$CGO_ENABLED\" \"$@\"\n"
|
||||
"printf '\\n'\n"
|
||||
"if [ \"$GOARCH\" = \"$FAIL_ARCH\" ]; then exit 19; fi\n"
|
||||
)
|
||||
compiler.chmod(0o755)
|
||||
result = subprocess.run(
|
||||
['sh', '-c', 'sh "$1"'+call, 'stage', str(script)], cwd=root,
|
||||
env={'PATH': str(root)+os.pathsep+os.defpath, 'TARGETARCH': target,
|
||||
'GO_BUILD_TAGS': tags, 'FAIL_ARCH': failing_arch},
|
||||
text=True, capture_output=True, check=False,
|
||||
)
|
||||
return result
|
||||
|
||||
def test_e2e_compiles_only_the_architecture_its_image_consumes(self):
|
||||
self.assertEqual(self.parents['backend-e2e-server'], 'backend-builder')
|
||||
self.assertEqual(self.parents['e2e_runtime'], 'pulse-runtime-foundation')
|
||||
for stage in ['backend-e2e-server', 'e2e_runtime']:
|
||||
self.assertIn('ARG TARGETARCH', self.stages[stage])
|
||||
self.assertIn('COPY --from=backend-e2e-server --chown=pulse:pulse --chmod=0755 '
|
||||
'/app/pulse-linux-${TARGETARCH:-amd64} ./pulse', self.stages['e2e_runtime'])
|
||||
for arch in ('amd64', 'arm64'):
|
||||
with self.subTest(arch=arch):
|
||||
result = self.run_server_recipe('backend-e2e-server', target=arch, tags='')
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(len(result.stdout.splitlines()), 1)
|
||||
self.assertIn(f'<linux/{arch}/0><build><-tags><>', result.stdout)
|
||||
self.assertIn(f'<-buildvcs=false><-trimpath><-o><pulse-linux-{arch}><./cmd/pulse>', result.stdout)
|
||||
|
||||
def test_regular_runtime_still_compiles_and_consumes_both_downloads(self):
|
||||
self.assertEqual(self.parents['runtime'], 'pulse-runtime-base')
|
||||
self.assertEqual(self.parents['hosted_runtime'], 'pulse-runtime-base')
|
||||
self.assertIn('COPY --from=backend-server-pair /app/VERSION ./VERSION',
|
||||
self.stages['release-assets-builder'])
|
||||
result = self.run_server_recipe('backend-server-pair', target='arm64', tags='release')
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
for arch, command in zip(('amd64', 'arm64'), result.stdout.splitlines(), strict=True):
|
||||
self.assertIn(f'<linux/{arch}/0><build><-tags><release>', command)
|
||||
self.assertIn(f'<-buildvcs=false><-trimpath><-o><pulse-linux-{arch}><./cmd/pulse>', command)
|
||||
self.assertIn(f'COPY --chown=pulse:pulse --from=backend-server-pair '
|
||||
f'/app/pulse-linux-{arch} /opt/pulse/bin/pulse-linux-{arch}', self.stages['runtime'])
|
||||
self.assertIn('COPY --from=backend-server-pair --chown=pulse:pulse --chmod=0755 '
|
||||
'/app/pulse-linux-${TARGETARCH:-amd64} ./pulse', self.stages['pulse-runtime-base'])
|
||||
|
||||
def test_e2e_compile_failure_is_not_retried_or_hidden(self):
|
||||
result = self.run_server_recipe('backend-e2e-server', target='arm64', tags='', failing_arch='arm64')
|
||||
self.assertEqual(result.returncode, 19, result.stderr)
|
||||
self.assertEqual(len(result.stdout.splitlines()), 1)
|
||||
self.assertIn('<linux/arm64/0><build>', result.stdout)
|
||||
|
||||
def test_all_source_payload_copies_have_final_ownership_not_recursive_copyup(self):
|
||||
commands = self.stages['runtime']
|
||||
for copy in (c for c in commands if c.startswith('COPY ')):
|
||||
|
||||
Reference in New Issue
Block a user