Compare commits

...
Sign in to create a new pull request.

7 commits

Author SHA1 Message Date
Rob Loranger
42f6733980
remove containers after use 2019-09-18 08:13:29 -07:00
Rob Loranger
66d9ecf387
add production stage 2019-09-17 10:17:14 -07:00
Rob Loranger
08403ca845
keep --update in apk call 2019-09-16 15:17:36 -07:00
Rob Loranger
82451aebfc
remove unused make target 2019-09-16 15:15:39 -07:00
Rob Loranger
4bc0b46368
clean up .dockerignore 2019-09-16 15:13:46 -07:00
Rob Loranger
34b5581026
finish updating dockerfile and compose
this simplifies the compose file a bit, makes the dockerfile more
efficient and reintroduces the setup script that works with the new
image.

also adds a default 'bind' of 0.0.0.0 to the server block in
config.ini.example.
2019-09-16 13:06:23 -07:00
Rob Loranger
2ec67fc26a
refactor Dockerfile to work with current version
this changes the Dockerfile a bit to work with the current version
0.10.0 of writefreely, and removes the docker-setup script for now.

Kind of a work in progress but wanted to share with those interested.
2019-09-14 14:49:55 -07:00
6 changed files with 58 additions and 39 deletions

View file

@ -1,35 +1,36 @@
# Build image FROM golang:1.12-alpine AS build
FROM golang:1.12-alpine as build
RUN apk add --update nodejs nodejs-npm make g++ git sqlite-dev RUN apk add --update nodejs nodejs-npm make g++ ca-certificates git sqlite-dev && \
RUN npm install -g less less-plugin-clean-css npm install -g less less-plugin-clean-css && \
RUN go get -u github.com/jteeuwen/go-bindata/... go get -u github.com/jteeuwen/go-bindata/...
RUN mkdir -p /go/src/github.com/writeas/writefreely WORKDIR /src
WORKDIR /go/src/github.com/writeas/writefreely COPY ./go.mod ./go.sum ./
RUN go mod download
COPY . . COPY . .
RUN cd cmd/writefreely && go build -v -tags='sqlite'
RUN make assets ui
ENV GO111MODULE=on RUN mkdir -p \
RUN make build \ /home/writefreely/static /home/writefreely/templates /home/writefreely/pages && \
&& make ui cp -r templates/ pages/ static/ /home/writefreely && \
RUN mkdir /stage && \ cp config.ini.example /home/writefreely/config.ini
cp -R /go/bin \
/go/src/github.com/writeas/writefreely/templates \
/go/src/github.com/writeas/writefreely/static \
/go/src/github.com/writeas/writefreely/pages \
/go/src/github.com/writeas/writefreely/keys \
/go/src/github.com/writeas/writefreely/cmd \
/stage
# Final image FROM alpine AS dev
FROM alpine:3.8
RUN apk add --no-cache openssl ca-certificates COPY --from=build /src/cmd/writefreely/writefreely /bin
COPY --from=build --chown=daemon:daemon /stage /go COPY --from=build /home /home
WORKDIR /go
VOLUME /go/keys
EXPOSE 8080 EXPOSE 8080
USER daemon WORKDIR /home/writefreely
ENTRYPOINT [ "writefreely" ]
ENTRYPOINT ["cmd/writefreely/writefreely"] FROM alpine AS prod
RUN apk add ca-certificates openssl
COPY --from=dev . .
EXPOSE 80 443
WORKDIR /home/writefreely
ENTRYPOINT [ "writefreely" ]

View file

@ -1,6 +1,7 @@
[server] [server]
hidden_host = hidden_host =
port = 8080 port = 8080
bind = 0.0.0.0
[database] [database]
type = mysql type = mysql

View file

@ -12,8 +12,9 @@
package config package config
import ( import (
"gopkg.in/ini.v1"
"strings" "strings"
"gopkg.in/ini.v1"
) )
const ( const (

View file

@ -1,10 +1,9 @@
version: "3" version: "3"
services: services:
web: web:
build: . image: writeas/writefreely:latest
volumes: volumes:
- "web-data:/go/src/app" - web-data:/home/writefreely
- "./config.ini.example:/go/src/app/config.ini"
ports: ports:
- "8080:8080" - "8080:8080"
networks: networks:
@ -15,8 +14,7 @@ services:
db: db:
image: "mariadb:latest" image: "mariadb:latest"
volumes: volumes:
- "./schema.sql:/tmp/schema.sql" - db-data:/var/lib/mysql
- db-data:/var/lib/mysql/data
networks: networks:
- writefreely - writefreely
environment: environment:
@ -25,8 +23,8 @@ services:
restart: unless-stopped restart: unless-stopped
volumes: volumes:
web-data: web-data:
db-data: db-data:
networks: networks:
writefreely: writefreely:

View file

@ -1,4 +1,22 @@
#!/bin/bash #! /bin/bash
docker-compose exec db sh -c 'exec mysql -u root -pchangeme writefreely < /tmp/schema.sql' # this script will configure and intialize the persitent data needed
docker exec writefreely_web_1 writefreely --gen-keys # for a writefreely instance using the docker-compose.yml in this repo
docker exec -it writefreely_web_1 writefreely --config
# start database
docker run --rm -d --volume=writefreely_db-data:/var/lib/mysql \
--name=db \
-e "MYSQL_DATABASE=writefreely" \
-e "MYSQL_ROOT_PASSWORD=changeme" \
-p 3306:3306 \
mariadb:latest
# create new asset signing keys
docker run --rm --volume=writefreely_web-data:/home/writefreely writeas/writefreely:latest "-gen-keys"
# generate new configuration and initialize database
docker run --rm -it --volume=writefreely_web-data:/home/writefreely \
--link db:db \
writeas/writefreely:latest "-config"
# clean up detached database container
docker container stop db

2
go.mod
View file

@ -63,7 +63,7 @@ require (
github.com/writeas/slug v1.2.0 github.com/writeas/slug v1.2.0
github.com/writeas/web-core v1.0.0 github.com/writeas/web-core v1.0.0
github.com/writefreely/go-nodeinfo v1.2.0 github.com/writefreely/go-nodeinfo v1.2.0
golang.org/x/crypto v0.0.0-20190208162236-193df9c0f06f // indirect golang.org/x/crypto v0.0.0-20190208162236-193df9c0f06f
golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1 // indirect golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1 // indirect
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 // indirect golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 // indirect
golang.org/x/sys v0.0.0-20190209173611-3b5209105503 // indirect golang.org/x/sys v0.0.0-20190209173611-3b5209105503 // indirect