From a334076b6af46ef17c9d2f45d79f53fbc403f68b Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Tue, 16 Oct 2018 10:26:03 +0200 Subject: [PATCH] Update, multi-stage build and lightweight image - Update to Stackedit 5.13.2 - Update to Alpine 3.8 - Multi stage build using Caddy server - Image cut down to 52MB - Readme simplified --- Caddyfile | 3 +++ Dockerfile | 45 +++++++++++++++++++------------ README.md | 67 +++++++++++++++++++++++++++++----------------- docker-compose.yml | 14 +++++----- 4 files changed, 80 insertions(+), 49 deletions(-) create mode 100644 Caddyfile diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..cbd0faf --- /dev/null +++ b/Caddyfile @@ -0,0 +1,3 @@ +http://localhost { + root /stackedit +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index fd50776..a9589b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,31 @@ -FROM alpine:3.7 +FROM golang:alpine AS caddy +WORKDIR /go/src/github.com/mholt/caddy +RUN echo https://alpine.global.ssl.fastly.net/alpine/v3.8/main > /etc/apk/repositories && \ + apk add --progress --update git gcc musl-dev ca-certificates +RUN git clone --branch v0.11.0 --single-branch --depth 1 https://github.com/mholt/caddy /go/src/github.com/mholt/caddy &> /dev/null && \ + sed -i 's/var EnableTelemetry = true/var EnableTelemetry = false/' /go/src/github.com/mholt/caddy/caddy/caddymain/run.go && \ + sed -i 's/const enableTelemetry = true/const enableTelemetry = false/' /go/src/github.com/mholt/caddy/caddy/caddymain/run.go +RUN git clone https://github.com/caddyserver/builds /go/src/github.com/caddyserver/builds +RUN cd caddy && go run build.go -goos=linux -goarch=amd64 + +FROM alpine:3.8 AS stackedit +RUN echo https://alpine.global.ssl.fastly.net/alpine/v3.8/main > /etc/apk/repositories && \ + apk add -q --progress --update --no-cache git npm +RUN git clone --branch v5.13.2 --single-branch --depth 1 https://github.com/benweet/stackedit.git /stackedit &> /dev/null +WORKDIR /stackedit +RUN npm install +RUN npm run build + +FROM alpine:3.8 LABEL maintainer="quentin.mcgaw@gmail.com" \ - description="Run the latest StackEdit server in a Docker container" \ - download="179MB" \ - size="581MB" \ - ram="340MB-500MB" \ + description="StackEdit server in a lightweight Docker container" \ + download="???MB" \ + size="51.2MB" \ + ram="2MB-3MB" \ cpu_usage="Very low" \ github="https://github.com/qdm12/stackedit-docker" -RUN apk add -q --progress --update --no-cache git nodejs && \ - git clone https://github.com/benweet/stackedit.git && \ - cd stackedit && \ - rm -rf .git .dockerignore .gitignore .travis.yml CHANGELOG.md \ - Dockerfile LICENSE README.md && \ - npm --silent install && \ - npm --silent run build && \ - apk del -q --progress --purge git && \ - rm -rf /var/cache/apk/* -EXPOSE 8080 -WORKDIR /stackedit -ENTRYPOINT npm start \ No newline at end of file +EXPOSE 80 +COPY --from=caddy /go/src/github.com/mholt/caddy/caddy/caddy /usr/bin/caddy +COPY Caddyfile /Caddyfile +COPY --from=stackedit /stackedit/dist /stackedit +ENTRYPOINT caddy -conf /Caddyfile -log stdout diff --git a/README.md b/README.md index e6879d1..d6c70d0 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,74 @@ # StackEdit Docker server -Run a StackEdit v5.10.4 (April 2018) server in a Docker container. +Run a StackEdit v5.13.2 (October 2018) server with Caddy server in a lightweight Docker container [![Docker StackEdit](https://github.com/qdm12/stackedit-docker/raw/master/readme/title.png)](https://hub.docker.com/r/qmcgaw/stackedit/) Docker build: [![Build Status](https://travis-ci.org/qdm12/stackedit-docker.svg?branch=master)](https://travis-ci.org/qdm12/stackedit-docker) +[![Docker Build Status](https://img.shields.io/docker/build/qmcgaw/stackedit.svg)](https://hub.docker.com/r/qmcgaw/stackedit) Stackedit build: [![Build Status](https://img.shields.io/travis/benweet/stackedit.svg?style=flat)](https://travis-ci.org/benweet/stackedit) -[![](https://images.microbadger.com/badges/image/qmcgaw/stackedit.svg)](https://microbadger.com/images/qmcgaw/stackedit "Get your own image badge on microbadger.com") -[![](https://images.microbadger.com/badges/version/qmcgaw/stackedit.svg)](https://microbadger.com/images/qmcgaw/stackedit "Get your own version badge on microbadger.com") +[![GitHub last commit](https://img.shields.io/github/last-commit/qdm12/stackedit-docker.svg)](https://github.com/qdm12/stackedit-docker/commits) +[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/qdm12/stackedit-docker.svg)](https://github.com/qdm12/stackedit-docker/commits) +[![GitHub issues](https://img.shields.io/github/issues/qdm12/stackedit-docker.svg)](https://github.com/qdm12/stackedit-docker/issues) + +[![Docker Pulls](https://img.shields.io/docker/pulls/qmcgaw/stackedit.svg)](https://hub.docker.com/r/qmcgaw/stackedit) +[![Docker Stars](https://img.shields.io/docker/stars/qmcgaw/stackedit.svg)](https://hub.docker.com/r/qmcgaw/stackedit) +[![Docker Automated](https://img.shields.io/docker/automated/qmcgaw/stackedit.svg)](https://hub.docker.com/r/qmcgaw/stackedit) + +[![](https://images.microbadger.com/badges/image/qmcgaw/stackedit.svg)](https://microbadger.com/images/qmcgaw/stackedit) +[![](https://images.microbadger.com/badges/version/qmcgaw/stackedit.svg)](https://microbadger.com/images/qmcgaw/stackedit) | Download size | Image size | RAM usage | CPU usage | | --- | --- | --- | --- | -| 179MB | 581MB | 310MB | Very low | - -It is based on: -- [Stackedit](https://github.com/benweet/stackedit) -- Alpine Linux -- Nodejs +| ???MB | 51.2MB | 2-3MB | Very low | ## Features - [Stackedit features](https://github.com/benweet/stackedit/blob/master/README.md#stackedit-can) +- Lightweight image based on: + - [Stackedit 5.13.2](https://github.com/benweet/stackedit) (38MB) + - Alpine 3.8 (4.41MB) + - Caddy HTTP server (9MB) +- Robust Caddy server (you can easily add HTTPS if needed) -## Installation +## Setup -### Option 1 of 2: Using Docker Compose +Using plain Docker with: -1. Download [**docker-compose.yml**](https://raw.githubusercontent.com/qdm12/stackedit-docker/master/docker-compose.yml) -1. Optionally edit *docker-compose.yml* to fit you better -1. With a terminal, go to the directory containing the file and launch -the container in the background with: - - ```bash - docker-compose up -d - ``` +```bash +docker run -d --name=stackedit --restart=always -p 8000:80/tcp qmcgaw/stackedit +``` -### Option 2 of 2: Using Docker only -In a terminal, enter: +Or use Docker Compose: -```bash -docker run -d --name=stackedit --restart=always -p 8080:8080/tcp qmcgaw/stackedit +```yml +version: '3' +services: + stackedit: + image: qmcgaw/stackedit + container_name: stackedit + ports: + - 8000:80/tcp + network_mode: bridge + restart: always ``` -The container TCP port 8080 is forwarded to the host TCP port 8080 + +with the command + + +```bash +docker-compose up -d +``` ## Testing -Go to [http://localhost:8080](http://localhost:8080) +Go to [http://localhost:8000](http://localhost:8000) ## Acknowledgements diff --git a/docker-compose.yml b/docker-compose.yml index baedfc8..4fc16df 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,9 @@ version: '3' services: - stackedit: - image: qmcgaw/stackedit - container_name: stackedit - ports: - - "8080:8080/tcp" - network_mode: bridge - restart: always \ No newline at end of file + stackedit: + image: qmcgaw/stackedit + container_name: stackedit + ports: + - 8000:80/tcp + network_mode: bridge + restart: always