diff --git a/.gitignore b/.gitignore index e5aa5b3c..5231862f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .idea *.iml -target \ No newline at end of file +target diff --git a/README.md b/README.md index 9c963633..bdcf7879 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,8 @@ Looking for older tags? Please see the [complete list of tags](https://github.co ## Using image -This image does not try to do any fancy. Users may use Hugo just as they are used to. +This image does not try to do any fancy. +Users may use Hugo just as they are used to. The good practice of having a separate output folder is part of the image. @@ -42,18 +43,22 @@ The good practice of having a separate output folder is part of the image. Normal build: -```docker run --rm -it -v $(pwd):/src -v $(pwd)/output:/target klakegg/hugo:0.41``` +``` +docker run --rm -it -v $(pwd):/src -v $(pwd)/output:/target klakegg/hugo:0.41 +``` Run server: -```docker run --rm -it -v $(pwd):/src -p 1313:1313 klakegg/hugo:0.41 server``` +``` +docker run --rm -it -v $(pwd):/src -p 1313:1313 klakegg/hugo:0.41 server +``` ### docker-compose Normal build: -``` +```yaml build: image: klakegg/hugo:0.41 volumes: @@ -63,7 +68,7 @@ Normal build: Run server: -``` +```yaml server: image: klakegg/hugo:0.41 command: server @@ -74,14 +79,26 @@ Run server: ``` +## Hugo shell + +A Hugo shell is made available in the Alpine images (including Asciidoctor image). +Initiating the shell will trigger installation of bash and configuration of autocomplete with Hugo support. + +To get into a shell for your site: + +``` +docker run --rm -it -v $(pwd):/src klakegg/hugo:0.41-alpine shell +``` + + ## Using a ONBUILD image The onbuild images adds content of the folder of your Dockerfile into `/src` and builds to the `/onbuild` folder. Example Dockerfile for your project where the site is made into a nginx image (Docker 17.05-ce or newer): -``` -FROM klakegg/hugo:onbuild AS hugo +```Dockerfile +FROM klakegg/hugo:0.41-onbuild AS hugo FROM nginx COPY --from=hugo /onbuild /usr/share/nginx/html @@ -94,11 +111,13 @@ Those wanting to override entrypoint in the image may easily do so. On command line using `--entrypoint`: -```docker run --rm -it -v $(pwd):/src -v $(pwd)/output:/src/public --entrypoint hugo klakegg/hugo:0.41``` +``` +docker run --rm -it -v $(pwd):/src -v $(pwd)/output:/src/public --entrypoint hugo klakegg/hugo:0.41 +``` In docker-compose using `entrypoint`: -``` +```yaml build: image: klakegg/hugo:0.41 entrypoint: hugo diff --git a/Dockerfile-alpine b/alpine/Dockerfile-alpine similarity index 95% rename from Dockerfile-alpine rename to alpine/Dockerfile-alpine index 62738ed0..af35c319 100644 --- a/Dockerfile-alpine +++ b/alpine/Dockerfile-alpine @@ -14,7 +14,7 @@ ENV HUGO_BIND="0.0.0.0" \ HUGO_DESTINATION="/target" COPY --from=fetch /hugo /bin/hugo -COPY run.sh /run.sh +COPY files / EXPOSE 1313 diff --git a/Dockerfile-alpine-onbuild b/alpine/Dockerfile-alpine-onbuild similarity index 100% rename from Dockerfile-alpine-onbuild rename to alpine/Dockerfile-alpine-onbuild diff --git a/Dockerfile-asciidoctor b/alpine/Dockerfile-asciidoctor similarity index 100% rename from Dockerfile-asciidoctor rename to alpine/Dockerfile-asciidoctor diff --git a/Dockerfile-asciidoctor-onbuild b/alpine/Dockerfile-asciidoctor-onbuild similarity index 100% rename from Dockerfile-asciidoctor-onbuild rename to alpine/Dockerfile-asciidoctor-onbuild diff --git a/alpine/files/run.sh b/alpine/files/run.sh new file mode 100644 index 00000000..7fe547ea --- /dev/null +++ b/alpine/files/run.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +case "$1" in + + # Commands from hugo + + "benchmark") + hugo $@ + ;; + + "config") + hugo $@ + ;; + + "convert") + hugo $@ + ;; + + "env") + hugo $@ + ;; + + "gen") + hugo $@ + ;; + + "help") + hugo $@ + ;; + + "import") + hugo $@ + ;; + + "list") + hugo $@ + ;; + + "new") + hugo $@ + ;; + + "server") + hugo server --bind=$HUGO_BIND $(echo $* | sed "s:^server::") + ;; + + "undraft") + hugo $@ + ;; + + "version") + hugo $@ + ;; + + # Commands special to docker image + + "shell") + sh /shell.sh + ;; + + # Default build command + + *) + hugo $@ --destination=$HUGO_DESTINATION + ;; + +esac diff --git a/alpine/files/shell.sh b/alpine/files/shell.sh new file mode 100644 index 00000000..14c597cd --- /dev/null +++ b/alpine/files/shell.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# Install bash +apk --no-cache add bash bash-completion + +# Setting up autocomplete for hugo +mkdir /etc/bash_completion.d +hugo gen autocomplete > /dev/null + +# Creating .bashrc +cat < /root/.bashrc +PS1="\e[1;32mhugo\e[m:\e[1;34m\w\e[m\$ " +HOME=/src + +alias hugo="sh /run.sh" +alias h="hugo" + +. /usr/share/bash-completion/bash_completion +EOF + +# Notify user +echo "Shell ready." +echo + +# Start bash +bash diff --git a/alpine/hooks/post_push b/alpine/hooks/post_push new file mode 100644 index 00000000..b182f754 --- /dev/null +++ b/alpine/hooks/post_push @@ -0,0 +1,45 @@ +#!/bin/bash + +if [ "$SOURCE_BRANCH" = "master" ]; then + exit +fi + +# Tag: alpine +docker tag $IMAGE_NAME klakegg/hugo:alpine + +# Tag: [version]-alpine +docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_BRANCH-alpine +docker push $DOCKER_REPO:$SOURCE_BRANCH-alpine + + +# Generate Alpine onbuild image + +# Tag: alpine-onbuild +docker build -t $DOCKER_REPO:alpine-onbuild -f Dockerfile-alpine-onbuild . +docker push $DOCKER_REPO:alpine-onbuild + +# Tag: [version]-alpine-onbuild +docker tag $DOCKER_REPO:alpine-onbuild $DOCKER_REPO:$SOURCE_BRANCH-alpine-onbuild +docker push $DOCKER_REPO:$SOURCE_BRANCH-alpine-onbuild + + +# Generate image for Asciidoctor + +# Tag: asciidoctor +docker build -t $DOCKER_REPO:asciidoctor -f Dockerfile-asciidoctor . +docker push $DOCKER_REPO:asciidoctor + +# Tag: [version]-asciidoctor +docker tag $DOCKER_REPO:asciidoctor $DOCKER_REPO:$SOURCE_BRANCH-asciidoctor +docker push $DOCKER_REPO:$SOURCE_BRANCH-asciidoctor + + +# Generate Asciidoctor onbuild image + +# Tag: asciidoctor-onbuild +docker build -t $DOCKER_REPO:asciidoctor-onbuild -f Dockerfile-asciidoctor-onbuild . +docker push $DOCKER_REPO:asciidoctor-onbuild + +# Tag: [version]-asciidoctor-onbuild +docker tag $DOCKER_REPO:asciidoctor-onbuild $DOCKER_REPO:$SOURCE_BRANCH-asciidoctor-onbuild +docker push $DOCKER_REPO:$SOURCE_BRANCH-asciidoctor-onbuild diff --git a/Dockerfile-busybox b/busybox/Dockerfile-busybox similarity index 95% rename from Dockerfile-busybox rename to busybox/Dockerfile-busybox index d7b44ae6..cdbb818d 100644 --- a/Dockerfile-busybox +++ b/busybox/Dockerfile-busybox @@ -14,7 +14,7 @@ ENV HUGO_BIND="0.0.0.0" \ HUGO_DESTINATION="/target" COPY --from=fetch /hugo /bin/hugo -COPY run.sh /run.sh +COPY files / EXPOSE 1313 diff --git a/Dockerfile-busybox-onbuild b/busybox/Dockerfile-busybox-onbuild similarity index 100% rename from Dockerfile-busybox-onbuild rename to busybox/Dockerfile-busybox-onbuild diff --git a/run.sh b/busybox/files/run.sh similarity index 100% rename from run.sh rename to busybox/files/run.sh diff --git a/busybox/hooks/post_push b/busybox/hooks/post_push new file mode 100644 index 00000000..e234d865 --- /dev/null +++ b/busybox/hooks/post_push @@ -0,0 +1,36 @@ +#!/bin/bash + +if [ "$SOURCE_BRANCH" = "master" ]; then + exit +fi + +# Tag: latest +docker tag $IMAGE_NAME $DOCKER_REPO:latest +docker push $DOCKER_REPO:latest + +# Tag: [version] +docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_BRANCH +docker push $DOCKER_REPO:$SOURCE_BRANCH + +# Tag: [version]-busybox +docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_BRANCH-busybox +docker push $DOCKER_REPO:$SOURCE_BRANCH-busybox + + +# Generate Busybox onbuild image + +# Tag: busybox-onbuild +docker build -t $DOCKER_REPO:busybox-onbuild -f Dockerfile-busybox-onbuild . +docker push $DOCKER_REPO:busybox-onbuild + +# Tag: [version]-busybox-onbuild +docker tag $DOCKER_REPO:busybox-onbuild $DOCKER_REPO:$SOURCE_BRANCH-busybox-onbuild +docker push $DOCKER_REPO:$SOURCE_BRANCH-busybox-onbuild + +# Tag: [version]-onbuild +docker tag $DOCKER_REPO:busybox-onbuild $DOCKER_REPO:$SOURCE_BRANCH-onbuild +docker push $DOCKER_REPO:$SOURCE_BRANCH-onbuild + +# Tag: onbuild +docker tag $DOCKER_REPO:busybox-onbuild $DOCKER_REPO:onbuild +docker push $DOCKER_REPO:onbuild diff --git a/hooks/post_push b/hooks/post_push deleted file mode 100644 index 32cfe4fe..00000000 --- a/hooks/post_push +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -if [ "$SOURCE_BRANCH" = "master" ]; then - exit -fi - -case "$DOCKER_TAG" in - - "busybox") - docker tag $IMAGE_NAME $DOCKER_REPO:latest - docker push $DOCKER_REPO:latest - - docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_BRANCH - docker push $DOCKER_REPO:$SOURCE_BRANCH - - docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_BRANCH-busybox - docker push $DOCKER_REPO:$SOURCE_BRANCH-busybox - - # Generate Busybox onbuild image - - docker build -t $DOCKER_REPO:busybox-onbuild -f Dockerfile-busybox-onbuild . - docker push $DOCKER_REPO:busybox-onbuild - - docker tag $DOCKER_REPO:busybox-onbuild $DOCKER_REPO:$SOURCE_BRANCH-busybox-onbuild - docker push $DOCKER_REPO:$SOURCE_BRANCH-busybox-onbuild - - docker tag $DOCKER_REPO:busybox-onbuild $DOCKER_REPO:$SOURCE_BRANCH-onbuild - docker push $DOCKER_REPO:$SOURCE_BRANCH-onbuild - - docker tag $DOCKER_REPO:busybox-onbuild $DOCKER_REPO:onbuild - docker push $DOCKER_REPO:onbuild - ;; - - "alpine") - docker tag $IMAGE_NAME klakegg/hugo:alpine - - docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_BRANCH-alpine - docker push $DOCKER_REPO:$SOURCE_BRANCH-alpine - - # Generate Alpine onbuild image - - docker build -t $DOCKER_REPO:alpine-onbuild -f Dockerfile-alpine-onbuild . - docker push $DOCKER_REPO:alpine-onbuild - - docker tag $DOCKER_REPO:alpine-onbuild $DOCKER_REPO:$SOURCE_BRANCH-alpine-onbuild - docker push $DOCKER_REPO:$SOURCE_BRANCH-alpine-onbuild - - # Generate image for Asciidoctor - - docker build -t $DOCKER_REPO:asciidoctor -f Dockerfile-asciidoctor . - docker push $DOCKER_REPO:asciidoctor - - docker tag $DOCKER_REPO:asciidoctor $DOCKER_REPO:$SOURCE_BRANCH-asciidoctor - docker push $DOCKER_REPO:$SOURCE_BRANCH-asciidoctor - - # Generate Asciidoctor onbuild image - - docker build -t $DOCKER_REPO:asciidoctor-onbuild -f Dockerfile-asciidoctor-onbuild . - docker push $DOCKER_REPO:asciidoctor-onbuild - - docker tag $DOCKER_REPO:asciidoctor-onbuild $DOCKER_REPO:$SOURCE_BRANCH-asciidoctor-onbuild - docker push $DOCKER_REPO:$SOURCE_BRANCH-asciidoctor-onbuild - - ;; - -esac