Skip to content

Commit

Permalink
Support multi-repo container building
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-linaro committed Aug 14, 2019
1 parent ded21df commit 7c6c0bb
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Text files to normalise to LF line endings
* text=auto
# `man 5 .gitattributes`
*.css text
*.html text
*.json text
*.md text
*.sh text
*.xml text
*.yml text

# Binary files to not modify on check-in
# Images
*.ico binary
*.jpg binary
*.png binary
# Fonts
*.eot binary
*.ttf binary
*.woff binary
*.woff2 binary
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.asset-cache
.sass-cache
Gemfile.lock
staging.96boards.org
production.96boards.org
merged_sources
7 changes: 7 additions & 0 deletions .vscode/settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"diffEditor.ignoreTrimWhitespace": false,
"files.eol": "\n",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true
}
5 changes: 5 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build-site.sh @pcolmer @morancj
check-links.sh @pcolmer @morancj
CODEOWNERS @pcolmer @morancj
Gemfile @pcolmer @morancj
manifest.json @pcolmer @morancj
86 changes: 86 additions & 0 deletions build-site.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

check_multi_repo() {
# A multi-repo site is defined by the presence of manifest.json.
#
# If that file exists, we look for the tags in the file, which
# specifies the env var names that must be used to tell this
# script where a local copy of that repo can be found.
#
# We then build up a list of mounts for Docker so that it can
# access those repo copies.
DOCKER_MOUNTS=""
if [ ! -f "manifest.json" ]; then
return
fi
#
# Get the tags from the file.
declare -a tags
tags=($(grep \"tag\" manifest.json | cut -d':' -f2))
tag_count="${#tags[@]}"
if [ "$tag_count" == 0 ]; then
echo "Cannot find repo tags in manifest file."
exit 1
fi
#
# Do any of them exist as variables that point to directories?
for ((i=0; i < tag_count; i++))
do
# Need to strip extraneous chars off the tag string
tag="${tags[$i]}"
# Strip the leading " and the trailing ",
tag="${tag:1:-3}"
# Does that tag name exist as a variable and have a value?
tag_val="${!tag}"
if [ "$tag_val" != "" ]; then
# Does the value point to a directory?
if [ -d "$tag_val" ]; then
# Construct a Docker mount command
DOCKER_MOUNTS="$DOCKER_MOUNTS -v $tag_val:/$tag"
fi
fi
done
}

check_environment_variables() {
if [ -z "$JEKYLLSITEBUILD" ]; then
export JEKYLLSITEBUILD=latest
fi
if [ -z "$JEKYLL_ENV" ]; then
export JEKYLL_ENV=staging
fi
if [ "$JEKYLL_ACTION" = "serve" ]; then
PORTS="-p 4000:4000"
else
PORTS=""
fi
}

check_interactive_running() {
# Are we running interactively or via Bamboo?
if [ -t 1 ]; then
INTER="-i"
else
INTER=""
fi
}

check_multi_repo
check_environment_variables
check_interactive_running

docker run \
--cap-drop ALL \
--rm \
-t \
$INTER \
$PORTS \
-e JEKYLL_ACTION \
-e JEKYLL_ENV \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
"$DOCKER_MOUNTS" \
-u "$(id -u)":"$(id -g)" \
-v "$(pwd)":/srv/source \
linaroits/jekyllsitebuild:"$JEKYLLSITEBUILD" \
build-site.sh "$@"
37 changes: 37 additions & 0 deletions check-links.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
#
# Calls the link checker container to run the tool against the current directory.
#
# The script is slightly more complicated that it could otherwise be because the
# parameters to the tool can reference files and these will typically be in the
# directory above the current directory, so we have to volume-map the parent
# directory and tell the tool to check *this* directory.

DIRNAME="$(basename "$(pwd)")"
PARENT="$(dirname "$(readlink -f .)")"

if [ -z "$LINKCHECK" ]; then
LINKCHECK=latest
fi

# Make sure that the script is not in the current directory. The output from Jekyll
# should be in a sub-directory of the git repository.
SCRIPTDIR="$(dirname "$(readlink -f "$0")")"
if [ "$SCRIPTDIR" == "$(pwd)" ]; then
echo "Script is being run incorrectly. Go into the built site directory and"
echo "then run:"
echo
echo "../check-links.sh"
exit 1
fi

docker run \
--cap-drop ALL \
--rm \
-t \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-u "$(id -u)":"$(id -g)" \
-v "$PARENT":/srv \
linaroits/linkcheck:"$LINKCHECK" \
-d "$DIRNAME" "$@"
18 changes: 18 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"site_dirs": [
"staging.96boards.org",
"production.96boards.org"
],
"repos": [
{
"tag": "NSBREPO1",
"url": "https://github.com/96boards/website.git",
"dir": "/"
},
{
"tag": "NSBREPO2",
"url": "https://github.com/96boards/documentation.git",
"dir": "/_documentation"
}
]
}

0 comments on commit 7c6c0bb

Please sign in to comment.