Merge pull request #1038 from leo9800/docker-prod

Docker for Production
pull/764/merge
Matt Baer 2 months ago committed by GitHub
commit 71033ecc3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 34
      Dockerfile.prod
  2. 18
      config/setup.go
  3. 25
      docker-compose.prod.yml

@ -0,0 +1,34 @@
FROM golang:alpine AS build
LABEL org.opencontainers.image.source="https://github.com/writefreely/writefreely"
LABEL org.opencontainers.image.description="WriteFreely is a clean, minimalist publishing platform made for writers. Start a blog, share knowledge within your organization, or build a community around the shared act of writing."
RUN apk update --no-cache && \
apk upgrade --no-cache && \
apk add --no-cache nodejs npm make g++ git sqlite-dev patch && \
npm install -g less less-plugin-clean-css && \
mkdir -p /go/src/github.com/writefreely/writefreely
COPY . /go/src/github.com/writefreely/writefreely
WORKDIR /go/src/github.com/writefreely/writefreely
ENV NODE_OPTIONS=--openssl-legacy-provider
RUN cat ossl_legacy.cnf >> /etc/ssl/openssl.cnf && \
make build && \
make ui
FROM alpine
RUN apk update --no-cache && \
apk upgrade --no-cache && \
apk add --no-cache openssl ca-certificates && \
mkdir /usr/share/writefreely
COPY --from=build /go/src/github.com/writefreely/writefreely/cmd/writefreely/writefreely /usr/bin
COPY --from=build /go/src/github.com/writefreely/writefreely/pages /usr/share/writefreely/pages
COPY --from=build /go/src/github.com/writefreely/writefreely/static /usr/share/writefreely/static
COPY --from=build /go/src/github.com/writefreely/writefreely/templates /usr/share/writefreely/templates
ENV WRITEFREELY_DOCKER=True
ENV HOME=/data
WORKDIR /data
CMD ["/usr/bin/writefreely"]

@ -12,12 +12,14 @@ package config
import ( import (
"fmt" "fmt"
"os"
"strconv"
"strings"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/manifoldco/promptui" "github.com/manifoldco/promptui"
"github.com/mitchellh/go-wordwrap" "github.com/mitchellh/go-wordwrap"
"github.com/writeas/web-core/auth" "github.com/writeas/web-core/auth"
"strconv"
"strings"
) )
type SetupData struct { type SetupData struct {
@ -80,6 +82,8 @@ func Configure(fname string, configSections string) (*SetupData, error) {
isDevEnv := envType == "Development" isDevEnv := envType == "Development"
isStandalone := envType == "Production, standalone" isStandalone := envType == "Production, standalone"
_, isDocker := os.LookupEnv("WRITEFREELY_DOCKER")
data.Config.Server.Dev = isDevEnv data.Config.Server.Dev = isDevEnv
if isDevEnv || !isStandalone { if isDevEnv || !isStandalone {
@ -150,6 +154,16 @@ func Configure(fname string, configSections string) (*SetupData, error) {
data.Config.Server.TLSKeyPath = "" data.Config.Server.TLSKeyPath = ""
} }
// If running in docker:
// 1. always bind to 0.0.0.0 instead of localhost
// 2. set paths of static files in UNIX manners
if !isDevEnv && isDocker {
data.Config.Server.TemplatesParentDir = "/usr/share/writefreely"
data.Config.Server.StaticParentDir = "/usr/share/writefreely"
data.Config.Server.PagesParentDir = "/usr/share/writefreely"
data.Config.Server.Bind = "0.0.0.0"
}
fmt.Println() fmt.Println()
} }

@ -0,0 +1,25 @@
services:
app:
image: writefreely
container_name: writefreely
volumes:
- ./data:/data
ports:
- 127.0.0.1:8080:8080
depends_on:
- db
restart: unless-stopped
db:
image: lscr.io/linuxserver/mariadb
container_name: writefreely-mariadb
volumes:
- ./db:/config
environment:
- PUID=65534
- PGID=65534
- TZ=Etc/UTC
- MYSQL_DATABASE=writefreely
- MYSQL_USER=writefreely
- MYSQL_PASSWORD=P@ssw0rd
restart: unless-stopped
Loading…
Cancel
Save