From 56c5b03b6c087cd270605e95fd1f3aa48aba0add Mon Sep 17 00:00:00 2001 From: Johandry Amador Date: Thu, 13 Aug 2020 15:04:57 -0700 Subject: [PATCH 1/4] Docker image to pack & publish the website --- website/.dockerignore | 3 + website/docker/Dockerfile | 19 +++++ website/docker/scripts/container.sh | 108 +++++++++++++++++++++++++ website/docker/scripts/nginx-boot.sh | 117 +++++++++++++++++++++++++++ 4 files changed, 247 insertions(+) create mode 100644 website/.dockerignore create mode 100644 website/docker/Dockerfile create mode 100755 website/docker/scripts/container.sh create mode 100644 website/docker/scripts/nginx-boot.sh diff --git a/website/.dockerignore b/website/.dockerignore new file mode 100644 index 00000000..8ba25f47 --- /dev/null +++ b/website/.dockerignore @@ -0,0 +1,3 @@ +.cache/ +node_modules/ +public/ diff --git a/website/docker/Dockerfile b/website/docker/Dockerfile new file mode 100644 index 00000000..17b8db63 --- /dev/null +++ b/website/docker/Dockerfile @@ -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 diff --git a/website/docker/scripts/container.sh b/website/docker/scripts/container.sh new file mode 100755 index 00000000..aa9eca46 --- /dev/null +++ b/website/docker/scripts/container.sh @@ -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 diff --git a/website/docker/scripts/nginx-boot.sh b/website/docker/scripts/nginx-boot.sh new file mode 100644 index 00000000..71aa0ee2 --- /dev/null +++ b/website/docker/scripts/nginx-boot.sh @@ -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=$( $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 From 858073d27c45f4d238cdb42bbb09031775f3a6bf Mon Sep 17 00:00:00 2001 From: Johandry Amador Date: Thu, 13 Aug 2020 15:05:17 -0700 Subject: [PATCH 2/4] mv ARTICLE to documents --- ARTICLE.md => docs/ARTICLE.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ARTICLE.md => docs/ARTICLE.md (100%) diff --git a/ARTICLE.md b/docs/ARTICLE.md similarity index 100% rename from ARTICLE.md rename to docs/ARTICLE.md From a61e5552ce29ac609802460dd0d908b78045f63e Mon Sep 17 00:00:00 2001 From: Johandry Amador Date: Thu, 13 Aug 2020 15:05:32 -0700 Subject: [PATCH 3/4] draft README --- README.md | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..048c0f35 --- /dev/null +++ b/README.md @@ -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) From d001b4e52d26b1d30855b3c1e80c28a3ed42b266 Mon Sep 17 00:00:00 2001 From: Johandry Amador Date: Thu, 13 Aug 2020 15:05:56 -0700 Subject: [PATCH 4/4] draft Travis (may be GH Actions or both) --- .travis.yml | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..0dd193ff --- /dev/null +++ b/.travis.yml @@ -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