1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Merge pull request #397 from muety/docker-simplify

Simplify Dockerfile
This commit is contained in:
Ferdinand Mütsch 2022-08-19 13:59:33 +02:00 committed by GitHub
commit 4bfc8a9e9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 45 deletions

View File

@ -1,33 +1,25 @@
# To build locally: docker buildx build . -t wakapi --load
# Preparation to save some time
FROM --platform=$BUILDPLATFORM golang:1.18-alpine AS prep-env
WORKDIR /src
ADD ./go.mod .
RUN go mod download
ADD . .
RUN wget "https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh" -O wait-for-it.sh && \
chmod +x wait-for-it.sh
# Build Stage
FROM golang:1.18-alpine AS build-env FROM golang:1.18-alpine AS build-env
WORKDIR /src
# Required for go-sqlite3 # Required for go-sqlite3
RUN apk add --no-cache gcc musl-dev RUN apk add --no-cache gcc musl-dev
WORKDIR /src RUN wget "https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh" -O wait-for-it.sh && \
COPY --from=prep-env /src . chmod +x wait-for-it.sh
RUN go build -v -o wakapi ADD ./go.mod ./go.sum ./
RUN go mod download
ADD . .
WORKDIR /app RUN go build -ldflags "-s -w" -v -o wakapi main.go
RUN cp /src/wakapi . && \
cp /src/config.default.yml config.yml && \ WORKDIR /staging
sed -i 's/listen_ipv6: ::1/listen_ipv6: /g' config.yml && \ RUN mkdir ./data ./app && \
cp /src/wait-for-it.sh . && \ cp /src/wakapi app/ && \
cp /src/entrypoint.sh . cp /src/config.default.yml app/config.yml && \
sed -i 's/listen_ipv6: ::1/listen_ipv6: /g' app/config.yml && \
cp /src/wait-for-it.sh app/ && \
cp /src/entrypoint.sh app/
# Run Stage # Run Stage
@ -41,18 +33,18 @@ WORKDIR /app
RUN apk add --no-cache bash ca-certificates tzdata RUN apk add --no-cache bash ca-certificates tzdata
# See README.md and config.default.yml for all config options # See README.md and config.default.yml for all config options
ENV ENVIRONMENT prod ENV ENVIRONMENT=prod \
ENV WAKAPI_DB_TYPE sqlite3 WAKAPI_DB_TYPE=sqlite3 \
ENV WAKAPI_DB_USER '' WAKAPI_DB_USER='' \
ENV WAKAPI_DB_PASSWORD '' WAKAPI_DB_PASSWORD='' \
ENV WAKAPI_DB_HOST '' WAKAPI_DB_HOST='' \
ENV WAKAPI_DB_NAME=/data/wakapi.db WAKAPI_DB_NAME=/data/wakapi.db \
ENV WAKAPI_PASSWORD_SALT '' WAKAPI_PASSWORD_SALT='' \
ENV WAKAPI_LISTEN_IPV4 '0.0.0.0' WAKAPI_LISTEN_IPV4='0.0.0.0' \
ENV WAKAPI_INSECURE_COOKIES 'true' WAKAPI_INSECURE_COOKIES='true' \
ENV WAKAPI_ALLOW_SIGNUP 'true' WAKAPI_ALLOW_SIGNUP='true'
COPY --from=build-env /app . COPY --from=build-env /staging /
EXPOSE 3000 EXPOSE 3000

26
main.go
View File

@ -2,7 +2,6 @@ package main
import ( import (
"embed" "embed"
"github.com/muety/wakapi/migrations"
"io/fs" "io/fs"
"log" "log"
"net" "net"
@ -11,28 +10,29 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/lpar/gzipped/v2"
"github.com/muety/wakapi/routes/relay"
"github.com/emvi/logbuch" "github.com/emvi/logbuch"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
conf "github.com/muety/wakapi/config"
"github.com/muety/wakapi/repositories"
"github.com/muety/wakapi/routes/api"
"github.com/muety/wakapi/services/mail"
fsutils "github.com/muety/wakapi/utils/fs"
"gorm.io/gorm/logger"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/lpar/gzipped/v2"
conf "github.com/muety/wakapi/config"
"github.com/muety/wakapi/middlewares" "github.com/muety/wakapi/middlewares"
"github.com/muety/wakapi/migrations"
"github.com/muety/wakapi/repositories"
"github.com/muety/wakapi/routes" "github.com/muety/wakapi/routes"
"github.com/muety/wakapi/routes/api"
shieldsV1Routes "github.com/muety/wakapi/routes/compat/shields/v1" shieldsV1Routes "github.com/muety/wakapi/routes/compat/shields/v1"
wtV1Routes "github.com/muety/wakapi/routes/compat/wakatime/v1" wtV1Routes "github.com/muety/wakapi/routes/compat/wakatime/v1"
"github.com/muety/wakapi/routes/relay"
"github.com/muety/wakapi/services" "github.com/muety/wakapi/services"
"github.com/muety/wakapi/services/mail"
fsutils "github.com/muety/wakapi/utils/fs"
_ "gorm.io/driver/mysql" _ "gorm.io/driver/mysql"
_ "gorm.io/driver/postgres" _ "gorm.io/driver/postgres"
_ "gorm.io/driver/sqlite" _ "gorm.io/driver/sqlite"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/logger"
) )
// Embed version.txt // Embed version.txt
@ -121,6 +121,10 @@ func main() {
// Connect to database // Connect to database
var err error var err error
db, err = gorm.Open(config.Db.GetDialector(), &gorm.Config{Logger: gormLogger}) db, err = gorm.Open(config.Db.GetDialector(), &gorm.Config{Logger: gormLogger})
if err != nil {
logbuch.Error(err.Error())
logbuch.Fatal("could not open database")
}
if config.Db.IsSQLite() { if config.Db.IsSQLite() {
db.Exec("PRAGMA foreign_keys = ON;") db.Exec("PRAGMA foreign_keys = ON;")
} }