diff --git a/.github/workflows/buildandrun-docker.yml b/.github/workflows/buildandrun-docker.yml new file mode 100644 index 0000000..7fc3481 --- /dev/null +++ b/.github/workflows/buildandrun-docker.yml @@ -0,0 +1,15 @@ +name: MySQL 8.0 Build and Run /w docker-compose +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Build and Run Spirit + run: docker compose -f docker/compose.yml -f docker/buildandrun.yml up --abort-on-container-exit diff --git a/.github/workflows/mysql8.0.28-docker.yml b/.github/workflows/mysql8.0.28-docker.yml new file mode 100644 index 0000000..6cecdea --- /dev/null +++ b/.github/workflows/mysql8.0.28-docker.yml @@ -0,0 +1,15 @@ +name: MySQL 8.0.28 (Aurora version) /w docker-compose +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Test + run: docker compose -f docker/compose.yml -f docker/8.0.28.yml -f docker/test.yml up --abort-on-container-exit diff --git a/.github/workflows/mysql8_rbr_minimal_docker.yml b/.github/workflows/mysql8_rbr_minimal_docker.yml new file mode 100644 index 0000000..67da228 --- /dev/null +++ b/.github/workflows/mysql8_rbr_minimal_docker.yml @@ -0,0 +1,15 @@ +name: MySQL 8.0.33 (RBR minimal) /w docker-compose +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Test + run: docker compose -f docker/compose.yml -f docker/8.0.33-rbr-minimal.yml -f docker/test.yml up --abort-on-container-exit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eee6489 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM golang:1.22 + +WORKDIR /app +COPY ../go.mod go.sum ./ +RUN go mod download +COPY .. . \ No newline at end of file diff --git a/buildandrun.sh b/buildandrun.sh new file mode 100755 index 0000000..648bbef --- /dev/null +++ b/buildandrun.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +set -e + +go build ./cmd/spirit +./spirit --host "mysql:3306" --database=test --table=t1 \ No newline at end of file diff --git a/docker/8.0.28.yml b/docker/8.0.28.yml new file mode 100644 index 0000000..ab945e9 --- /dev/null +++ b/docker/8.0.28.yml @@ -0,0 +1,5 @@ +services: + mysql: + image: mysql:8.0.28 + platform: linux/amd64 + ports: [ '8028:3306' ] \ No newline at end of file diff --git a/docker/8.0.33-rbr-minimal.yml b/docker/8.0.33-rbr-minimal.yml new file mode 100644 index 0000000..54416c9 --- /dev/null +++ b/docker/8.0.33-rbr-minimal.yml @@ -0,0 +1,4 @@ +services: + mysql: + ports: [ '8333:3306' ] + command: --binlog-row-image=MINIMAL \ No newline at end of file diff --git a/docker/bootstrap.sql b/docker/bootstrap.sql new file mode 100644 index 0000000..8bc03a1 --- /dev/null +++ b/docker/bootstrap.sql @@ -0,0 +1,18 @@ +use mysql; +set password='msandbox'; + +create role if not exists R_DO_IT_ALL; +grant all on *.* to R_DO_IT_ALL; +create user if not exists msandbox@'%' identified by 'msandbox'; + +grant R_DO_IT_ALL to msandbox@'%' ; +set default role R_DO_IT_ALL to msandbox@'%'; + +create schema if not exists test; + +create table if not exists test.t1 +( + id int not null primary key auto_increment, + b int not null, + c int not null +) \ No newline at end of file diff --git a/docker/buildandrun.yml b/docker/buildandrun.yml new file mode 100644 index 0000000..e889b64 --- /dev/null +++ b/docker/buildandrun.yml @@ -0,0 +1,9 @@ +services: + buildandrun: + build: + context: ../. + dockerfile: Dockerfile + command: ./buildandrun.sh + depends_on: + mysql: + condition: service_healthy \ No newline at end of file diff --git a/docker/compose.yml b/docker/compose.yml new file mode 100644 index 0000000..fbc7b4b --- /dev/null +++ b/docker/compose.yml @@ -0,0 +1,21 @@ +services: + mysql: + image: mysql:8.0.33 + ports: [ '8033:3306' ] + # to supress mbind: Operation not permitted in CI + # https://stackoverflow.com/a/55706057 + cap_add: + - SYS_NICE + environment: + MYSQL_ROOT_PASSWORD: msandbox + MYSQL_USER: msandbox + MYSQL_PASSWORD: msandbox + MYSQL_DATABASE: test + healthcheck: + test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD + start_period: 1s + interval: 1s + timeout: 2s + retries: 60 + volumes: + - ./bootstrap.sql:/docker-entrypoint-initdb.d/bootstrap.sql \ No newline at end of file diff --git a/docker/test.yml b/docker/test.yml new file mode 100644 index 0000000..6d03856 --- /dev/null +++ b/docker/test.yml @@ -0,0 +1,11 @@ +services: + test: + build: + context: ../ + dockerfile: Dockerfile + command: go test -race -v ./... + depends_on: + mysql: + condition: service_healthy + environment: + MYSQL_DSN: msandbox:msandbox@tcp(mysql)/test \ No newline at end of file