Skip to content

Commit 53f895a

Browse files
committed
feat: update docker for sqlite
1 parent f175a47 commit 53f895a

File tree

5 files changed

+12
-62
lines changed

5 files changed

+12
-62
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM golang:1.20-alpine
3+
FROM golang:1.20
44

55
WORKDIR /app
66

@@ -9,6 +9,7 @@ COPY go.sum ./
99
RUN go mod download
1010

1111
COPY ./cmd/server ./cmd/server
12+
COPY ./data/sqlite ./data/sqlite
1213
COPY ./pkg ./pkg
1314
COPY ./docs ./docs
1415
COPY ./static/site ./static/site

cmd/server/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import (
99
log "github.com/sirupsen/logrus"
1010
)
1111

12-
// @title Jepp API Documentation
13-
// @description This is a simple api to access jeopardy data.
14-
// @version 1.0
15-
// @BasePath /api
12+
// @title Jepp API Documentation
13+
// @description This is a simple api to access jeopardy data.
14+
// @version 1.0
15+
// @BasePath /api
1616
//
17-
// @contact.name shreve
17+
// @contact.name shreve
1818
//
19-
// @license.name MIT License
20-
// @license.url https://github.com/ecshreve/jepp/blob/main/LICENSE
19+
// @license.name MIT License
20+
// @license.url https://github.com/ecshreve/jepp/blob/main/LICENSE
2121
func main() {
2222
if os.Getenv("JEPP_ENV") == "prod" {
2323
docs.SwaggerInfo.Host = "jepp.app"

docker-compose.yml

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,12 @@
11
version: '3.1'
22

33
services:
4-
db:
5-
image: mariadb:10.11.3
6-
restart: unless-stopped
7-
environment:
8-
MARIADB_DATABASE: jeppdb
9-
MARIADB_USER: jepp
10-
MARIADB_PASSWORD: jepp
11-
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
12-
MARIADB_MYSQL_LOCALHOST_USER: true
13-
ports:
14-
- 3306:3306
15-
volumes:
16-
- db-data:/var/lib/mysql
17-
- ./data/dump.sql.gz:/docker-entrypoint-initdb.d/dump.sql.gz
18-
healthcheck:
19-
test: ["CMD", "/usr/local/bin/healthcheck.sh", "--connect", "--innodb_initialized"]
20-
interval: 30s
21-
timeout: 30s
22-
retries: 10
23-
start_period: 30s
24-
25-
api:
26-
build:
4+
app:
5+
build:
276
context: .
287
dockerfile: Dockerfile
298
restart: unless-stopped
309
environment:
3110
JEPP_ENV: ${JEPP_ENV}
32-
JEPP_DB_HOST: db
33-
JEPP_DB_PASSWORD: ""
3411
ports:
3512
- 8880:8880
36-
depends_on:
37-
db:
38-
condition: service_healthy
39-
40-
# useful for local development
41-
#
42-
# adminer:
43-
# image: adminer
44-
# restart: unless-stopped
45-
# depends_on:
46-
# db:
47-
# condition: service_healthy
48-
# ports:
49-
# - 8881:8080
50-
51-
52-
volumes:
53-
db-data:
54-
driver: local

pkg/models/category.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func (db *JeppDB) InsertCategory(name string) (*Category, error) {
6666
if err := tx.Commit(); err == nil {
6767
lid, _ := res.LastInsertId()
6868
cat = &Category{CategoryID: lid, Name: name}
69-
db.LastCategoryID = lid
7069
log.Debugf("inserted category -- %+v", cat)
7170
} else {
7271
return nil, oops.Wrapf(err, "could not insert category: %v", name)

pkg/models/models.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,13 @@ package models
33
import (
44
"github.com/jmoiron/sqlx"
55
_ "github.com/mattn/go-sqlite3"
6-
log "github.com/sirupsen/logrus"
76
)
87

98
type JeppDB struct {
109
*sqlx.DB
11-
LastCategoryID int64
1210
}
1311

1412
func NewJeppDB(dbfile string) *JeppDB {
1513
db := sqlx.MustOpen("sqlite3", dbfile)
16-
var lid int64
17-
if err := db.Get(&lid, "SELECT MAX(category_id) FROM category"); err != nil {
18-
log.Debugf("could not get last category id: %v", err)
19-
return nil
20-
}
21-
db.Get(&lid, "SELECT MAX(id) FROM category")
22-
return &JeppDB{DB: db, LastCategoryID: lid}
14+
return &JeppDB{DB: db}
2315
}

0 commit comments

Comments
 (0)