Created
April 25, 2019 11:20
-
-
Save wayneashleyberry/bd3ed716ff7dfdb8229aa3252ec258f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.6' | |
services: | |
database: | |
restart: always | |
image: mysql:5.6 | |
ports: | |
- "3306:3306" | |
environment: | |
- MYSQL_ROOT_PASSWORD=123456 | |
- MYSQL_USER=test | |
- MYSQL_PASSWORD=test | |
- MYSQL_DATABASE=test | |
app: | |
build: . | |
restart: always | |
depends_on: | |
- database | |
volumes: | |
- .:/code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang | |
COPY . /code | |
ENV GO111MODULE on | |
WORKDIR /code | |
RUN ["go", "run", "-mod=vendor", "main.go"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"time" | |
"github.com/go-sql-driver/mysql" | |
"github.com/jmoiron/sqlx" | |
) | |
func main() { | |
conf := mysql.NewConfig() | |
conf.User = "root" | |
conf.Passwd = "123456" | |
conf.Addr = "database:3306" | |
conf.DBName = "test" | |
conf.Net = "tcp" | |
dsn := conf.FormatDSN() | |
for i := 0; i <= 60; i++ { | |
_, err := sqlx.Connect("mysql", dsn) | |
if err == nil { | |
os.Exit(0) | |
} | |
fmt.Println(err) | |
time.Sleep(1 * time.Second) | |
} | |
os.Exit(1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment