-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.yml
89 lines (85 loc) · 2.36 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
x-templateappenv: &templateappenv
TEMPLATEAPP: >
package main
import (
"context"
"database/sql"
"embed"
"os"
"os/signal"
"syscall"
_ "REPLACEIMPORT"
"github.com/alexdyukov/dbmigrator"
)
//go:embed *.sql
var embeded embed.FS
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer cancel()
db, err := sql.Open("REPLACEDRIVER", os.Getenv("CONNSTRING"))
if err != nil {
panic(err.Error())
}
if err = dbmigrator.Migrate(ctx, embeded, db, "migrations"); err != nil {
panic(err)
}
}
x-common: &common
image: golang
volumes:
- ./:/fake:ro
services:
postgres_test:
<<: *common
depends_on:
postgres_db:
condition: service_healthy
environment:
<<: *templateappenv
CONNSTRING: postgres://postgres:postgres@postgres_db:5432/postgres?sslmode=disable
entrypoint: >
bash -c 'cp -r /fake/* /go/src/ && \
cd /go/src/ && \
printenv TEMPLATEAPP | sed -e "s|REPLACEDRIVER|pgx|g" -e "s|REPLACEIMPORT|github.com/jackc/pgx/v5/stdlib|g" > ./tests/pgx/main.go && \
go mod tidy && \
go run ./tests/pgx/main.go'
postgres_db:
image: postgres
ports:
- '5432:5432'
healthcheck:
test: [ "CMD", "pg_isready", "-U", "postgres" ]
interval: 10s
timeout: 5s
retries: 5
environment:
POSTGRES_PASSWORD: postgres
mysql_test:
<<: *common
depends_on:
mysql_db:
condition: service_healthy
environment:
<<: *templateappenv
CONNSTRING: mysql:mysql@tcp(mysql_db:3306)/mysql
CGO_ENABLED: 1
entrypoint: >
bash -c 'cp -r /fake/* /go/src/ && \
cd /go/src/ && \
printenv TEMPLATEAPP | sed -e "s|REPLACEDRIVER|mysql|g" -e "s|REPLACEIMPORT|github.com/go-sql-driver/mysql|g" > ./tests/mysql/main.go && \
go mod tidy && \
go run ./tests/mysql/main.go'
mysql_db:
image: mysql
ports:
- '3306:3306'
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
interval: 10s
timeout: 5s
retries: 5
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
MYSQL_DATABASE: mysql