Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/actions/orm-tests/action.yaml

This file was deleted.

29 changes: 23 additions & 6 deletions .github/workflows/ci-orm-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
name: Test ORM integrations

on:
pull_request:
paths:
- 'go/**'
- 'integration-tests/**'
workflow_dispatch:
repository_dispatch:
types: [ test-orm-integrations ]

concurrency:
group: ci-orm-tests-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
orm_integrations_job:
runs-on: ubuntu-22.04
timeout-minutes: 30
name: Run tests
name: ORM tests
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Copy go package
run: cp -r ./go ./integration-tests/go
with:
path: dolt
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build ORM test image
uses: docker/build-push-action@v6
with:
context: .
file: dolt/integration-tests/orm-tests/Dockerfile
tags: orm-tests:latest
load: true
- name: Test ORM integrations
uses: ./.github/actions/orm-tests
run: docker run --rm orm-tests:latest
- name: Configure AWS Credentials
if: ${{ failure() }}
if: ${{ failure() && !env.ACT }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Send Email
if: ${{ failure() }}
if: ${{ failure() && !env.ACT }}
uses: ./.github/actions/ses-email-action
with:
template: 'OrmIntegrationFailureTemplate'
Expand Down
64 changes: 0 additions & 64 deletions integration-tests/ORMDockerfile

This file was deleted.

68 changes: 68 additions & 0 deletions integration-tests/orm-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# syntax=docker/dockerfile:1
FROM golang:1.25-alpine AS golang_cgo125
ENV CGO_ENABLED=1
ENV GO_LDFLAGS="-linkmode external -extldflags '-static'"
RUN apk add --no-cache build-base

FROM golang_cgo125 AS dolt_build
RUN apk add --no-cache icu-dev icu-static
#COPY go-mysql-server /build/go-mysql-server
COPY dolt/go/go.mod /build/dolt/go/
WORKDIR /build/dolt/go/
RUN go mod download
COPY dolt/go/ /build/dolt/go/
RUN go build -tags icu_static -ldflags "$GO_LDFLAGS" -o /build/bin/dolt ./cmd/dolt

FROM --platform=${BUILDPLATFORM} ubuntu:20.04 AS runtime

# install ORM tools and dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update -y && \
apt install -y \
ca-certificates \
curl \
gnupg \
software-properties-common && \
curl -sL https://deb.nodesource.com/setup_22.x | bash -
RUN apt update -y && \
apt install -y \
nodejs \
python3.9 \
python3-pip \
git \
mysql-client \
libmysqlclient-dev \
netcat-openbsd \
# weird issue: installing openjdk-17-jdk errors if `maven` or possibly any other package is not installed after it
openjdk-17-jdk \
# currently, `apt install maven` installs v3.6.0 which does not work with openjdk-17-jdk
maven && \
update-ca-certificates -f

RUN git clone --depth 1 --branch v1.13.0 https://github.com/bats-core/bats-core.git /tmp/bats-core && \
/tmp/bats-core/install.sh /usr/local && \
rm -rf /tmp/bats-core

# install mysql connector and pymsql
RUN pip3 install mysql-connector-python PyMySQL sqlalchemy

# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/

# install the current latest maven version, `v3.9.11`, because apt installed one does not work with jdk 17
ADD https://archive.apache.org/dist/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz apache-maven-3.9.11-bin.tar.gz
RUN tar zxvf apache-maven-3.9.11-bin.tar.gz && \
cp -r apache-maven-3.9.11 /opt && \
rm -rf apache-maven-3.9.11 apache-maven-3.9.11-bin.tar.gz

# add maven binary
ENV PATH=/opt/apache-maven-3.9.11/bin:$PATH

COPY --from=dolt_build /build/bin/dolt /usr/local/bin/dolt
COPY dolt/integration-tests/orm-tests /orm-tests
COPY dolt/integration-tests/bats/helper /orm-tests/helper
COPY dolt/integration-tests/orm-tests/orm-tests-entrypoint.sh /orm-tests/entrypoint.sh
RUN chmod +x /orm-tests/entrypoint.sh

WORKDIR /orm-tests
ENTRYPOINT ["/orm-tests/entrypoint.sh"]
27 changes: 8 additions & 19 deletions integration-tests/orm-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,19 @@ These tests verify that various ORM libraries that support MySQL are compatible
we use the same test suite that the ORM provides to test their support with MySQL, but in some
cases we may start with a smaller smoke test to get some quick, initial coverage.

These tests can be run locally using Docker. Before you can build the image, you also need to copy the go folder
into the integration-tests folder; unfortunately just symlinking doesn't seem to work. From the
integration-tests directory of the dolt repo, run:
These tests can be run locally using Docker from the root of the workspace directory that contains `dolt/`:

```bash
$ cp -r ../go .
$ docker build -t orm-tests -f ORMDockerfile .
$ docker build -t orm-tests -f dolt/integration-tests/orm-tests/Dockerfile .
$ docker run orm-tests:latest
```

Running the container should produce output like:
The `dolt` binary is built in a separate stage from the ORM test runtime. This speeds up first-time image builds with parallel stage building. Secondly, ORM-only changes will reuse the cached binary from the `dolt_build` stage.

```bash
Updating dolt config for tests:
Config successfully updated.
Config successfully updated.
Config successfully updated.
Config successfully updated.
Running orm-tests:
1..1
not ok 1 peewee client test
You can also build other Dolt related dependencies from a local source into the Docker `dolt` binary. Copy the required source into the `dolt_build` stage's `build/` directory in the `orm-tests/Dockerfile`. The one caveat is that your repository must be placed in the same parent directory as `dolt`.
```dockerfile
COPY go-mysql-server /build/go-mysql-server
```
The line above has been commented out in the actual Dockerfile so you know the correct placement. You are responsible for updating `go.mod` with the `replace` directive in your local `dolt/` directory.

### Future ORM Libraries to Test
- typeorm
- mikro-orm
- hibernate
To stop the build at a specific stage use [`--target <stage_name>`](https://docs.docker.com/build/building/multi-stage/#stop-at-a-specific-build-stage) option. You can then run the build as a normal image afterward, but it'll run within the target stage. Alternatively, use GoLand's bundled Docker plugin. You may have to add `*Dockerfile` as a pattern in your [File Types](https://www.jetbrains.com/help/go/creating-and-registering-file-types.html#register-new-association) settings.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ public class Util {

static{
try{
sessionFactory = new Configuration().configure().buildSessionFactory();
Configuration config = new Configuration();

config.setProperty("hibernate.connection.url", "jdbc:" + System.getenv("DB_URL"));
config.setProperty("hibernate.connection.username", System.getenv("DB_USER"));
config.setProperty("hibernate.connection.password", System.getenv("DB_PASSWORD"));

sessionFactory = config.configure().buildSessionFactory();
}catch (Throwable ex) {
System.err.println("Session Factory could not be created." + ex);
throw new ExceptionInInitializerError(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">dolt</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dolt</property>
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="show_sql">true</property>
<property name="format_sql">false</property>
<mapping class="com.dolt.hibernate.model.Student"/>
Expand Down
7 changes: 3 additions & 4 deletions integration-tests/orm-tests/mikro-orm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { MySqlDriver } from '@mikro-orm/mysql';
import { User } from "./entity/User";

async function connectAndGetOrm() {
const dbUrl = process.env.DB_URL ?? 'mysql://root@localhost:3306/dolt';

const orm = await MikroORM.init<MySqlDriver>({
entities: [User],
type: "mysql",
clientUrl: "mysql://localhost:3306",
dbName: "dolt",
user: "dolt",
password: "",
clientUrl: dbUrl,
persistOnCreate: true,
});

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/orm-tests/orm-tests-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ dolt config --global --add user.name orm-test-runner
dolt config --global --add user.email orm-test-runner@liquidata.co

echo "Running orm-tests:"
bats /orm-tests/orm-tests.bats
bats /orm-tests/orm-tests.bats --print-output-on-failure
Loading
Loading