This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
[WIP] Initial setup for running the website in Docker #286
Open
mpetason
wants to merge
2
commits into
knative:main
Choose a base branch
from
mpetason:run-website-in-docker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM ubuntu:18.04 | ||
|
||
RUN apt-get update -y && apt-get install git wget -y | ||
|
||
RUN wget https://github.com/gohugoio/hugo/releases/download/v0.81.0/hugo_extended_0.81.0_Linux-64bit.deb | ||
RUN dpkg -i hugo_extended_0.81.0_Linux-64bit.deb | ||
|
||
RUN git clone --recurse-submodules https://github.com/knative/website.git | ||
RUN git clone https://github.com/knative/docs.git | ||
|
||
WORKDIR /website | ||
|
||
COPY processsourcefiles.sh scripts/processsourcefiles.sh | ||
COPY localbuild.sh scripts/localbuild.sh | ||
|
||
ENTRYPOINT ["/bin/bash", "scripts/localbuild.sh","-s","reload"] | ||
|
||
EXPOSE 1313 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# knative-docs-docker | ||
|
||
```bash | ||
git clone [email protected]:knative/website.git | ||
``` | ||
|
||
```bash | ||
cd website/docker | ||
``` | ||
|
||
```bash | ||
docker build -t {USER/knative-docs} . | ||
``` | ||
|
||
There are custom scripts that avoid deletion of this folder in processsourcefiles. If using the default version of the script (not in the Dockerfile image build) then it will delete the directory. **Test this out using a test directory you have cloned and change GOPATH to the test directory. (/home/user/testing/docs/docs)** | ||
|
||
Just Docs | ||
```bash | ||
docker run --name=knative-docs -d -v $GOPATH/src/github.com/knative.dev/docs/docs:/website/content/en/docs -p 9001:1313 USER/knative-docs:latest | ||
``` | ||
|
||
Docs and Blog | ||
```bash | ||
docker run --name=knative-docs -d -v $GOPATH/src/github.com/knative.dev/docs/docs:/website/content/en/docs -v $GOPATH/src/github.com/knative.dev/docs/blog:/website/content/en/blog -p 9001:1313 USER/knative-docs:latest | ||
``` | ||
|
||
This will run the service on port 9001, but you can pick any port you want. The container is listening on 1313. | ||
|
||
|
||
Diffs on script files (edited so that mounted volumes aren't deleted or copied over) | ||
|
||
``` | ||
$ diff localbuild.sh ../knative.dev/website/scripts/localbuild.sh | ||
153,157c153,157 | ||
< SERVER="server " | ||
< # if [ "${OPTARG}" = "reload" ]; then | ||
< # echo 'with live reload' | ||
< # LIVERELOAD=" --disableFastRender --renderToDisk" | ||
< # fi | ||
--- | ||
> SERVER="server $LIVERELOAD" | ||
> if [ "${OPTARG}" = "reload" ]; then | ||
> echo 'with live reload' | ||
> LIVERELOAD=" --disableFastRender --renderToDisk" | ||
> fi | ||
170c170 | ||
< exec hugo $SERVER --disableFastRender --baseURL "" --environment "$BUILDENVIRONMENT" --bind=0.0.0.0 --gc | ||
--- | ||
> hugo $SERVER --baseURL "" --environment "$BUILDENVIRONMENT" --gc | ||
178d177 | ||
< | ||
``` | ||
|
||
``` | ||
$ diff processsourcefiles.sh ../../knative.dev/website/scripts/processsourcefiles.sh | ||
11c11 | ||
< # rm -rf content/en | ||
--- | ||
> rm -rf content/en | ||
30c30 | ||
< # mv content/en/docs content/en/development | ||
--- | ||
> mv content/en/docs content/en/development | ||
70c70 | ||
< #cp -r ../docs content/en/ | ||
--- | ||
> cp -r ../docs content/en/ | ||
187d186 | ||
< | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
#!/bin/bash | ||
|
||
# Quit on error | ||
set -e | ||
|
||
############################################## | ||
# THIS FILE IS USED TO RUN LOCAL SITE BUILDS # | ||
############################################## | ||
|
||
# USAGE: | ||
# 1. Install Hugo: https://www.docsy.dev/docs/getting-started/#install-hugo | ||
# | ||
# 2. For Mac OSX: The script uses the `gnu` version of `sed`. To install `gnu-sed`, you use brew: | ||
# 1. Run `brew install gnu-sed` | ||
# 2. Add it to your `PATH`. For example, add the following line to your `~/.bash_profile`: | ||
# `PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"` | ||
# | ||
# 3. Install PostCSS. Needed to build the site locally. | ||
# https://www.docsy.dev/docs/getting-started/#install-postcss | ||
# | ||
# 4. Clone the knative/docs repo: | ||
# `git clone https://github.com/knative/docs.git` | ||
# | ||
# 5. Clone the knative/website repo, including the Docsy theme submodule: | ||
# `git clone --recurse-submodules https://github.com/knative/website.git` | ||
# | ||
# Note: These repos must be cloned into the same folder and use the same | ||
# names ('docs', 'website', 'community') | ||
# | ||
# 6. Optional: Clone the knative/community repo. | ||
# `git clone https://github.com/knative/community.git` | ||
# | ||
# 7. From the root of the knative/website clone, run: | ||
# `scripts/localbuild.sh` | ||
# | ||
# See all command options below (ie. build from your remote fork, etc). | ||
# | ||
# 8. If you change content in your knative/docs repo clone, you rebuild your local | ||
# site by stopping the localhost (CTRL C) and running `scripts/localbuild.sh` again. | ||
# | ||
# By default, the command locally runs a Hugo build of using your local knative/website and | ||
# knative/docs clones (including any local changes). | ||
# | ||
# All files from you local knative/docs clone are copied into the 'content' | ||
# folder of your knative/website repo clone, and then they are processed in the | ||
# same way that they are process on the Netlify host server. | ||
# | ||
# You can also build and preview changes from other remote Forks and Branches. | ||
# See details about optional settings and flags below. | ||
|
||
# Retrieve the default docs version | ||
source scripts/docs-version-settings.sh | ||
# Use default repo and branch from docs-version-settings.sh | ||
BRANCH="$DEFAULTBRANCH" | ||
FORK="$DEFAULTREPO" | ||
REPO="$DEFAULTORG" | ||
|
||
# Set local build default values | ||
BUILDENVIRONMENT="local" | ||
BUILDALLRELEASES="false" | ||
BUILDSINGLEBRANCH="false" | ||
PRBUILD="false" | ||
LOCALBUILD="true" | ||
|
||
# Default Hugo build options | ||
# disable Hugo server | ||
SERVER="" | ||
# disable live reload | ||
LIVERELOAD=" --watch=false --disableLiveReload" | ||
|
||
# OPTIONS: | ||
# | ||
# (1) Specify a remote repo fork, branch, or both, to build that content locally. | ||
# The specified repo and branch are cloned and built locally to allow you to | ||
# preview changes in remote forks and branches. | ||
# | ||
# USAGE: Append the -f repofork and/or the -b branchname to the command. | ||
# Example: | ||
# ./scripts/build.sh -f repofork -b branchname -s true | ||
# | ||
# (2) Run a complete local build of the knative.dev site. Clones all the content | ||
# from knative/docs repo, including all branches. | ||
# | ||
# USAGE: Append the -a true to the command. | ||
# Example: | ||
# ./scripts/build.sh -a true -s true | ||
# | ||
# Examples: | ||
# | ||
# - Default: Build local clone to static HTML (output to 'public' folder): | ||
# ./scripts/localbuild.sh | ||
# | ||
# - Locally build knative.dev: | ||
# ./scripts/localbuild.sh -a true | ||
# | ||
# - Run Hugo server (localhost): | ||
# | ||
# - Local clone build (-s true): | ||
# ./scripts/localbuild.sh -s true | ||
# | ||
# - Local clone build with live reload (-s reload): | ||
# - Useful for website changes only (doesn't work on docs) | ||
# ./scripts/localbuild.sh -s reload | ||
# | ||
# - Additional build options - build from remote Fork and Branch: | ||
# | ||
# - Build content from specified fork and branch: | ||
# - Build any branch from your fork or from someones in a PR | ||
# ./scripts/localbuild.sh -f REPO/FORK -b BRANCHNAME | ||
# | ||
# - Locally build a specific branch from knative/docs: | ||
# ./scripts/localbuild.sh -b BRANCHNAME | ||
# | ||
# - Combine other -s or -a flags. Example: | ||
# ./scripts/localbuild.sh -f my-docs-contributor-fork -a true -s reload | ||
# | ||
while getopts "f:b:a:s:" arg; do | ||
case "${arg}" in | ||
f) | ||
echo '--- BUILDING FROM ---' | ||
echo 'FORK:' "${OPTARG}" | ||
# Build remote content locally | ||
# Set the GitHub repo name of your knative/docs fork that you want built. | ||
# Example: myrepo/forkname | ||
FORK="${OPTARG}" | ||
# Retrieve content from remote repo | ||
BUILDSINGLEBRANCH="true" | ||
# Extract the repo name | ||
REPO=$(echo "$FORK" | sed -e 's/\.*\/.*//') | ||
;; | ||
b) | ||
echo 'USING BRANCH:' "${OPTARG}" | ||
# Build remote content locally | ||
# Set the branch name that you want built. | ||
BRANCH="${OPTARG}" | ||
# Retrieve content from remote repo branch | ||
BUILDSINGLEBRANCH="true" | ||
;; | ||
a) | ||
echo 'BUILDING ALL RELEASES FROM' "$FORK" | ||
# If 'true', all knative/docs branches are built to mimic a | ||
# "production" build. | ||
# REQUIRED: If you specify a fork ($FORK), all of the same branches | ||
# (with the same branch names) that are built in knative.dev must | ||
# also exist and be available in the that $FORK (ie, 'release-0.X'). | ||
# See scripts/docs-version-settings.sh for the list of the built branches. | ||
BUILDALLRELEASES="${OPTARG}" | ||
BUILDENVIRONMENT="production" | ||
BUILDSINGLEBRANCH="false" | ||
;; | ||
s) | ||
echo 'Running Hugo server' | ||
SERVER="server " | ||
# if [ "${OPTARG}" = "reload" ]; then | ||
# echo 'with live reload' | ||
# LIVERELOAD=" --disableFastRender --renderToDisk" | ||
# fi | ||
;; | ||
esac | ||
done | ||
|
||
# Create the require "content" folder | ||
mkdir -p content | ||
|
||
# Process the source files | ||
source scripts/processsourcefiles.sh | ||
|
||
# BUILD MARKDOWN | ||
# Start HUGO build | ||
exec hugo $SERVER --disableFastRender --baseURL "" --environment "$BUILDENVIRONMENT" --bind=0.0.0.0 --gc | ||
|
||
if [ -z "$SERVER" ]; then | ||
echo '' | ||
echo '********** DONE! **********' | ||
echo '' | ||
echo 'Static HTML files output to public/. Open public/index.html to view these files.' | ||
fi | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Rather than putting the script here, why not have a
.patch
file created by something like:This would allow you to use the
patch
command to apply the patch to the original files in the Docker build, and avoid needing to keep an extra copy of the scripts here with only a few lines changed.