Skip to content

Commit

Permalink
dockerised app now runs with mysql db
Browse files Browse the repository at this point in the history
  • Loading branch information
kamsandhu93 committed May 31, 2023
1 parent d8ade42 commit 1e50293
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18-buster as builder
FROM golang:1.20-buster as builder

WORKDIR /app

Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
SHELL := $(shell which bash)
DOC_COM := docker compose --project-name gqldenring

generate:
go generate ./...

run:
go run server.go

run-db:
SQL_CONN="root:qwerty@tcp(0.0.0.0:3306)/db" go run server.go

fmt:
goimports -w .

Expand All @@ -16,13 +20,16 @@ tidy:
go mod tidy

up:
docker compose --project-name gqldenring up -d --build
$(DOC_COM) up -d --build --wait

up-db:
$(DOC_COM) up -d --wait db phpmyadmin

down:
docker compose down
$(DOC_COM) down --remove-orphans

logs:
docker compose logs -f
$(DOC_COM) logs -f

lint:
PWD=$(pwd) docker run -t --rm -v ${PWD}:/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run -v
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
- "internal"
environment:
PORT: "8080"
SQL_CONN: "root:qwerty@tcp(db:3306)/db"

db:
image: "mysql:8.0.33-oracle"
Expand All @@ -37,7 +38,7 @@ services:
PMA_PASSWORD: "qwerty"
ports:
- "9090:80"
restart: "always"
restart: "on-failure"
networks:
- "internal"

Expand Down
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ func main() {
}

sqlConn := os.Getenv("SQL_CONN")

var db graph.DB
if sqlConn != "" {
log.Printf("[INFO] Using sql db sqlConn=%s", sqlConn)
log.Print("[INFO] Using sql db")
db = sqlDB.NewDB(sqlConn)
} else {
log.Print("[INFO] Using in memory db")
Expand Down

0 comments on commit 1e50293

Please sign in to comment.