Browse Source

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

Josh Habdas 11 months ago
parent
commit
52f1830226
Signed by: Josh Habdas <jhabdas@protonmail.com> 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 @@
1 1
 node_modules
2 2
 data/npm
3
+site

+ 56
- 0
Dockerfile View File

@@ -0,0 +1,56 @@
1
+#
2
+# Copyright (C) 2019  Josh Habdas <jhabdas@protonmail.com>
3
+#
4
+# This file is part of After Dark.
5
+#
6
+# After Dark is free software: you can redistribute it and/or modify
7
+# it under the terms of the GNU Affero General Public License as published
8
+# by the Free Software Foundation, either version 3 of the License, or
9
+# (at your option) any later version.
10
+#
11
+# After Dark is distributed in the hope that it will be useful,
12
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+# GNU Affero General Public License for more details.
15
+#
16
+# You should have received a copy of the GNU Affero General Public License
17
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
+#
19
+
20
+# DOCKER-VERSION 19.03.1-ce, build 74b1e89e8a
21
+
22
+# Specify build image
23
+ARG GO_VERSION=1.11.4
24
+ARG BUILD_TARGET=alpine3.8
25
+
26
+# Pull builder base image
27
+FROM golang:${GO_VERSION}-${BUILD_TARGET} AS hugobuilder
28
+
29
+# Set hugo environment variables
30
+ENV HUGO_VERSION=0.57.0 \
31
+    CGO_ENABLED=1 \
32
+    GOOS=linux \
33
+    GO111MODULE=on \
34
+    BUILD_TAGS="extended"
35
+
36
+# Build hugo from source using specified version
37
+RUN \
38
+  apk add --update --no-cache git gcc g++ binutils musl-dev && \
39
+  git clone https://github.com/gohugoio/hugo.git $GOPATH/src/github.com/gohugoio/hugo && \
40
+  cd ${GOPATH:-$HOME/go}/src/github.com/gohugoio/hugo && \
41
+  git checkout v$HUGO_VERSION && \
42
+  go install -ldflags '-s -w -extldflags "-static"' -tags ${BUILD_TAGS}
43
+
44
+# Install After Dark via script
45
+FROM node:alpine as sitebuilder
46
+COPY --from=hugobuilder /go/bin/hugo /usr/local/bin/hugo
47
+WORKDIR /tmp
48
+RUN wget -qO - https://go.habd.as/after-dark | sh
49
+
50
+# Move compiled sources into micro container
51
+FROM busybox
52
+EXPOSE 80
53
+COPY --from=hugobuilder /go/bin/hugo /usr/local/bin/hugo
54
+COPY --from=sitebuilder /tmp/flying-toasters/ /opt/after-dark/
55
+ENTRYPOINT ["/usr/local/bin/hugo"]
56
+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 @@
1
+#
2
+# Copyright (C) 2019  Josh Habdas <jhabdas@protonmail.com>
3
+#
4
+# This file is part of After Dark.
5
+#
6
+# After Dark is free software: you can redistribute it and/or modify
7
+# it under the terms of the GNU Affero General Public License as published
8
+# by the Free Software Foundation, either version 3 of the License, or
9
+# (at your option) any later version.
10
+#
11
+# After Dark is distributed in the hope that it will be useful,
12
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+# GNU Affero General Public License for more details.
15
+#
16
+# You should have received a copy of the GNU Affero General Public License
17
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
+#
19
+
20
+# DOCKER-VERSION 19.03.1-ce, build 74b1e89e8a
21
+# COMPOSE-VERSION 1.24.1
22
+
23
+# HOW TO USE THIS FILE
24
+#
25
+# 1. Install Docker and Docker Compose on a host
26
+# 2. Copy `Dockerfile` and `docker-compose.yml` to directory of choice
27
+# 3. Run `docker build .` to build after-dark image
28
+# 4. Run `mkdir -p site/content` to contain your config and site content
29
+# 5. Create a temporary container to copy site config and welcome post from container to host
30
+#    ```
31
+#    docker create -it --name temp $(docker images -q | head -n 1) sh && \
32
+#    docker cp temp:/opt/after-dark/config.toml ./site && \
33
+#    docker cp temp:/opt/after-dark/content/post/ ./site/content/ && \
34
+#    docker rm -fv temp
35
+#    ```
36
+# 6. Add a rule to your hosts file like: `127.0.0.1 after-dark.local` to match traefik label
37
+# 7. Bring the stack up with `docker-compose up -d` then check state with `docker-compose ps`
38
+# 8. If both traefik and web services are up navigate to http://after-dark.local in a browser
39
+# 9. Make a change to the site config for content and watch the page reload with the updates
40
+
41
+version: "3.7"
42
+services:
43
+
44
+  traefik:
45
+    image: traefik:v2.0.0
46
+    command:
47
+      # - "--log.level=DEBUG"
48
+      # - "--api.insecure=true"
49
+      - "--global.checkNewVersion=false"
50
+      - "--global.sendAnonymousUsage=false"
51
+      - "--providers.docker=true"
52
+      - "--providers.docker.exposedbydefault=false"
53
+      - "--entrypoints.web.address=:80"
54
+    ports:
55
+      - "80:80"
56
+      # - "8080:8080" # Traefik Web UI (enabled by --api.insecure)
57
+    volumes:
58
+      - /var/run/docker.sock:/var/run/docker.sock:ro # So that Traefik can listen to the Docker events
59
+      # - ./traefik.toml:/etc/traefik/traefik.toml # Start using config
60
+
61
+  web:
62
+    build: .
63
+    expose:
64
+      - "80"
65
+    volumes:
66
+      - ./site/content:/opt/after-dark/content/:ro
67
+      - ./site/config.toml:/opt/after-dark/config.toml:ro
68
+    labels:
69
+      - traefik.enable=true
70
+      - traefik.http.routers.after-dark.entrypoints=web
71
+      - traefik.http.routers.after-dark.rule=Host(`after-dark.local`)

Loading…
Cancel
Save