Browse Source

Add Dockerfile

pull/1/head
Jan-Lukas Else 1 year ago
parent
commit
c2c384cf65
4 changed files with 34 additions and 6 deletions
  1. +4
    -0
      .dockerignore
  2. +22
    -0
      Dockerfile
  3. +4
    -1
      database.go
  4. +4
    -5
      helpers/packrSource.go

+ 4
- 0
.dockerignore View File

@ -0,0 +1,4 @@
.idea
data
.dockerignore
Dockerfile

+ 22
- 0
Dockerfile View File

@ -0,0 +1,22 @@
FROM golang:1.12-alpine as packr
RUN apk add --no-cache git
RUN go get github.com/gobuffalo/packr/v2/packr2
FROM golang:1.12-alpine as build
COPY --from=packr /go/bin/packr2 /go/bin
ADD . /app
WORKDIR /app
RUN apk add --no-cache git gcc musl-dev
RUN GO111MODULE=on packr2
RUN go build kis3.dev/kis3
FROM alpine:3.9
RUN adduser -S -D -H -h /app kis3
COPY --from=build /app/kis3 /app/
RUN chown -R kis3 /app
USER kis3
WORKDIR /app
RUN mkdir data
VOLUME ["/app/data"]
EXPOSE 8080
CMD ["./kis3"]

+ 4
- 1
database.go View File

@ -3,6 +3,7 @@ package main
import (
"database/sql"
"fmt"
"github.com/gobuffalo/packr/v2"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/sqlite3"
_ "github.com/mattn/go-sqlite3"
@ -30,7 +31,9 @@ func initDatabase() (database *Database, e error) {
}
func migrateDatabase(database *sql.DB) (e error) {
sourceDriver, e := (&helpers.PackrSource{}).Open("")
sourceDriver, e := (&helpers.PackrSource{
Box: packr.New("migrations", "migrations"),
}).Open("")
if e != nil {
return
}


+ 4
- 5
helpers/packrSource.go View File

@ -15,13 +15,13 @@ import (
type PackrSource struct {
lock sync.Mutex
box *packr.Box
Box *packr.Box
migrations *source.Migrations
}
func (s *PackrSource) loadMigrations() (*source.Migrations, error) {
migrations := source.NewMigrations()
for _, filename := range s.box.List() {
for _, filename := range s.Box.List() {
migration, err := source.Parse(filename)
if err != nil {
return nil, err
@ -34,7 +34,6 @@ func (s *PackrSource) loadMigrations() (*source.Migrations, error) {
func (s *PackrSource) Open(url string) (source.Driver, error) {
s.lock.Lock()
defer s.lock.Unlock()
s.box = packr.New("migrations", "../migrations")
if migrations, err := s.loadMigrations(); err != nil {
return nil, err
} else {
@ -78,7 +77,7 @@ func (s *PackrSource) ReadUp(version uint) (r io.ReadCloser, identifier string,
if migration, ok := s.migrations.Up(version); !ok {
return nil, "", os.ErrNotExist
} else {
b, _ := s.box.Find(migration.Raw)
b, _ := s.Box.Find(migration.Raw)
return ioutil.NopCloser(bytes.NewBuffer(b)),
migration.Identifier,
nil
@ -89,7 +88,7 @@ func (s *PackrSource) ReadDown(version uint) (r io.ReadCloser, identifier string
if migration, ok := s.migrations.Down(version); !ok {
return nil, "", migrate.ErrNilVersion
} else {
b := s.box.Bytes(migration.Raw)
b := s.Box.Bytes(migration.Raw)
return ioutil.NopCloser(bytes.NewBuffer(b)),
migration.Identifier,
nil


Loading…
Cancel
Save