Skip to content

Commit

Permalink
New deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
gfodor committed Oct 9, 2019
1 parent f169a6d commit 4f62d96
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 33 deletions.
18 changes: 14 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pipeline {
steps {
script {
def baseAssetsPath = env.BASE_ASSETS_PATH
def targetS3Url = env.TARGET_S3_URL
def targetS3Bucket = env.TARGET_S3_BUCKET
def smokeURL = env.SMOKE_URL
def reticulumServer = env.RETICULUM_SERVER
def thumbnailServer = env.THUMBNAIL_SERVER
Expand All @@ -41,17 +41,27 @@ pipeline {
def slackURL = env.SLACK_URL
def sentryDsn = env.SENTRY_DSN

def habCommand = "sudo /usr/bin/hab-docker-studio -k mozillareality run /bin/bash scripts/hab-build-and-push.sh \\\"${baseAssetsPath}\\\" \\\"${reticulumServer}\\\" \\\"${thumbnailServer}\\\" \\\"${corsProxyServer}\\\" \\\"${nonCorsProxyDomains}\\\" \\\"${sentryDsn}\\\" \\\"${targetS3Url}\\\" \\\"${env.BUILD_NUMBER}\\\" \\\"${env.GIT_COMMIT}\\\""
def habCommand = "sudo /usr/bin/hab-docker-studio -k mozillareality run /bin/bash scripts/hab-build-and-push.sh \\\"${baseAssetsPath}\\\" \\\"${reticulumServer}\\\" \\\"${thumbnailServer}\\\" \\\"${corsProxyServer}\\\" \\\"${nonCorsProxyDomains}\\\" \\\"${sentryDsn}\\\" \\\"${targetS3Bucket}\\\" \\\"${env.BUILD_NUMBER}\\\" \\\"${env.GIT_COMMIT}\\\""
sh "/usr/bin/script --return -c ${shellString(habCommand)} /dev/null"

def s = $/eval 'ls -rt results/*.hart | head -n 1'/$
def hart = sh(returnStdout: true, script: "${s}").trim()
s = $/eval 'tail -n +6 ${hart} | xzcat | tar tf - | grep IDENT'/$
def identPath = sh(returnStdout: true, script: "${s}").trim()
s = $/eval 'tail -n +6 ${hart} | xzcat | tar xf - "${identPath}" -O'/$
def packageIdent = sh(returnStdout: true, script: "${s}").trim()
def packageTimeVersion = packageIdent.tokenize('/')[3]
def (major, minor, version) = packageIdent.tokenize('/')[2].tokenize('.')
def spokeVersion = "${major}.${minor}.${version}.${packageTimeVersion}"
def gitMessage = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'[%an] %s'").trim()
def gitSha = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
def text = (
"*<http://localhost:8080/job/${env.JOB_NAME}/${env.BUILD_NUMBER}|#${env.BUILD_NUMBER}>* *${env.JOB_NAME}* " +
"<https://github.com/mozilla/Spoke/commit/$gitSha|$gitSha> " +
"Spoke: ```${gitSha} ${gitMessage}```\n" +
"<${smokeURL}?required_version=${env.BUILD_NUMBER}|Smoke Test> - to push:\n" +
"`/mr spoke deploy ${env.BUILD_NUMBER} ${targetS3Url}`"
"<${smokeURL}?required_version=${spokeVersion}|Smoke Test> - to push:\n" +
"`/mr spoke deploy ${env.BUILD_NUMBER} ${targetS3Bucket}`"
)
def payload = 'payload=' + JsonOutput.toJson([
text : text,
Expand Down
63 changes: 40 additions & 23 deletions scripts/hab-build-and-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,53 @@ export THUMBNAIL_SERVER=$3
export CORS_PROXY_SERVER=$4
export NON_CORS_PROXY_DOMAINS=$5
export SENTRY_DSN=$6
export TARGET_S3_URL=$7
export TARGET_S3_BUCKET=$7
export BUILD_NUMBER=$8
export GIT_COMMIT=$9
export BUILD_VERSION="${BUILD_NUMBER} (${GIT_COMMIT})"
export SENTRY_LOG_LEVEL=debug

# To build + push to S3 run:
# hab studio run "bash scripts/hab-build-and-push.sh"
# On exit, need to make all files writable so CI can clean on next build

trap 'chmod -R a+rw .' EXIT
# Build the package, upload it, and start the service so we deploy to staging target.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DIR/../habitat/plan.sh"
PKG="$pkg_origin/$pkg_name"

pushd "$DIR/.."

rm /usr/bin/env
ln -s "$(hab pkg path core/coreutils)/bin/env" /usr/bin/env
hab pkg install -b core/coreutils core/bash core/node core/yarn core/git core/aws-cli core/python2

yarn config set cache-folder "$(pwd)/.cache" # Set the yarn cache to a directory in the current workspace so that it can be reused across ci builds
yarn install --frozen-lockfile
yarn build
mkdir -p dist/pages
mv dist/*.html dist/pages

# we need to upload wasm blobs with wasm content type explicitly because, unlike all our
# other assets, AWS's built-in MIME type dictionary doesn't know about that one
aws s3 sync --acl public-read --cache-control "max-age=31556926" --include "*" --exclude "*.wasm" dist/assets "$TARGET_S3_URL/spoke/assets"
aws s3 sync --acl public-read --cache-control "max-age=31556926" --exclude "*" --include "*.wasm" --content-type "application/wasm" dist/assets "$TARGET_S3_URL/spoke/assets"

aws s3 sync --acl public-read --cache-control "no-cache" --delete dist/pages "$TARGET_S3_URL/spoke/pages/latest"
aws s3 sync --acl public-read --cache-control "no-cache" --delete dist/pages "$TARGET_S3_URL/spoke/pages/releases/${BUILD_NUMBER}"
trap "rm /hab/svc/$pkg_name/var/deploying && sudo /usr/bin/hab-clean-perms && chmod -R a+rw ." EXIT

# Wait for a lock file so we serialize deploys
mkdir -p /hab/svc/$pkg_name/var
while [ -f /hab/svc/$pkg_name/var/deploying ]; do sleep 1; done
touch /hab/svc/$pkg_name/var/deploying

rm -rf results
mkdir -p results
sudo /usr/bin/hab-docker-studio -k mozillareality run build
hab svc unload $PKG
sudo /usr/bin/hab-pkg-install results/*.hart
hab svc load $PKG
hab svc stop $PKG

# Apparently these vars come in from jenkins with quotes already
cat > build-config.toml << EOTOML
[general]
base_assets_path = $BASE_ASSETS_PATH
reticulum_server = $RETICULUM_SERVER
thumbnail_server = $THUMBNAIL_SERVER
cors_proxy_server = $CORS_PROXY_SERVER
non_cors_proxy_domains = $NON_CORS_PROXY_DOMAINS
sentry_dsn = $SENTRY_DSN
ga_tracking_id = $GA_TRACKING_ID
[deploy]
type = "s3"
target = $TARGET_S3_BUCKET
region = "us-west-1"
EOTOML

cat build-config.toml
sudo /usr/bin/hab-user-toml-install $pkg_name build-config.toml
hab svc start $PKG
sudo /usr/bin/hab-pkg-upload results/*.hart
12 changes: 6 additions & 6 deletions src/api/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import PublishedSceneDialog from "./PublishedSceneDialog";
// https://github.com/mozilla/hubs/blob/master/src/utils/media-utils.js

const resolveUrlCache = new Map();
const RETICULUM_SERVER = process.env.RETICULUM_SERVER || document.location.hostname;

// NOTE: We avoid doing truthy comparison for process.env.var since we inject these at runhook time, and
// otherwise the check may be elided by the compiler.
const RETICULUM_SERVER =
process.env.RETICULUM_SERVER.length !== 0 ? process.env.RETICULUM_SERVER : document.location.hostname;

// thanks to https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
function b64EncodeUnicode(str) {
Expand Down Expand Up @@ -60,11 +64,7 @@ export const proxiedUrlFor = url => {
};

export const scaledThumbnailUrlFor = (url, width, height) => {
if (
process.env.RETICULUM_SERVER &&
process.env.RETICULUM_SERVER.includes("hubs.local") &&
url.includes("hubs.local")
) {
if (process.env.RETICULUM_SERVER.includes("hubs.local") && url.includes("hubs.local")) {
return url;
}

Expand Down

0 comments on commit 4f62d96

Please sign in to comment.