Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MySQL module #943

Merged
merged 14 commits into from
Mar 23, 2023
Merged
12 changes: 6 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ updates:
interval: monthly
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/mysql
schedule:
interval: monthly
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/nginx
schedule:
Expand Down Expand Up @@ -102,6 +96,12 @@ updates:
interval: monthly
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
eddumelendez marked this conversation as resolved.
Show resolved Hide resolved
directory: /modules/mysql
schedule:
interval: monthly
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/postgres
schedule:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Mysql example pipeline
name: MySQL module pipeline

on: [push, pull_request]

concurrency:
group: "${{ github.workflow }}-${{ github.head_ref || github.sha }}"
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
Expand All @@ -24,15 +24,15 @@ jobs:
uses: actions/checkout@v3

- name: modVerify
working-directory: ./examples/mysql
working-directory: ./modules/mysql
run: go mod verify

- name: modTidy
working-directory: ./examples/mysql
working-directory: ./modules/mysql
run: make tools-tidy

- name: gotestsum
working-directory: ./examples/mysql
working-directory: ./modules/mysql
run: make test-unit

- name: Run checker
Expand Down
9 changes: 0 additions & 9 deletions docs/examples/mysql.md

This file was deleted.

68 changes: 68 additions & 0 deletions docs/modules/mysql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# MySQL

## Adding this module to your project dependencies

Please run the following command to add the MySQL module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/mysql
```

## Usage example

<!--codeinclude-->
[Creating a MySQL container](../../modules/mysql/mysql.go)
<!--/codeinclude-->

## Module Reference

The MySQL module exposes one entrypoint function to create the container, and this function receives two parameters:

```golang
func StartContainer(ctx context.Context, opts ...Option) (*MySQLContainer, error) {
```

- `context.Context`, the Go context.
- `Option`, a variad argument for passing options.

## Container Options

When starting the MySQL container, you can pass options in a variadic way to configure it.

!!!tip

You can find all the available configuration and environment variables for the MySQL Docker image on [Docker Hub](https://hub.docker.com/_/mysql).

### Set Image

By default, the image used is `mysql:8`. If you need to use a different image, you can use `WithImage` option.

<!--codeinclude-->
[Custom Image](../../modules/mysql/mysql_test.go) inside_block:withConfigFile
<!--/codeinclude-->

### Set username, password and database name

If you need to set a different database, and its credentials, you can use `WithUsername`, `WithPassword`, `WithDatabase`
options. By default, the username, the password and the database name is `test`.

<!--codeinclude-->
[Custom Database initialization](../../modules/mysql/mysql_test.go) inside_block:customInitialization
<!--/codeinclude-->

### Init Scripts

If you would like to perform DDL or DML operations in the MySQL container, add one or more `*.sql`, `*.sql.gz`, or `*.sh`
scripts to the container request. Those files will be copied under `/docker-entrypoint-initdb.d`.

<!--codeinclude-->
[Include init scripts](../../modules/mysql/mysql_test.go) inside_block:withScripts
<!--/codeinclude-->

### Custom configuration

If you need to set a custom configuration, you can use `WithConfigFile` option.

<!--codeinclude-->
[Custom MySQL config file](../../modules/mysql/mysql_test.go) inside_block:withConfigFile
<!--/codeinclude-->
38 changes: 0 additions & 38 deletions examples/mysql/mysql.go

This file was deleted.

55 changes: 0 additions & 55 deletions examples/mysql/mysql_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ nav:
- modules/index.md
- modules/couchbase.md
- modules/localstack.md
- modules/mysql.md
- modules/postgres.md
- modules/pulsar.md
- modules/vault.md
Expand All @@ -64,7 +65,6 @@ nav:
- examples/datastore.md
- examples/firestore.md
- examples/mongodb.md
- examples/mysql.md
- examples/nginx.md
- examples/pubsub.md
- examples/redis.md
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/mysql/go.mod → modules/mysql/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/testcontainers/testcontainers-go/examples/mysql
module github.com/testcontainers/testcontainers-go/modules/mysql

go 1.19

Expand Down
File renamed without changes.
Loading