-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.test
More file actions
109 lines (91 loc) · 4.39 KB
/
Copy pathDockerfile.test
File metadata and controls
109 lines (91 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# =============================================================================
# Dockerfile.test -- Multi-stage build for running the full pg-migration-lint
# test suite, including Liquibase bridge JAR support and golden file tests.
#
# Stage 1: Build the Liquibase bridge fat JAR (Maven + JDK 21), generate
# golden files, and run Java tests.
# Stage 2: Build and test the Rust project with the JAR available, including
# feature-gated bridge integration tests.
#
# Usage:
# docker build -f Dockerfile.test -t pg-migration-lint-test .
# docker run --rm pg-migration-lint-test
#
# To generate/update golden files and snapshots:
# make bridge-generate
#
# To verify all tests pass:
# make bridge-verify
# =============================================================================
# ---------------------------------------------------------------------------
# Stage 1: Build the Liquibase bridge JAR and run Java tests
# ---------------------------------------------------------------------------
FROM maven:3.9-eclipse-temurin-21 AS bridge-build
WORKDIR /build/bridge
# Copy POM first for dependency caching
COPY bridge/pom.xml .
RUN mvn dependency:go-offline -q
# Copy Java sources and build the shaded (fat) JAR — skip tests for now
# because the full-changelog golden file hasn't been generated yet.
COPY bridge/src/ src/
RUN mvn package -q -DskipTests
# Verify the JAR was produced
RUN test -f target/liquibase-bridge-1.0.0.jar
# Copy test fixtures so the bridge can process the full changelog
COPY tests/fixtures/ /build/tests/fixtures/
# Generate the full-changelog golden file from the bridge JAR output.
# This is used by both Java golden file tests and as a reference artifact.
RUN java -jar target/liquibase-bridge-1.0.0.jar \
--changelog /build/tests/fixtures/repos/liquibase-xml/changelog/master.xml \
> src/test/resources/fixtures/full-changelog.expected.json
# Now run Java tests — the golden file test can validate against the
# generated file.
RUN mvn test
# ---------------------------------------------------------------------------
# Stage 2: Rust build, test, and lint (including bridge integration tests)
# ---------------------------------------------------------------------------
FROM rust:1.93-bookworm AS rust-test
# Install system dependencies required by pg_query crate (bindgen needs
# libclang) and general Rust build tooling.
RUN rustup component add clippy && \
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libclang-dev \
clang \
pkg-config \
libssl-dev \
wget \
# JRE needed at test time so the bridge loader can shell out to `java`
default-jre-headless \
&& rm -rf /var/lib/apt/lists/*
# Install Liquibase CLI (pinned version) for update-sql E2E tests
ARG LIQUIBASE_VERSION=5.0.1
RUN wget -q -O /tmp/liquibase.tar.gz \
"https://github.com/liquibase/liquibase/releases/download/v${LIQUIBASE_VERSION}/liquibase-${LIQUIBASE_VERSION}.tar.gz" && \
mkdir -p /opt/liquibase && \
tar -xzf /tmp/liquibase.tar.gz -C /opt/liquibase && \
ln -s /opt/liquibase/liquibase /usr/local/bin/liquibase && \
rm /tmp/liquibase.tar.gz
WORKDIR /app
# -- Layer 1: Cache Rust dependencies --
# Copy only the manifests and create a dummy lib/main so cargo can fetch deps.
COPY Cargo.toml Cargo.lock ./
# Create minimal stub sources so `cargo fetch` resolves all dependencies.
# These will be overwritten in the next COPY, but the dependency layer is cached.
RUN mkdir -p src && \
echo 'pub fn _stub() {}' > src/lib.rs && \
echo 'fn main() {}' > src/main.rs && \
cargo fetch
# -- Layer 2: Copy the bridge JAR and golden file --
COPY --from=bridge-build /build/bridge/target/liquibase-bridge-1.0.0.jar bridge/target/liquibase-bridge-1.0.0.jar
COPY --from=bridge-build /build/bridge/src/test/resources/fixtures/full-changelog.expected.json bridge/src/test/resources/fixtures/full-changelog.expected.json
# -- Layer 3: Copy the full Rust project source --
COPY src/ src/
COPY tests/ tests/
# -- Layer 4: Build (compile check) including bridge-tests feature --
RUN cargo build --tests --features bridge-tests 2>&1
# -- Layer 5: Run all tests and clippy --
# Snapshots are already committed in the repo and copied via COPY tests/ above,
# so we run in verify mode (no INSTA_UPDATE).
ENV PG_LINT_LIQUIBASE_PATH=/usr/local/bin/liquibase
CMD ["sh", "-c", "cargo test --features bridge-tests && cargo clippy -- -D warnings"]