Skip to content

Commit

Permalink
Adding shell for alpine build, minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
klakegg committed May 27, 2018
1 parent edfdbf0 commit 9e8e83f
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
*.iml
target
target
37 changes: 28 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:
Expand All @@ -63,7 +68,7 @@ Normal build:
Run server:
```
```yaml
server:
image: klakegg/hugo:0.41
command: server
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-alpine → alpine/Dockerfile-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions alpine/files/run.sh
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions alpine/files/shell.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF > /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
45 changes: 45 additions & 0 deletions alpine/hooks/post_push
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Dockerfile-busybox → busybox/Dockerfile-busybox
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions busybox/hooks/post_push
Original file line number Diff line number Diff line change
@@ -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
66 changes: 0 additions & 66 deletions hooks/post_push

This file was deleted.

0 comments on commit 9e8e83f

Please sign in to comment.