Skip to content

Commit

Permalink
Merge pull request #40 from evanebb/fixes
Browse files Browse the repository at this point in the history
Small Docker container-related fixes
  • Loading branch information
evanebb authored Sep 21, 2023
2 parents 22f3933 + 0cd2b82 commit f36bb20
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.git/
.github/
bin/
configs/
.dockerignore
.gitignore
Dockerfile
*.md
LICENSE
6 changes: 5 additions & 1 deletion configs/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ version: "3"

services:
gobble:
image: ghcr.io/evanebb/gobble:0.0.2
container_name: gobble
image: ghcr.io/evanebb/gobble:0.0.6
build:
context: ../
dockerfile: Dockerfile
depends_on:
- database
ports:
- "80:80/tcp"
environment:
Expand All @@ -15,6 +18,7 @@ services:
GOBBLE_DB_NAME: gobble

database:
container_name: gobble_database
image: postgres:15
volumes:
- "db_data:/var/lib/postgresql/data"
Expand Down
2 changes: 1 addition & 1 deletion server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewAppConfig() (AppConfig, error) {
flag.StringVar(&a.dbUser, "db-user", a.dbUser, "the database user")
flag.StringVar(&a.dbPass, "db-pass", a.dbPass, "the database password")
flag.StringVar(&a.dbHost, "db-host", a.dbHost, "the database host")
flag.StringVar(&a.dbName, "db-name", a.dbHost, "the database to use")
flag.StringVar(&a.dbName, "db-name", a.dbName, "the database to use")
flag.IntVar(&a.dbPort, "db-port", a.dbPort, "the database port to connect to")
flag.StringVar(&a.httpsCertFile, "https-cert-file", a.httpsCertFile, "the TLS certificate file to use for HTTPS")
flag.StringVar(&a.httpsKeyFile, "https-key-file", a.httpsKeyFile, "the TLS certificate key file to use for HTTPS")
Expand Down
19 changes: 16 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/jackc/pgx/v5/pgxpool"
"log"
"net/http"
"time"
)

type Server struct {
Expand All @@ -36,8 +37,20 @@ func NewServer() (Server, error) {
return s, err
}

if err = db.Ping(context.Background()); err != nil {
return s, err
start := time.Now()
timeout := 30 * time.Second

log.Printf("waiting %s for database...", timeout.String())

for {
err = db.Ping(context.Background())
if err == nil {
break
}

if time.Since(start) > timeout {
return s, err
}
}

ar, err := postgres.NewApiUserRepository(db)
Expand Down Expand Up @@ -65,7 +78,7 @@ func NewServer() (Server, error) {
}

func (s *Server) Run() {
log.Println("starting API...")
log.Printf("starting API on %s", s.config.listenAddress)
s.routes()
if s.config.httpsEnabled {
log.Fatal(http.ListenAndServeTLS(s.config.listenAddress, s.config.httpsCertFile, s.config.httpsKeyFile, s.router))
Expand Down

0 comments on commit f36bb20

Please sign in to comment.