Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Improve website with automation and documentation #15

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
language: node_js
node_js:
- 13

env:
global:
- PAGES_FQDN="pages.github.ibm.com"

# services:
# - docker

# install:
# - curl -sL https://ibm.biz/idt-installer | bash

before_script:
- npm install
- |
if [[ ${TRAVIS_BRANCH} == "dev" ]]; then
sed -i.bkp 's|/att-cloudnative/ibmcloud-pattern-guide|/att-cloudnative/ibmcloud-pattern-guide-staging|g' gatsby-config.js
fi
if [[ ${TRAVIS_BRANCH} == "x" ]]; then
sed -i.bkp 's|/att-cloudnative/ibmcloud-pattern-guide|/cloud-enterprise-examples|g' gatsby-config.js
fi

script:
- npm run build

# after_success:
# - |
# if [[ ${TRAVIS_BRANCH} != "dev" && ${TRAVIS_BRANCH} != "master" ]]; then
# ibmcloud login -r 'us-south' --apikey $IC_API_KEY
# ibmcloud cr login
# bash scripts/container.sh --build --deploy
# fi

before_deploy:
- mkdir -p release/${TRAVIS_BRANCH}
- mv public release/${TRAVIS_BRANCH}/public
- echo "Built on ${TRAVIS_BRANCH}" >> release/${TRAVIS_BRANCH}/public/.source_branch

deploy:
- provider: pages
skip_cleanup: true
github_url: github.ibm.com
github_token: $GITHUB_TOKEN
keep_history: false
local_dir: release/${TRAVIS_BRANCH}/public
on:
branch: master

- provider: pages
skip_cleanup: true
github_url: github.ibm.com
github_token: $GITHUB_TOKEN
repo: att-cloudnative/ibmcloud-pattern-guide-staging
keep_history: false
local_dir: release/${TRAVIS_BRANCH}/public
on:
branch: dev
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# IBM Cloud

[![Build Status](https://travis.ibm.com/att-cloudnative/ibmcloud-pattern-guide.svg?token=7NEaPtW1LU1ncUWL18Tz&branch=dev)](https://travis.ibm.com/att-cloudnative/ibmcloud-pattern-guide)

## Pattern Guide

This IBM Cloud pattern guide, can be used to help define an outcome aligned to core certification patterns required to demonstrate key capabilities from IBM Cloud and ATT project.

The rendered Learning Journey can be viewed here - [IBM Cloud Pattern Guide](https://pages.github.ibm.com/att-cloudnative/ibmcloud-pattern-guide/)

To update and manage the IBM Cloud Pattern Guide follow these steps.

### Clone the repository

```bash
git clone
```

### Install dependencies

```bash
npm install
```

This will install all the dependencies necessary to run the environment in development mode
and to build and publish the content.

Most notably, this project depends on the following:
(documented in `package.json`):

```bash
npm install -g gatsby
npm install -g gh-pages
```

Having problems installing `node-gyp`? Check [here](https://github.com/nodejs/node-gyp#installation) for some instructions and [here](https://github.com/nodejs/node-gyp/blob/master/macOS_Catalina.md) if you are on macOS 10.15.

### Write content

The content of the Learning Journey is authored through a hybrid of Markdown and
React. The content
itself is primarily provided using Markdown. React components are sprinkled into the Markdown to
provide for a richer and more interactive set of components in the published guide.

To render the content within your local development environment, run the following:

```bash
npm run build
npm run dev
```

### Publish Content

Currently, the content is published to the GitHub pages site through the `gh-pages` branch
using the `gh-pages` npm module. All of the details for handling the publishing are covered within
the deploy script. The deploy can be run using the following:

```bash
npm run build
npm run deploy
```

The result of the `deploy` can be viewed here -[IBM Cloud Pattern Guide](https://pages.github.ibm.com/att-cloudnative/ibmcloud-pattern-guide/)

**Note:** There is a time delay between when the deploy process completes and when the
content is available on the published site.

### Gatsby and Carbon

Get started using with the Gatsby Carbon theme which includes all configuration you might need to build a
beautiful site inspired by the [Carbon Design System](https://www.carbondesignsystem.com).

## Resources

- [Getting Started](https://gatsby-theme-carbon.now.sh/getting-started)
- [Guides](https://gatsby-theme-carbon.now.sh/guides/configuration)
- [Components](https://gatsby-theme-carbon.now.sh/components/markdown)
- [Demo](https://gatsby-theme-carbon.now.sh/demo)
- [Gallery](https://gatsby-theme-carbon.now.sh/gallery)
- [Contributions](https://gatsby-theme-carbon.now.sh/contributions)
File renamed without changes.
3 changes: 3 additions & 0 deletions website/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.cache/
node_modules/
public/
19 changes: 19 additions & 0 deletions website/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:13-alpine as build

WORKDIR /app
ADD . ./
RUN npm install
RUN node_modules/.bin/gatsby build

FROM alpine

COPY --from=build /app/public /pub

ADD ./scripts/nginx-boot.sh /sbin/nginx-boot

RUN chmod +x /sbin/nginx-boot && \
apk --update add nginx bash && \
rm -fR /var/cache/apk/*

CMD [ "/sbin/nginx-boot" ]
EXPOSE 80
108 changes: 108 additions & 0 deletions website/docker/scripts/container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash

if [[ -n $TRAVIS_BRANCH ]]; then
TAG="$(echo $TRAVIS_BRANCH | rev | cut -f1 -d/ | rev)-$TRAVIS_BUILD_NUMBER"
else
BRANCH=$(git rev-parse --abbrev-ref HEAD)
TAG="$(echo $BRANCH | rev | cut -f1 -d/ | rev)-0"
fi

PORT="8080"
NAME="att-cloudnative/ibmcloud-pattern-guide"

IMAGE="us.icr.io/$NAME:$TAG"

login() {
if [[ "$1" == icr ]]; then
ibmcloud cr login
else
docker login $1
fi
}

build() {
docker build -t $IMAGE .
[[ $? -eq 0 ]] && echo "[ OK ] the docker image '$IMAGE' have been built locally"
}

deploy() {
docker push $IMAGE
[[ $? -ne 0 ]] && return

# ibmcloud cr image-list
echo "[ OK ] the docker image '$IMAGE' have been deployed to IBM Cloud Registry"
echo "[ INFO ] pull the image with tag: $TAG"
echo "[ INFO ] or execute the command: docker run --rm -p $PORT:80 $IMAGE"
}

run() {
if [[ $1 == debug ]]; then
IT="-it "
echo "[ INFO ] exit from the container with: exit"
fi
if [[ -n $2 ]]; then
IMAGE=$2
echo "[ INFO ] running docker image '$IMAGE'"
fi
echo "[ INFO ] serving the site at: http://localhost:$PORT"
docker run $IT --rm -p $PORT:80 $IMAGE
}

clean() {
docker image rm $IMAGE
[[ $? -eq 0 ]] && echo "[ OK ] the docker image '$IMAGE' have been deleted locally"
}

if [[ $# -lt 1 ]]; then
echo "USAGE:"
echo
echo "$0 ACTION [ACTION ACTION ...]"
echo
echo "ACTION:"
echo " --build | -b: build the container locally with the web site"
echo " --deploy | -d: deploy the container to the IBM Cloud Registry"
echo " --deploy-to REGISTRY: deploy the container to the given Docker Registry"
echo " --run | -r: runs the container to access the web site"
echo " --run-tag | -t TAG: runs the container from the IBM Cloud Registry with the given tag"
echo " --debug: run the container and open a shell on it so you can debug the behaviour of the HTTP server"
echo " --all: do build, deploy and run"
echo " --clean: removes the local docker image"
echo
exit 0
fi

while (( "$#" )); do
case $1 in
--build | -b)
build
;;
--login-icr)
login icr
;;
--deploy | -d)
deploy
;;
--deploy-to)
deploy
;;
--run | -r)
run
;;
--run-tag | -t)
run _ $2
shift
;;
--debug)
run debug
;;
--clean)
clean
;;
--all)
build
deploy
run
;;
esac
shift
done
117 changes: 117 additions & 0 deletions website/docker/scripts/nginx-boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash

# Check for variables
export CHARSET=${CHARSET:-utf-8}

export WORKER_CONNECTIONS=${WORKER_CONNECTIONS:-1024}
export HTTP_PORT=${HTTP_PORT:-80}
export NGINX_CONF=/etc/nginx/mushed.conf

export PUBLIC_PATH=${PUBLIC_PATH:-/pub}

export GZIP_TYPES=${GZIP_TYPES:-application/javascript application/x-javascript application/rss+xml text/javascript text/css image/svg+xml}
export GZIP_LEVEL=${GZIP_LEVEL:-6}

export CACHE_IGNORE=${CACHE_IGNORE:-html}
export CACHE_PUBLIC=${CACHE_PUBLIC:-ico|jpg|jpeg|png|gif|svg|js|jsx|css|less|swf|eot|ttf|otf|woff|woff2}
export CACHE_PUBLIC_EXPIRATION=${CACHE_PUBLIC_EXPIRATION:-1y}

if [ "$TRAILING_SLASH" = false ]; then
REWRITE_RULE="rewrite ^(.+)/+\$ \$1 permanent"
TRY_FILES="try_files \$uri \$uri/index.html =404"
else
REWRITE_RULE="rewrite ^([^.]*[^/])\$ \$1/ permanent"
TRY_FILES="try_files \$uri \$uri/ \$uri/index.html =404"
fi

if [ "$DISABLE_FILE_CACHE" != true ]; then
read -r -d '' FILE_CACHE <<'EOF'

## Cache open FD
open_file_cache max=10000 inactive=3600s;
open_file_cache_valid 7200s;
open_file_cache_min_uses 2;

EOF
fi

if [ -f /etc/nginx/server.conf ]; then
CUSTOM_SERVER_CONFIG=$(</etc/nginx/server.conf)
else
CUSTOM_SERVER_CONFIG=${CUSTOM_SERVER_CONFIG:-};
fi

# Build config
cat <<EOF > $NGINX_CONF
daemon off;
worker_processes 1;
user root;

events {
worker_connections $WORKER_CONNECTIONS;
}

http {
include mime.types;
default_type application/octet-stream;

keepalive_timeout 15;
autoindex off;
server_tokens off;
port_in_redirect off;
sendfile off;
tcp_nopush on;
tcp_nodelay on;

client_max_body_size 64k;
client_header_buffer_size 16k;
large_client_header_buffers 4 16k;

$FILE_CACHE

## Gzipping is an easy way to reduce page weight
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_types $GZIP_TYPES;
gzip_buffers 16 8k;
gzip_comp_level $GZIP_LEVEL;

access_log /dev/stdout;
error_log /dev/stderr error;

server {
listen $HTTP_PORT;
root $PUBLIC_PATH;

index index.html;
autoindex off;
charset $CHARSET;

error_page 404 /404.html;

location ~* \.($CACHE_IGNORE)$ {
add_header Cache-Control "no-store";
expires off;
}
location ~* \.($CACHE_PUBLIC)$ {
add_header Cache-Control "public";
expires +$CACHE_PUBLIC_EXPIRATION;
}

$REWRITE_RULE;

$TRY_FILES;

$CUSTOM_SERVER_CONFIG
}
}

EOF

[ "" != "$DEBUG" ] && cat $NGINX_CONF;

mkdir -p /run/nginx/
chown -R root:root /var/lib/nginx

exec nginx -c $NGINX_CONF