From 5b393309a5c092aa60b687f144329b949ed3db45 Mon Sep 17 00:00:00 2001 From: Jean-Francois Arseneau Date: Tue, 13 Nov 2018 20:24:06 -0800 Subject: [PATCH] Add Dockerfile and Docker Compose files This adds the first version of a Dockerfile, built on an Alpine Linux variation of the golang image, as well as a Docker Compose file that spins up both a MariaDB and the instance. It also updates the README with instructions on how to get Write Freely running with this setup. --- Dockerfile | 15 +++++++++++++++ README.md | 38 ++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a2dd072 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.11.2-alpine3.8 + +RUN apk add --update nodejs nodejs-npm make git +RUN npm install -g less +RUN npm install -g less-plugin-clean-css + +WORKDIR /go/src/app +COPY . . + +RUN make install +RUN make ui +RUN make deps + +EXPOSE 8080 +CMD ["writefreely"] diff --git a/README.md b/README.md index 62d9d66..99a0be1 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,44 @@ make ui # Generates CSS (run this whenever you update your styles) make run # Runs the application ``` +### Using Docker + +From the cloned git repository, you can quickly stand up a Write Freely instance with Docker and Docker Compose. + +First, you'll need to change the password for MariaDB's root user in `docker-compose.yml` from `changeme` to something that is unique to your setup: + +``` +environment: + - MYSQL_ROOT_PASSWORD=changeme +``` + +After that, you can spin up the containers and configure them: + +```bash +# 1) Spin up the DB and Write Freely +docker-compose up -d + +# 2) Connect to MariaDB container +docker-compose exec db /bin/sh + +# 3) Log in to MariaDB, using the password you specified in docker-compose.yml +mysql -u root -p + +# 4) Create the database for Write Freely +CREATE DATABASE writefreely; +exit + +# 5) Migrate the database +mysql -u root -p writefreely < /tmp/schema.sql +exit + +# 6) Generate the configuration and clean up +docker-compose run web writefreely --config +docker stop writefreely_web_run_1 && docker rm writefreely_web_run_1 +``` + +Now you should be able to navigate to http://localhost:8080 and start blogging! + ## License Licensed under the AGPL. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8284636 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +version: "3" +services: + web: + build: . + volumes: + - "web-data:/go/src/app" + ports: + - "8080:8080" + networks: + - writefreely + depends_on: + - db + restart: unless-stopped + db: + image: "mariadb:latest" + volumes: + - "./schema.sql:/tmp/schema.sql" + - db-data:/var/lib/mysql/data + networks: + - writefreely + environment: + - MYSQL_ROOT_PASSWORD=changeme + restart: unless-stopped + +volumes: + web-data: + db-data: + +networks: + writefreely: