mirror of https://github.com/knative/func.git
targeted test (rolling)
This commit is contained in:
parent
ed92075702
commit
652f31008b
|
@ -79,9 +79,25 @@ jobs:
|
|||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y podman
|
||||
|
||||
# Create registries.conf (same as upstream test-integration-podman.sh)
|
||||
# Use absolute path since tests may run from different directories
|
||||
REGISTRIES_CONF_PATH="${{ github.workspace }}/registries.conf"
|
||||
cat <<EOF > "${REGISTRIES_CONF_PATH}"
|
||||
unqualified-search-registries = ["docker.io", "quay.io", "registry.fedoraproject.org", "registry.access.redhat.com"]
|
||||
short-name-mode="permissive"
|
||||
|
||||
[[registry]]
|
||||
location="localhost:50000"
|
||||
insecure=true
|
||||
EOF
|
||||
|
||||
echo "CONTAINERS_REGISTRIES_CONF=${REGISTRIES_CONF_PATH}" >> "$GITHUB_ENV"
|
||||
|
||||
# Start Podman service in background
|
||||
podman system service --time=0 > /dev/null 2>&1 &
|
||||
sleep 2 # Give it time to start
|
||||
|
||||
# Get the socket path and set it for E2E tests
|
||||
PODMAN_SOCKET="$(podman info -f '{{.Host.RemoteSocket.Path}}' 2>/dev/null)"
|
||||
echo "FUNC_E2E_PODMAN=true" >> "$GITHUB_ENV"
|
||||
|
|
|
@ -43,3 +43,10 @@ CLAUDE.md
|
|||
|
||||
# Operating system temporary files
|
||||
.DS_Store
|
||||
|
||||
# TODO: Update this test to be from a temp directory with a hard-coded impl:
|
||||
/pkg/builders/testdata/go-fn-with-private-deps/.s2i
|
||||
|
||||
# TODO: Run this test from a temp directory instead:
|
||||
pkg/oci/testdata/test-links/absoluteLink
|
||||
pkg/oci/testdata/test-links/absoluteLinkWindows
|
||||
|
|
8
Makefile
8
Makefile
|
@ -227,12 +227,8 @@ func-instrumented-bin: # func binary instrumented with coverage reporting
|
|||
|
||||
.PHONY: test-all
|
||||
test-all: func-instrumented-bin ## Run all tests (unit, integration, e2e)
|
||||
@echo "Running unit and integration tests..."
|
||||
go test -tags "integration" -cover -timeout 30m --coverprofile=coverage.txt ./... -v
|
||||
@echo "Running E2E tests..."
|
||||
go test -tags "e2e" -cover -timeout 30m --coverprofile=coverage-e2e.txt ./e2e -v
|
||||
@echo "Merging coverage reports..."
|
||||
@cat coverage-e2e.txt >> coverage.txt && rm coverage-e2e.txt
|
||||
cd e2e && go test -v -tags e2e
|
||||
|
||||
|
||||
######################
|
||||
##@ Release Artifacts
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -190,7 +191,17 @@ var (
|
|||
func init() {
|
||||
fmt.Fprintln(os.Stderr, "Initializing E2E Tests")
|
||||
fmt.Fprintln(os.Stderr, "----------------------")
|
||||
fmt.Fprintln(os.Stderr, "Config Provided:")
|
||||
// Useful for CI debugging:
|
||||
// fmt.Fprintln(os.Stderr, "-- Initial Environment: ")
|
||||
// for _, env := range os.Environ() {
|
||||
// fmt.Println(env)
|
||||
// }
|
||||
fmt.Fprintln(os.Stderr, "-- Preserved Environment: ")
|
||||
fmt.Fprintf(os.Stderr, " HOME=%v\n", os.Getenv("HOME"))
|
||||
fmt.Fprintf(os.Stderr, " PATH=%v\n", os.Getenv("PATH"))
|
||||
fmt.Fprintf(os.Stderr, " XDG_CONFIG_HOME%v\n", os.Getenv("XDG_CONFIG_HOME"))
|
||||
fmt.Fprintf(os.Stderr, " XDG_RUNTIME_DIR%v\n", os.Getenv("XDG_RUNTIME_DIR"))
|
||||
fmt.Fprintln(os.Stderr, "-- Config Provided: ")
|
||||
fmt.Fprintf(os.Stderr, " FUNC_E2E_BIN=%v\n", os.Getenv("FUNC_E2E_BIN"))
|
||||
fmt.Fprintf(os.Stderr, " FUNC_E2E_CLEAN=%v\n", os.Getenv("FUNC_E2E_CLEAN"))
|
||||
fmt.Fprintf(os.Stderr, " FUNC_E2E_DOCKER_HOST=%v\n", os.Getenv("FUNC_E2E_DOCKER_HOST"))
|
||||
|
@ -1385,7 +1396,9 @@ func TestRemote_Dir(t *testing.T) {
|
|||
func TestPodman_Pack(t *testing.T) {
|
||||
name := "func-e2e-test-podman-pack"
|
||||
_ = fromCleanEnv(t, name)
|
||||
setupPodman(t)
|
||||
if err := setupPodman(t); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !Podman {
|
||||
t.Skip("Podman tests not enabled. Enable with FUNC_E2E_PODMAN=true and set FUNC_E2E_PODMAN_HOST to the Podman socket")
|
||||
|
@ -1418,7 +1431,9 @@ func TestPodman_Pack(t *testing.T) {
|
|||
func TestPodman_S2I(t *testing.T) {
|
||||
name := "func-e2e-test-podman-s2i"
|
||||
_ = fromCleanEnv(t, name)
|
||||
setupPodman(t)
|
||||
if err := setupPodman(t); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !Podman {
|
||||
t.Skip("Podman tests not enabled. Enable with FUNC_E2E_TEST_PODMAN=true and set FUNC_E2E_PODMAN_HOST to the Podman socket")
|
||||
|
@ -1762,16 +1777,19 @@ func setupPodmanLinks(t *testing.T) {
|
|||
// run locally outside of CI. Some environment variables, provided via
|
||||
// FUNC_E2E_* or other settings, are explicitly set here.
|
||||
func setupEnv(t *testing.T) {
|
||||
// Keep HOME
|
||||
// Preserve HOME, PATH and some XDG paths, and PATH
|
||||
home := os.Getenv("HOME")
|
||||
path := Tools + ":" + os.Getenv("PATH") // Prepend E2E tools
|
||||
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
|
||||
xdgRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
|
||||
|
||||
// Keep PATH, but prepend the path to the tools installed with
|
||||
path := Tools + ":" + os.Getenv("PATH")
|
||||
|
||||
// Clear everything else
|
||||
os.Clearenv()
|
||||
|
||||
os.Setenv("PATH", path)
|
||||
os.Setenv("HOME", home)
|
||||
os.Setenv("PATH", path)
|
||||
os.Setenv("XDG_CONFIG_HOME", xdgConfigHome)
|
||||
os.Setenv("XDG_RUNTIME_DIR", xdgRuntimeDir)
|
||||
os.Setenv("KUBECONFIG", Kubeconfig)
|
||||
os.Setenv("GOCOVERDIR", Gocoverdir)
|
||||
os.Setenv("FUNC_VERBOSE", fmt.Sprintf("%t", Verbose))
|
||||
|
@ -1800,9 +1818,15 @@ func setupEnv(t *testing.T) {
|
|||
func setupPodman(t *testing.T) error {
|
||||
t.Helper()
|
||||
|
||||
// Podman Socket
|
||||
os.Setenv("DOCKER_HOST", PodmanHost)
|
||||
|
||||
cfg := `
|
||||
// Podman Config
|
||||
// NOTE: the unqualified-search-registries and short-name-mode may be
|
||||
// unnecessary.
|
||||
cfg := `unqualified-search-registries = ["docker.io", "quay.io", "registry.fedoraproject.org", "registry.access.redhat.com"]
|
||||
short-name-mode="permissive"
|
||||
|
||||
[[registry]]
|
||||
location="localhost:50000"
|
||||
insecure=true
|
||||
|
@ -1813,14 +1837,35 @@ insecure=true
|
|||
}
|
||||
os.Setenv("CONTAINERS_REGISTRIES_CONF", cfgPath)
|
||||
|
||||
// Podman Info
|
||||
// May be useful when debugging:
|
||||
// t.Log("podman info:")
|
||||
// infoCmd := exec.Command("podman", "info")
|
||||
// output, err := infoCmd.CombinedOutput()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// t.Logf("%s", output)
|
||||
|
||||
// Done if Linux
|
||||
if runtime.GOOS == "linux" {
|
||||
// Podman machine setup is only needed on macOS/Windows
|
||||
// On Linux, Podman runs natively without a VM
|
||||
t.Log("Running on Linux - Podman machine setup not needed")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Windows and Darwin must run Podman in a VM.
|
||||
// connect the pipes
|
||||
|
||||
// List available machines (debug)
|
||||
t.Log("Available Podman Machines:")
|
||||
listCmd := exec.Command("podman", "machine", "list")
|
||||
output, err := listCmd.CombinedOutput()
|
||||
output, err = listCmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.Logf("output: %s", output)
|
||||
t.Logf("%s", output)
|
||||
|
||||
// Kill any existing process on port 50000 in the Podman VM
|
||||
killCmd := exec.Command("podman", "machine", "ssh", "--",
|
||||
|
@ -1848,8 +1893,8 @@ insecure=true
|
|||
// will be set as well.
|
||||
// arguments set to those provided.
|
||||
func newCmd(t *testing.T, args ...string) *exec.Cmd {
|
||||
t.
|
||||
bin := Bin
|
||||
t.Helper()
|
||||
bin := Bin
|
||||
|
||||
// If Plugin proivided, it is a subcommand so prepend it to args.
|
||||
if Plugin != "" {
|
||||
|
|
|
@ -27,12 +27,20 @@ registry() {
|
|||
|
||||
warn_nix
|
||||
|
||||
# Check the value of CONTAINER_ENGINE
|
||||
# Configure both Docker and Podman if they exist
|
||||
# This supports environments where both are installed
|
||||
echo 'Setting registry as trusted local-only'
|
||||
if [ "$CONTAINER_ENGINE" == "docker" ]; then
|
||||
set_registry_insecure
|
||||
elif [ "$CONTAINER_ENGINE" == "podman" ]; then
|
||||
set_registry_insecure_podman
|
||||
|
||||
# Try to configure Docker if it exists
|
||||
if command -v docker &> /dev/null; then
|
||||
echo "Configuring Docker for insecure registry..."
|
||||
set_registry_insecure || echo "${yellow}Warning: Failed to configure Docker${reset}"
|
||||
fi
|
||||
|
||||
# Try to configure Podman if it exists
|
||||
if command -v podman &> /dev/null; then
|
||||
echo "Configuring Podman for insecure registry..."
|
||||
set_registry_insecure_podman || echo "${yellow}Warning: Failed to configure Podman${reset}"
|
||||
fi
|
||||
|
||||
echo "${green}✅ Registry${reset}"
|
||||
|
@ -40,8 +48,10 @@ registry() {
|
|||
|
||||
warn_nix() {
|
||||
if [[ -x $(command -v "nix") || -x $(command -v "nixos-rebuild") ]]; then
|
||||
if [ "$CONTAINER_ENGINE" == "docker" ]; then
|
||||
echo "${yellow}Warning: Nix detected${reset}"
|
||||
echo "${yellow}Warning: Nix detected${reset}"
|
||||
|
||||
# Warn about Docker if it's installed
|
||||
if command -v docker &> /dev/null; then
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
echo "If Docker Desktop was installed via Nix on macOS, you may need to manually configure the insecure registry."
|
||||
echo "Please confirm \"localhost:50000\" is specified as an insecure registry in the docker config file."
|
||||
|
@ -52,8 +62,10 @@ warn_nix() {
|
|||
echo " daemon.settings.insecure-registries = [ \"localhost:50000\" ];"
|
||||
echo " };"
|
||||
fi
|
||||
elif [ "$CONTAINER_ENGINE" == "podman" ]; then
|
||||
echo "${yellow}Warning: Nix detected${reset}"
|
||||
fi
|
||||
|
||||
# Warn about Podman if it's installed
|
||||
if command -v podman &> /dev/null; then
|
||||
echo "If podman was configured via Nix, this command will likely fail. At time of this writing, podman configured via the nix option 'virtualisation.podman' does not have an option for configuring insecure registries."
|
||||
echo "The configuration required is adding the following to registries.conf:"
|
||||
echo -e " [[registry-insecure-local]]\n location = \"localhost:50000\"\n insecure = true"
|
||||
|
@ -94,12 +106,36 @@ set_registry_insecure() {
|
|||
}
|
||||
|
||||
set_registry_insecure_podman() {
|
||||
FILE="/etc/containers/registries.conf"
|
||||
|
||||
# Check if the section exists
|
||||
if ! sudo grep -q "\[\[registry-insecure-local\]\]" "$FILE"; then
|
||||
# Append the new section to the file
|
||||
echo -e "\n[[registry-insecure-local]]\nlocation = \"localhost:50000\"\ninsecure = true" | sudo tee -a "$FILE" > /dev/null
|
||||
# Handle both rootful and rootless Podman configurations
|
||||
# For rootless, use user's config directory
|
||||
USER_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/containers"
|
||||
SYSTEM_CONFIG_FILE="/etc/containers/registries.conf"
|
||||
|
||||
# Try user config first (rootless)
|
||||
if [ -w "$USER_CONFIG_DIR" ] || mkdir -p "$USER_CONFIG_DIR" 2>/dev/null; then
|
||||
USER_CONFIG_FILE="$USER_CONFIG_DIR/registries.conf"
|
||||
echo "Configuring rootless Podman registry at $USER_CONFIG_FILE"
|
||||
|
||||
# Create the file if it doesn't exist
|
||||
if [ ! -f "$USER_CONFIG_FILE" ]; then
|
||||
echo "" > "$USER_CONFIG_FILE"
|
||||
fi
|
||||
|
||||
# Check if the section exists
|
||||
if ! grep -q "\[\[registry\]\]" "$USER_CONFIG_FILE" || ! grep -A2 "\[\[registry\]\]" "$USER_CONFIG_FILE" | grep -q "location.*localhost:50000"; then
|
||||
# Append the new section to the file
|
||||
echo -e "\n[[registry]]\nlocation = \"localhost:50000\"\ninsecure = true" >> "$USER_CONFIG_FILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Also try system config if we have sudo (rootful)
|
||||
if command -v sudo &> /dev/null && sudo -n true 2>/dev/null; then
|
||||
echo "Configuring system-wide Podman registry at $SYSTEM_CONFIG_FILE"
|
||||
# Check if the section exists
|
||||
if ! sudo grep -q "\[\[registry\]\].*localhost:50000" "$SYSTEM_CONFIG_FILE" 2>/dev/null; then
|
||||
# Append the new section to the file
|
||||
echo -e "\n[[registry]]\nlocation = \"localhost:50000\"\ninsecure = true" | sudo tee -a "$SYSTEM_CONFIG_FILE" > /dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
# On macOS, set up SSH port forwarding so Podman VM can access host's localhost:50000
|
||||
|
|
Loading…
Reference in New Issue