Skip to content

Commit

Permalink
Add makefile and docker build support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Killen committed Nov 9, 2018
1 parent f911a57 commit 93ef0a3
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 14 deletions.
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM alpine:latest
ARG HUGO_VERSION=0.49.2

RUN apk add --no-cache \
bash \
git \
grep \
rsync \
sed

RUN wget -qO- https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_linux-64bit.tar.gz | \
tar xvz hugo -C /usr/local/bin \
&& mkdir -p /src \
&& addgroup -Sg 1000 hugo \
&& adduser -Sg hugo -u 1000 -g 1000 -h /src hugo

WORKDIR /src

EXPOSE 1313

USER hugo:hugo

SHELL [ "/bin/bash", "-c" ]
69 changes: 69 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
BUILD_DIR := $(join $(DIR), build)
CONTENT_DIR := $(join $(DIR), content)
DOCKER ?= docker
DOCKER_IMAGE := k8s-contrib-site-hugo
DOCKER_RUN := $(DOCKER) run --rm -it -v $(DIR):/src
HUGO_VERSION := 0.49.2

.DEFAULT_GOAL := help

.PHONY: targets docker-targets
targets: help render serve clean-all clean-build clean-content
docker-targets: docker-image docker-build docker-serve docker-gen-site docker-gen-site-ci

help: ## Show this help text.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

render: ## Build Hugo site.
hugo

server: ## Start Hugo webserver.
hugo server --ignoreCache --disableFastRender

gen-site: ## Generate Contributor Site content.
./gen-site.sh

gen-site-ci: ## Generate Contributor Site content as if called from CI system.
CI_BUILD=true ./gen-site.sh

docker-image: ## Build container imagefor use with docker-* targets.
$(DOCKER) build . -t $(DOCKER_IMAGE) --build-arg HUGO_VERSION=$(HUGO_VERSION)

docker-render: ## Build Hugo site executing within a container (equiv to render).
$(DOCKER_RUN) $(DOCKER_IMAGE) hugo

docker-server: ## Start Hugo webserver executing within a container (equiv to server).
$(DOCKER_RUN) -p 1313:1313 $(DOCKER_IMAGE) hugo server --watch --bind 0.0.0.0

docker-gen-site: ## Generate Contributor Site content executing within a container (equiv to gen-site).
$(DOCKER_RUN) $(DOCKER_IMAGE) ./gen-site.sh

docker-gen-site-ci: ## Generate Contributor Site content as if called from CI system (equiv to gen-site-ci).
$(DOCKER_RUN) -e CI_BUILD=true $(DOCKER_IMAGE) ./gen-site.sh

clean-all: clean-build clean-content clean-docker ## Executes clean-build, clean-content, and clean-docker.

clean-build: ## Cleans build dependnecies.
[ -d $(BUILD_DIR) ] && rm -rf $(BUILD_DIR)/*

clean-content: ## Cleans generated content.
[ -d $(CONTENT_DIR) ] && rm -rf $(CONTENT_DIR)/*

clean-docker: ## Removes docker image if found.
$(DOCKER) rmi $(DOCKER_IMAGE)
36 changes: 28 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,39 @@ built with `hugo`. If it is built, the default location is `build/public`.

# Building the Site

The Kubernetes Contributor Site is built with [Hugo][hugo]. For instructions
on installing and general usage, see the [Hugo Documentation][hugo-docs].
## Using Docker

Once Hugo is installed, clone the repository locally. Then run the
[`gen-site.sh`](gen-site.sh), script to pull down the [kubernetes/community][kcommunity]
repository and generate the site content.
The easiest and most cross-system compatible method of building the Contributor
Site is to use [Docker][docker]. To begin, create the docker image to be used
with generating the site by executing `make docker-image`.

After the script completes, the site can be previewed by executing `hugo serve`
When image building is complete, the site may be generated by running
`make docker-gen-site`.

After the Contributor Site content is generated, it may be previewed with the
`make docker-server` command.

If satisfied with your changes, the site can be fully rendered with the
`make docker-render` command; outputting the site to the `build/public`
directory.


## Natively

For instructions on installing and general usage, see the
[Hugo Documentation][hugo-docs]. When complete, simply execute `make gen-site`;
to pull down the [kubernetes/community][kcommunity] repository and generate
the site content.

After the script completes, the site can be previewed by executing `make server`
from the project directory. If satisfied with your changes, the site can be
fully rendered with the `hugo` command to the `build/public` directory.
fully rendered with the `make render` command; outputting the site to the
`build/public` directory.

### Note to MAC Users
OSX by default ships with an outdated version of bash that does not support all
the functionality used by the site generator script. Bash can be safely updated
via [homebrew](https://brew.sh/). Once installed, execute the below commands to
via [homebrew][brew]. Once installed, execute the below commands to
install a newer version of bash.
```
$ brew install bash
Expand Down Expand Up @@ -103,6 +121,8 @@ Participation in the Kubernetes community is governed by the
[docdock]: https://github.com/vjeantet/hugo-theme-docdock
[kcommunity]: https://git.k8s.io/community
[frontmatter]: https://gohugo.io/content-management/front-matter/
[docker]: https://www.docker.com/get-started
[brew]: https://brew.sh/
[sig-contribex]: https://github.com/kubernetes/community/blob/master/sig-contributor-experience/README.md
[sig-contribex-slack]: http://slack.k8s.io/#sig-contribex
[sig-contribex-list]: https://groups.google.com/forum/#!forum/kubernetes-sig-contribex
Expand Down
8 changes: 4 additions & 4 deletions gen-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set -o nounset
set -o pipefail

readonly DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P)"
readonly HUGO_BUILD="${HUGO_BUILD:-false}"
readonly CI_BUILD="${CI_BUILD:-false}"
readonly KCOMMUNITY_REPO="${KCOMMUNITY_REPO:-"https://github.com/kubernetes/community.git"}"
readonly KCOMMUNITY_SRC_DIR="${KCOMMUNITY_SRC_DIR:-"$DIR/build/community"}"
readonly CONTENT_DIR="$DIR/content"
Expand All @@ -36,7 +36,7 @@ readonly KCOMMUNITY_EXCLUDE_LIST="$DIR/kcommunity_exclude.list"
# directory to ensure there are no left over artifacts from previous build.
init_content() {
mkdir -p "$CONTENT_DIR"
if [[ "$HUGO_BUILD" = true && \
if [[ "$CI_BUILD" = true && \
-n "$(find "$CONTENT_DIR" -mindepth 1 -not -path "*.gitignore")" ]]; then
echo "Clearing Content Directory."
rm -r "${CONTENT_DIR:?}/"*
Expand All @@ -52,7 +52,7 @@ init_src() {
if [[ ! -d "$2" ]]; then
echo "Cloning $1"
git clone "$1" "$2"
elif [[ "$HUGO_BUILD" = true && \
elif [[ "$CI_BUILD" = true && \
$(git -C "$2" rev-parse --show-toplevel) == "$2" ]]; then
echo "Syncing with latest content from master."
git -C "$2" checkout .
Expand Down Expand Up @@ -393,7 +393,7 @@ main() {
sync_managed_content

echo "Completed Content Update."
if [[ "$HUGO_BUILD" = true ]]; then
if [[ "$CI_BUILD" = true ]]; then
echo "Building Site with: hugo --cleanDestinationDir --source \"$DIR\" $*"
hugo --source "$DIR" "$@"
fi
Expand Down
4 changes: 2 additions & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ publish = "build/public"
command = "python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);' && ./gen-site.sh"

[build.environment]
HUGO_VERSION = "0.49"
HUGO_BUILD = "true"
HUGO_VERSION = "0.49.2"
CI_BUILD = "true"

[context.production.environment]
HUGO_ENV = "production"
Expand Down

0 comments on commit 93ef0a3

Please sign in to comment.