Skip to content

Commit

Permalink
Add docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
gr1m0h committed Nov 19, 2022
1 parent abdde82 commit 25481c2
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# test:
# go test -v -cover -covermode=atmic ./...

docker-build:
docker build -t go-test-server .

docker-run: docker-build
docker-compose up --build -d

docker-stop:
docker-compose down

replace-local-modules:
go mod edit -replace github.com/grimoh/go-test-server/article/delivery/http=./article/delivery/http
go mod edit -replace github.com/grimoh/go-test-server/article/delivery/http/middleware=./article/delivery/http/middleware
Expand Down
3 changes: 2 additions & 1 deletion app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"
"time"

_ "github.com/go-sql-driver/mysql"
"github.com/labstack/echo"
"github.com/spf13/viper"

Expand Down Expand Up @@ -38,7 +39,7 @@ func main() {

val := url.Values{}
val.Add("parseTime", "1")
val.Add("loc", "Asia/Japan")
val.Add("loc", "Local")

dsn := fmt.Sprintf("%s?%s", conn, val.Encode())

Expand Down
17 changes: 17 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"debug": true,
"server": {
"address": ":9090"
},
"context":{
"timeout":2
},
"database": {
"host": "mysql",
"port": "3306",
"user": "user",
"pass": "password",
"name": "article"
}

}
45 changes: 45 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: "3.8"
services:
web:
build:
context: .
dockerfile: Dockerfile
container_name: go-test-server
ports:
- 9090:9090
depends_on:
mysql:
condition: service_healthy
volumes:
- ./config.json:/app/config.json

adminer:
container_name: go-test-adminer
hostname: adminer
image: adminer:4.8.1
restart: always
ports:
- 8080:8080
environment:
ADMINER_DEFAULT_SERVER: go-test-mysql
ADMINER_DESIGN: dracula
depends_on:
mysql:
condition: service_healthy

mysql:
image: mysql:5.7
platform: linux/x86_64
container_name: go-test-mysql
command: mysqld --user=root
ports:
- 3306:3306
environment:
MYSQL_DATABASE: article
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 5s
retries: 10
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/gin-gonic/gin v1.8.1
github.com/go-sql-driver/mysql v1.6.0
golang.org/x/sync v0.1.0
google.golang.org/protobuf v1.28.1
gopkg.in/go-playground/validator.v9 v9.31.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/j
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0=
github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM=
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down

0 comments on commit 25481c2

Please sign in to comment.