Skip to content

Commit

Permalink
Add support for running tests with docker-compose
Browse files Browse the repository at this point in the history
TODO:
1. Tests with replicas
2. Docs (holding off docs till support is complete)

See also: cashapp#187
  • Loading branch information
sahilm committed Jun 24, 2024
1 parent 788655a commit f2ef314
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/buildandrun-docker.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions .github/workflows/mysql8.0.28-docker.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions .github/workflows/mysql8_rbr_minimal_docker.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang:1.22

WORKDIR /app
COPY ../go.mod go.sum ./
RUN go mod download
COPY .. .
5 changes: 5 additions & 0 deletions buildandrun.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
set -e

go build ./cmd/spirit
./spirit --host "mysql:3306" --database=test --table=t1
5 changes: 5 additions & 0 deletions docker/8.0.28.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
mysql:
image: mysql:8.0.28
platform: linux/amd64
ports: [ '8028:3306' ]
4 changes: 4 additions & 0 deletions docker/8.0.33-rbr-minimal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
mysql:
ports: [ '8333:3306' ]
command: --binlog-row-image=MINIMAL
18 changes: 18 additions & 0 deletions docker/bootstrap.sql
Original file line number Diff line number Diff line change
@@ -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
)
9 changes: 9 additions & 0 deletions docker/buildandrun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
buildandrun:
build:
context: ../.
dockerfile: Dockerfile
command: ./buildandrun.sh
depends_on:
mysql:
condition: service_healthy
21 changes: 21 additions & 0 deletions docker/compose.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions docker/test.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f2ef314

Please sign in to comment.