Skip to content

Commit 20f8f2b

Browse files
committed
Add support for running tests with docker-compose
TODO: 1. Tests with replicas 2. Docs (holding off docs till support is complete) See also: block#187
1 parent 788655a commit 20f8f2b

11 files changed

+124
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: MySQL 8.0 Build and Run /w docker-compose
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Build and Run Spirit
15+
run: docker compose -f docker/compose.yml -f docker/buildandrun.yml up --abort-on-container-exit
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: MySQL 8.0.28 (Aurora version) /w docker-compose
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Test
15+
run: docker compose -f docker/compose.yml -f docker/8.0.28.yml -f docker/test.yml up --abort-on-container-exit
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: MySQL 8.0.33 (RBR minimal) /w docker-compose
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Test
15+
run: docker compose -f docker/compose.yml -f docker/8.0.33-rbr-minimal.yml -f docker/test.yml up --abort-on-container-exit

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM golang:1.22
2+
3+
WORKDIR /app
4+
COPY ../go.mod go.sum ./
5+
RUN go mod download
6+
COPY .. .

buildandrun.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
set -e
3+
4+
go build ./cmd/spirit
5+
./spirit --host "mysql:3306" --database=test --table=t1

docker/8.0.28.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
mysql:
3+
image: mysql:8.0.28
4+
platform: linux/amd64
5+
ports: [ '8028:3306' ]

docker/8.0.33-rbr-minimal.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
mysql:
3+
ports: [ '8333:3306' ]
4+
command: --binlog-row-image=MINIMAL

docker/bootstrap.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use mysql;
2+
set password='msandbox';
3+
4+
create role if not exists R_DO_IT_ALL;
5+
grant all on *.* to R_DO_IT_ALL;
6+
create user if not exists msandbox@'%' identified by 'msandbox';
7+
8+
grant R_DO_IT_ALL to msandbox@'%' ;
9+
set default role R_DO_IT_ALL to msandbox@'%';
10+
11+
create schema if not exists test;
12+
13+
create table if not exists test.t1
14+
(
15+
id int not null primary key auto_increment,
16+
b int not null,
17+
c int not null
18+
)

docker/buildandrun.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
buildandrun:
3+
build:
4+
context: ../.
5+
dockerfile: Dockerfile
6+
command: ./buildandrun.sh
7+
depends_on:
8+
mysql:
9+
condition: service_healthy

docker/compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
mysql:
3+
image: mysql:8.0.33
4+
ports: [ '8033:3306' ]
5+
# to supress mbind: Operation not permitted in CI
6+
# https://stackoverflow.com/a/55706057
7+
cap_add:
8+
- SYS_NICE
9+
environment:
10+
MYSQL_ROOT_PASSWORD: msandbox
11+
MYSQL_USER: msandbox
12+
MYSQL_PASSWORD: msandbox
13+
MYSQL_DATABASE: test
14+
healthcheck:
15+
test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
16+
start_period: 1s
17+
interval: 1s
18+
timeout: 2s
19+
retries: 60
20+
volumes:
21+
- ./bootstrap.sql:/docker-entrypoint-initdb.d/bootstrap.sql

0 commit comments

Comments
 (0)