Browse Source

feat(feat/extended-builds): add dockerfile and docker-compose

pull/198/head
Josh Habdas 2 years ago
parent
commit
52f1830226
Signed by: jhabdas GPG Key ID: B148B31154C75A74
3 changed files with 128 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +56
    -0
      Dockerfile
  3. +71
    -0
      docker-compose.yml

+ 1
- 0
.gitignore View File

@ -1,2 +1,3 @@
node_modules
data/npm
site

+ 56
- 0
Dockerfile View File

@ -0,0 +1,56 @@
#
# Copyright (C) 2019 Josh Habdas <jhabdas@protonmail.com>
#
# This file is part of After Dark.
#
# After Dark is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# After Dark is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# DOCKER-VERSION 19.03.1-ce, build 74b1e89e8a
# Specify build image
ARG GO_VERSION=1.11.4
ARG BUILD_TARGET=alpine3.8
# Pull builder base image
FROM golang:${GO_VERSION}-${BUILD_TARGET} AS hugobuilder
# Set hugo environment variables
ENV HUGO_VERSION=0.57.0 \
CGO_ENABLED=1 \
GOOS=linux \
GO111MODULE=on \
BUILD_TAGS="extended"
# Build hugo from source using specified version
RUN \
apk add --update --no-cache git gcc g++ binutils musl-dev && \
git clone https://github.com/gohugoio/hugo.git $GOPATH/src/github.com/gohugoio/hugo && \
cd ${GOPATH:-$HOME/go}/src/github.com/gohugoio/hugo && \
git checkout v$HUGO_VERSION && \
go install -ldflags '-s -w -extldflags "-static"' -tags ${BUILD_TAGS}
# Install After Dark via script
FROM node:alpine as sitebuilder
COPY --from=hugobuilder /go/bin/hugo /usr/local/bin/hugo
WORKDIR /tmp
RUN wget -qO - https://go.habd.as/after-dark | sh
# Move compiled sources into micro container
FROM busybox
EXPOSE 80
COPY --from=hugobuilder /go/bin/hugo /usr/local/bin/hugo
COPY --from=sitebuilder /tmp/flying-toasters/ /opt/after-dark/
ENTRYPOINT ["/usr/local/bin/hugo"]
CMD ["serve","--buildDrafts","--bind","0.0.0.0","--port","80","--source","/opt/after-dark","--destination","/var/www"]

+ 71
- 0
docker-compose.yml View File

@ -0,0 +1,71 @@
#
# Copyright (C) 2019 Josh Habdas <jhabdas@protonmail.com>
#
# This file is part of After Dark.
#
# After Dark is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# After Dark is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# DOCKER-VERSION 19.03.1-ce, build 74b1e89e8a
# COMPOSE-VERSION 1.24.1
# HOW TO USE THIS FILE
#
# 1. Install Docker and Docker Compose on a host
# 2. Copy `Dockerfile` and `docker-compose.yml` to directory of choice
# 3. Run `docker build .` to build after-dark image
# 4. Run `mkdir -p site/content` to contain your config and site content
# 5. Create a temporary container to copy site config and welcome post from container to host
# ```
# docker create -it --name temp $(docker images -q | head -n 1) sh && \
# docker cp temp:/opt/after-dark/config.toml ./site && \
# docker cp temp:/opt/after-dark/content/post/ ./site/content/ && \
# docker rm -fv temp
# ```
# 6. Add a rule to your hosts file like: `127.0.0.1 after-dark.local` to match traefik label
# 7. Bring the stack up with `docker-compose up -d` then check state with `docker-compose ps`
# 8. If both traefik and web services are up navigate to http://after-dark.local in a browser
# 9. Make a change to the site config for content and watch the page reload with the updates
version: "3.7"
services:
traefik:
image: traefik:v2.0.0
command:
# - "--log.level=DEBUG"
# - "--api.insecure=true"
- "--global.checkNewVersion=false"
- "--global.sendAnonymousUsage=false"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
# - "8080:8080" # Traefik Web UI (enabled by --api.insecure)
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro # So that Traefik can listen to the Docker events
# - ./traefik.toml:/etc/traefik/traefik.toml # Start using config
web:
build: .
expose:
- "80"
volumes:
- ./site/content:/opt/after-dark/content/:ro
- ./site/config.toml:/opt/after-dark/config.toml:ro
labels:
- traefik.enable=true
- traefik.http.routers.after-dark.entrypoints=web
- traefik.http.routers.after-dark.rule=Host(`after-dark.local`)

Loading…
Cancel
Save