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 npm install -g less less-plugin-clean-css
RUN go get -u github.com/jteeuwen/go-bindata/...
RUN apk add --update nodejs nodejs-npm make g++ ca-certificates git sqlite-dev && \
npm install -g less less-plugin-clean-css && \
go get -u github.com/jteeuwen/go-bindata/...
RUN mkdir -p /go/src/github.com/writeas/writefreely
WORKDIR /go/src/github.com/writeas/writefreely
WORKDIR /src
COPY ./go.mod ./go.sum ./
RUN go mod download
COPY . .
RUN cd cmd/writefreely && go build -v -tags='sqlite'
RUN make assets ui
ENV GO111MODULE=on
RUN make build \
&& make ui
RUN mkdir /stage && \
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
RUN mkdir -p \
/home/writefreely/static /home/writefreely/templates /home/writefreely/pages && \
cp -r templates/ pages/ static/ /home/writefreely && \
cp config.ini.example /home/writefreely/config.ini
# Final image
FROM alpine:3.8
FROM alpine AS dev
RUN apk add --no-cache openssl ca-certificates
COPY --from=build --chown=daemon:daemon /stage /go
COPY --from=build /src/cmd/writefreely/writefreely /bin
COPY --from=build /home /home
WORKDIR /go
VOLUME /go/keys
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]
hidden_host =
port = 8080
bind = 0.0.0.0
[database]
type = mysql

View file

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

View file

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

View file

@ -1,4 +1,22 @@
#! /bin/bash
docker-compose exec db sh -c 'exec mysql -u root -pchangeme writefreely < /tmp/schema.sql'
docker exec writefreely_web_1 writefreely --gen-keys
docker exec -it writefreely_web_1 writefreely --config
# this script will configure and intialize the persitent data needed
# for a writefreely instance using the docker-compose.yml in this repo
# 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/web-core v1.0.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/net v0.0.0-20190206173232-65e2d4e15006 // indirect
golang.org/x/sys v0.0.0-20190209173611-3b5209105503 // indirect