diff --git a/docker/serverDockerfile b/docker/serverDockerfile index 5126080c82..1cec69b1dd 100644 --- a/docker/serverDockerfile +++ b/docker/serverDockerfile @@ -11,25 +11,36 @@ RUN apt update -y && \ apt clean && \ rm -rf /var/lib/apt/lists/* -# we install dolt with the install.sh script, which will determine the platform/arch of the container -# and install the proper dolt binary -# Handle "latest" by fetching the actual latest version -RUN if [ "$DOLT_VERSION" = "latest" ]; then \ - LATEST_RELEASE=$(curl -s https://api.github.com/repos/dolthub/dolt/releases/latest) && \ - echo "Latest release data: $LATEST_RELEASE" && \ - DOLT_VERSION=$(echo "$LATEST_RELEASE" | grep '"tag_name"' | cut -d'"' -f4 | sed 's/^v//') && \ - echo "Resolved version: $DOLT_VERSION"; \ +COPY *dolt /tmp/dolt + +# Either build from source or download based on DOLT_VERSION +RUN if [ "$DOLT_VERSION" = "source" ]; then \ + apt update -y && apt install -y golang-1.22 git build-essential && \ + export PATH="/usr/lib/go-1.22/bin:$PATH" && \ + cd /tmp/dolt/go && go build -o /usr/local/bin/dolt ./cmd/dolt && \ + chmod +x /usr/local/bin/dolt; \ else \ - echo "Using specified version: $DOLT_VERSION"; \ + if [ "$DOLT_VERSION" = "latest" ]; then \ + LATEST_RELEASE=$(curl -s https://api.github.com/repos/dolthub/dolt/releases/latest) && \ + echo "Latest release data: $LATEST_RELEASE" && \ + DOLT_VERSION=$(echo "$LATEST_RELEASE" | grep '"tag_name"' | cut -d'"' -f4 | sed 's/^v//') && \ + echo "Resolved version: $DOLT_VERSION"; \ + else \ + echo "Using specified version: $DOLT_VERSION"; \ + fi && \ + curl -L https://github.com/dolthub/dolt/releases/download/v${DOLT_VERSION}/install.sh | bash; \ fi && \ - curl -L https://github.com/dolthub/dolt/releases/download/v${DOLT_VERSION}/install.sh | bash + rm -rf /tmp/dolt + RUN /usr/local/bin/dolt version RUN mkdir /docker-entrypoint-initdb.d RUN mkdir -p /var/lib/dolt VOLUME /var/lib/dolt -COPY docker/docker-entrypoint.sh /usr/local/bin/ +COPY *docker/*docker-entrypoint.sh /usr/local/bin/ +COPY *dolt/*docker/*docker-entrypoint.sh /usr/local/bin/ + RUN chmod +x /usr/local/bin/docker-entrypoint.sh RUN chmod 755 /var/lib/dolt diff --git a/docker/serverREADME.md b/docker/serverREADME.md index 005fc72a93..fc90e0070a 100644 --- a/docker/serverREADME.md +++ b/docker/serverREADME.md @@ -98,6 +98,20 @@ $ docker build -f docker/serverDockerfile --build-arg DOLT_VERSION=1.59.7 -t dol # Note: To run the local build replace `dolthub/dolt-sql-server:latest` with `dolt-sql-server:latest` ``` +## Building from Source + +To build from your local source code instead of downloading a pre-built binary: + +```shell +# Build from local source code (requires workspace directory with source dependencies, e.g., dolt_workspace/) +$ docker build -f dolt/docker/serverDockerfile --build-arg DOLT_VERSION=source -t dolt-sql-server:source . +# Note: This should contain dolt/ at the minimum, any other repos need to be +# added to COPY. + +# Run the source-built image +$ docker run -e DOLT_ROOT_PASSWORD=secret2 -e DOLT_ROOT_HOST=% -p 3307:3306 dolt-sql-server:source +``` + ### Connect to the server in the container from the host system From the host system, to connect to a server running in a container, we need to map a port on the host system to the port our sql-server is running on in the container. diff --git a/integration-tests/bats/docker-entrypoint.bats b/integration-tests/bats/docker-entrypoint.bats index 92cc78d253..c4d93c77d8 100644 --- a/integration-tests/bats/docker-entrypoint.bats +++ b/integration-tests/bats/docker-entrypoint.bats @@ -9,16 +9,21 @@ setup() { setup_no_dolt_init # Compute repo root from integration-tests/bats directory - REPO_ROOT=$(cd "$BATS_TEST_DIRNAME/../.." && pwd) + REPO_ROOT=$(cd "$BATS_TEST_DIRNAME/../../.." && pwd) export REPO_ROOT - # Image and container naming - DOLT_DOCKER_TEST_VERSION=${DOLT_DOCKER_TEST_VERSION:-latest} + # Image and container naming - use source for all tests + DOLT_DOCKER_TEST_VERSION=${DOLT_DOCKER_TEST_VERSION:-source} TEST_IMAGE="dolt-entrypoint-it:${DOLT_DOCKER_TEST_VERSION}" TEST_PREFIX="dolt-entrypoint-it-$$-" - # Ensure image exists (build if missing) - docker build -f "$REPO_ROOT/docker/serverDockerfile" --build-arg DOLT_VERSION=$DOLT_DOCKER_TEST_VERSION -t "$TEST_IMAGE" "$REPO_ROOT" || true + # Build from source only once per test run (check if image already exists) + if ! docker image inspect "$TEST_IMAGE" >/dev/null 2>&1; then + echo "Building Dolt from source for integration tests..." + docker build -f "$REPO_ROOT/doltx``/docker/serverDockerfile" --build-arg DOLT_VERSION=$DOLT_DOCKER_TEST_VERSION -t "$TEST_IMAGE" "$REPO_ROOT" + else + echo "Using existing source-built image: $TEST_IMAGE" + fi # Best-effort cleanup of leftovers from a previous attempt docker ps -a --filter "name=$TEST_PREFIX" --format '{{.Names}}' | xargs -r docker rm -f >/dev/null 2>&1 || true @@ -609,3 +614,37 @@ EOF # Cleanup temp directory rm -rf "$temp_dir" } + +# bats test_tags=no_lambda +@test "docker-entrypoint: CREATE SCHEMA without database name" { # DBeaver creates schemas (databases) without specifying a database name + cname="${TEST_PREFIX}create-schema" + usr="testuser" + pwd="testpass" + + # Run container with custom user but no specific database + run_container_with_port "$cname" 3306 \ + -e DOLT_ROOT_PASSWORD=rootpass \ + -e DOLT_ROOT_HOST=% \ + -e DOLT_USER="$usr" \ + -e DOLT_PASSWORD="$pwd" + + # Test that user can create a schema without specifying a database name (DBeaver style) + run docker exec "$cname" dolt -u "root" -p "rootpass" sql -q "CREATE SCHEMA dbeaver_test;" + [ $status -eq 0 ] + + # Verify the schema was created + run docker exec "$cname" dolt -u "root" -p "rootpass" sql -q "SHOW DATABASES;" + [ $status -eq 0 ] + [[ "$output" =~ "dbeaver_test" ]] || false + + # Test table creation + run docker exec "$cname" dolt -u "root" -p "rootpass" sql -q "USE dbeaver_test; CREATE TABLE test_table (id INT PRIMARY KEY, name VARCHAR(50));" + [ $status -eq 0 ] + + run docker exec "$cname" dolt -u "root" -p "rootpass" sql -q "USE dbeaver_test; INSERT INTO test_table VALUES (1, 'test data');" + [ $status -eq 0 ] + + run docker exec "$cname" dolt -u "root" -p "rootpass" sql -q "USE dbeaver_test; SELECT * FROM test_table;" + [ $status -eq 0 ] + [[ "$output" =~ "test data" ]] || false +}