├── Dockerfile ├── LICENSE ├── build.sh ├── entrypoint.sh ├── generate.sh ├── hooks.json ├── readme.md └── vuepress-webhook.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.19-alpine as build 2 | 3 | RUN apk add curl tar gzip libc-dev git 4 | COPY build.sh /build.sh 5 | RUN chmod +x /build.sh && /build.sh 6 | 7 | FROM node:16-alpine 8 | 9 | RUN yarn global add vuepress@1.9.2 \ 10 | && yarn add -D vuepress@1.9.2 @vuepress/plugin-pwa@1.9.2 @vuepress/plugin-medium-zoom@1.9.2 \ 11 | && mkdir -p /root/src /root/html \ 12 | && apk add rsync curl git 13 | COPY --from=build /usr/local/bin/webhook /usr/local/bin/webhook 14 | COPY entrypoint.sh /entrypoint.sh 15 | COPY vuepress-webhook.sh /vuepress-webhook.sh 16 | COPY hooks.json /hooks.json 17 | COPY generate.sh /generate.sh 18 | RUN chmod +x /vuepress-webhook.sh 19 | EXPOSE 9000 20 | ENTRYPOINT ["sh", "/entrypoint.sh"] 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 blastehh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | 3 | mkdir -p ~/webhook 4 | curl -sL https://github.com/adnanh/webhook/archive/refs/tags/2.8.0.tar.gz | tar -xvz --strip-components=1 -C ~/webhook 5 | cd ~/webhook 6 | go get -d 7 | go build -o /usr/local/bin/webhook -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | if [ -n "${PLUGINS}" ]; then 3 | yarn add -D ${PLUGINS} 4 | fi 5 | if [ -n "$USE_HOOK" ]; then 6 | 7 | /usr/local/bin/webhook -hooks /hooks.json -verbose 8 | 9 | else 10 | sh /generate.sh 11 | while sleep 23h; do sh /generate.sh; done 12 | fi -------------------------------------------------------------------------------- /generate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | set -euo pipefail 3 | 4 | mkdir -p /root/html 5 | cd /root/src 6 | rm -rf .vuepress/dist 7 | vuepress build 8 | echo "Copying files..." 9 | rsync -q -r --delete .vuepress/dist/ /root/html/ 10 | echo "Done!" -------------------------------------------------------------------------------- /hooks.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "vuepress-webhook", 4 | "execute-command": "/vuepress-webhook.sh", 5 | "command-working-directory": "/" 6 | } 7 | ] -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # [Vuepress-docker](https://hub.docker.com/r/blasteh/vuepress) 2 | Simple build of vuepress using Alpine Linux on Docker. 3 | 4 | The image has 2 folders, 1 for input files, 1 for output files. 5 | Mount these folders to use the image: 6 | 7 | Input folder: `/root/src` 8 | 9 | Output folder: `/root/html` 10 | 11 | When the build runs, it will take contents of the input folder, generate the site, and then place them in the output folder. 12 | This image regenerates the files every 23 hours unless you use the hook option. 13 | Webhook is supplied by [Hookdoo](https://github.com/adnanh/webhook) 14 | 15 | ## Environment variables 16 | `USE_HOOK` - The web hook is enabled as long as this is present. 17 | 18 | `GITHUB_REPO` - Remove "https://" from the url; e.g. use `GITHUB_REPO=github.com/blastehh/vuepress-docker.git` instead of `GITHUB_REPO=https://github.com/blastehh/vuepress-docker.git` 19 | 20 | `GITHUB_TOKEN` - Needed to access private repos, otherwise will try to access a public repo. 21 | 22 | `GITHUB_PUSH_REPO` - URL of repo to push to once build finishes, e.g. `github.com/blastehh/mypage.git` 23 | 24 | `GITHUB_PUSH_TOKEN` - Set the token for pushing to Github if different from `GITHUB_TOKEN` 25 | 26 | `PLUGINS` - A space delimited list of vuepress plugins to install; e.g. `PLUGINS="@vuepress/plugin-back-to-top @vuepress/plugin-pwa"` 27 | 28 | ## Example docker command 29 | This will automatically regenerate the source files every 23 hours. 30 | ``` 31 | docker run --name vuepress -v /host/vuepress/files/:/root/src/:rw -v /host/vuepress/output/:/root/html/:rw -d blasteh/vuepress 32 | ``` 33 | 34 | ## Github example: 35 | This will pull from the repo before generating the files. 36 | ``` 37 | docker run --name vuepress -v /host/vuepress/files/:/root/src/:rw -v /host/vuepress/output/:/root/html/:rw -d -e GITHUB_REPO=github.com/blastehh/vuepress-docker.git blasteh/vuepress 38 | ``` 39 | 40 | ## Github example with a [Personal access token](https://github.com/settings/tokens): 41 | This will pull from a private repo before generating the files. 42 | ``` 43 | docker run --name vuepress -v /host/vuepress/files/:/root/src/:rw -v /host/vuepress/output/:/root/html/:rw -d -e GITHUB_REPO=github.com/blastehh/vuepress-docker.git -e GITHUB_TOKEN=TOKENHERE blasteh/vuepress 44 | ``` 45 | 46 | ## Github with hooks example: 47 | This will listen for a webhook, and then pull from a private repo before generating the files. 48 | Trigger the hook via `http://:9000/hooks/vuepress-webhook` 49 | ``` 50 | docker run --name vuepress -v /host/vuepress/files/:/root/src/:rw -v /host/vuepress/output/:/root/html/:rw -d -p 9000:9000 -e USE_HOOK=1 -e GITHUB_REPO=github.com/blastehh/vuepress-docker.git -e GITHUB_TOKEN=TOKENHERE blasteh/vuepress 51 | ``` -------------------------------------------------------------------------------- /vuepress-webhook.sh: -------------------------------------------------------------------------------- 1 | #!/bin/ash 2 | set -eo pipefail 3 | 4 | if [ -n "$GITHUB_REPO" ]; then 5 | mkdir -p /root/html 6 | cd /root/src 7 | rm -rf ..?* .[!.]* * 8 | if [ -n "$GITHUB_TOKEN" ]; then 9 | git clone https://$GITHUB_TOKEN@$GITHUB_REPO .; git pull 10 | else 11 | git clone https://$GITHUB_REPO .; git pull 12 | fi 13 | 14 | vuepress build || (echo "Build failed. Aborting!"; exit 1) 15 | echo "Copying files..." 16 | rsync -q -r --delete .vuepress/dist/ /root/html/ 17 | echo "Done!" 18 | if [ -n "$GITHUB_PUSH_REPO" ]; then 19 | if [ -n "$GITHUB_PUSH_TOKEN" ]; then 20 | PUSH_TOKEN=$GITHUB_PUSH_TOKEN 21 | else 22 | if [ -z "$GITHUB_TOKEN" ]; then 23 | echo "No tokens set for pushing." 24 | exit 1 25 | fi 26 | PUSH_TOKEN=$GITHUB_TOKEN 27 | fi 28 | echo "Pushing to Github..." 29 | cd .vuepress/dist 30 | git init 31 | git add -A 32 | git config --global user.email "vuepress@autobuild.local" 33 | git config --global user.name "Vuepress Autobuild" 34 | git commit -m 'Auto Deploy' 35 | git remote add origin https://$PUSH_TOKEN@$GITHUB_PUSH_REPO 36 | git push -f origin master 37 | fi 38 | else 39 | sh /generate.sh 40 | fi --------------------------------------------------------------------------------