Skip to content

Commit 2e18625

Browse files
authored
ci(storybook): Auto-deploy Storybook to storybook.core-patch (#4590)
* ci(api): Tweak to address API update on tag (#4585) * ci(build): Fix Storybook build output path * ci(build): Add needed files
1 parent 5a7bfe0 commit 2e18625

File tree

6 files changed

+138
-49
lines changed

6 files changed

+138
-49
lines changed

.circleci/config.yml

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,10 @@ commands:
5656
export CURRENT_DEFAULT_BRANCH=`git remote show origin | grep "HEAD branch" | cut -d ":" -f 2 | xargs`
5757
echo 'export HEROKU_RELEASE_STORYBOOK_APP_NAME=false' >> $BASH_ENV
5858
if [[ "${CIRCLE_BRANCH}" = "${CURRENT_DEFAULT_BRANCH}" ]] ; then
59-
if [[ "${CIRCLE_TAG}" =~ ^v\d+\.\d+\.\d+-.+$ ]] ; then
60-
echo "Publishing to CORE-MAIN..."
61-
echo 'export HEROKU_APP_NAME=${HEROKU_APP_CORE_MAIN}' >> $BASH_ENV
62-
else
63-
echo "Publishing to UPCOMING..."
64-
echo 'export HEROKU_APP_NAME=${HEROKU_APP_UPCOMING}' >> $BASH_ENV
65-
echo 'export HEROKU_RELEASE_STORYBOOK_APP_NAME=storybook-upcoming' >> $BASH_ENV
66-
fi
67-
elif [[ "${CIRCLE_TAG}" =~ ^v\d+\.\d+\.\d+$ ]] ; then
59+
echo "Publishing to UPCOMING..."
60+
echo "Publishing to CORE-MAIN..."
61+
echo 'export HEROKU_APP_NAME=${HEROKU_APP_CORE_MAIN}' >> $BASH_ENV
62+
elif [[ ${CIRCLE_TAG} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] ; then
6863
echo "Publishing to CORE-PATCH..."
6964
echo 'export HEROKU_APP_NAME=${HEROKU_APP_CORE_PATCH}' >> $BASH_ENV
7065
echo 'export HEROKU_RELEASE_STORYBOOK_APP_NAME=storybook-core-patch' >> $BASH_ENV
@@ -157,7 +152,7 @@ commands:
157152
command: 'tar -xvf workspace/storybook.tar.gz'
158153
- run:
159154
name: Start server
160-
command: 'npx http-server .out'
155+
command: 'npx http-server .www'
161156
background: true
162157
- run:
163158
name: Poll until server is up
@@ -275,7 +270,7 @@ jobs:
275270
export VERSION_FROM_TAG=$([[ ${CIRCLE_TAG} -eq "v" ]] && echo ${CIRCLE_TAG:1:20} || echo ${CIRCLE_TAG})
276271
export SALESFORCE_VERSION=$(cat package.json | jq -r .slds.id)
277272
export VERSION_FROM_PACKAGE=$(cat package.json | jq -r .version)
278-
curl --location --request PATCH 'https://design-systems-api.herokuapp.com/v1/release' \
273+
curl --location --request PATCH 'https://api.lightningdesignsystem.com/v1/release' \
279274
--header 'Content-Type: application/json' \
280275
--header 'Authorization: Bearer ${DSE_API_RELEASE_TOKEN}' \
281276
--data-raw '{
@@ -300,24 +295,9 @@ jobs:
300295
name: Build static Storybook
301296
command: 'npm run storybook:build'
302297

303-
- run:
304-
name: 'Generate custom Nginx config'
305-
command: |
306-
cat > nginx_app.conf\<<'EOF'
307-
# Redirect all non-SSL requests
308-
if ($http_x_forwarded_proto != 'https') {
309-
return 301 https://$host$request_uri;
310-
}
311-
312-
location / {
313-
index index.php index.html index.htm;
314-
}
315-
EOF
316-
cat nginx_app.conf
317-
318298
- run:
319299
name: Archive static Storybook
320-
command: 'tar -czvf workspace/storybook.tar.gz .out/ Procfile composer.json nginx_app.conf'
300+
command: 'tar -czvf workspace/storybook.tar.gz .www/ Procfile config/nginx.conf.erb heroku-start.sh app.json'
321301

322302
- persist_to_workspace:
323303
root: workspace
@@ -361,7 +341,7 @@ jobs:
361341
echo "=============================="
362342
echo ${PUBLISH_STORYBOOK_TO}
363343
echo "=============================="
364-
heroku buildpacks -a ${PUBLISH_STORYBOOK_TO} | grep "heroku/php" || heroku buildpacks:set heroku/php -a ${PUBLISH_STORYBOOK_TO}
344+
heroku buildpacks -a ${PUBLISH_STORYBOOK_TO} | grep "https://github.com/salesforce-ux/heroku-buildpack-nginx.git#dse" || heroku buildpacks:set https://github.com/salesforce-ux/heroku-buildpack-nginx.git#dse -a ${PUBLISH_STORYBOOK_TO}
365345
heroku builds:create --source-tar workspace/storybook.tar.gz -a ${PUBLISH_STORYBOOK_TO}
366346
367347
- install-gh-cli
@@ -417,20 +397,7 @@ jobs:
417397
- run:
418398
name: 'Generate site tarball'
419399
command: |
420-
echo '{}' > composer.json
421-
echo 'web: vendor/bin/heroku-php-nginx -C nginx_app.conf .www' > Procfile
422-
cat > nginx_app.conf\<<'EOF'
423-
# Redirect all non-SSL requests
424-
if ($http_x_forwarded_proto != 'https') {
425-
return 301 https://$host$request_uri;
426-
}
427-
428-
location / {
429-
index index.php index.html index.htm;
430-
}
431-
EOF
432-
cat nginx_app.conf
433-
tar -czvf site-next.tar.gz .www/ Procfile composer.json nginx_app.conf
400+
tar -czvf site-next.tar.gz .www/ Procfile config/nginx.conf.erb heroku-start.sh app.json
434401
435402
- run:
436403
name: 'Deploy to Heroku app'
@@ -439,7 +406,7 @@ jobs:
439406
echo "=============================="
440407
echo ${HEROKU_APP_NAME}
441408
echo "=============================="
442-
heroku buildpacks -a ${HEROKU_APP_NAME} | grep "heroku/php" || heroku buildpacks:set heroku/php -a ${HEROKU_APP_NAME}
409+
heroku buildpacks -a ${HEROKU_APP_NAME} | grep "https://github.com/salesforce-ux/heroku-buildpack-nginx.git#dse" || heroku buildpacks:set https://github.com/salesforce-ux/heroku-buildpack-nginx.git#dse -a ${HEROKU_APP_NAME}
443410
heroku builds:create --source-tar site-next.tar.gz -a ${HEROKU_APP_NAME}
444411
445412
- install-gh-cli
@@ -538,10 +505,10 @@ workflows:
538505
context: ux-eng-keys
539506
requires:
540507
- framework-build
541-
# only on the main version branches with a public release tag (X.X.X)
508+
# update for all tagged versions (X.X.X[-*])
542509
filters:
543510
tags:
544-
only: /^v\d+\.\d+\.\d+$/
511+
only: /^v\d+\.\d+\.\d+.*/
545512
branches:
546513
ignore: /.*/
547514
- vrt-desktop:

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: vendor/bin/heroku-php-nginx -C nginx_app.conf .out
1+
web: ./heroku-start.sh

app.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
"env": {},
66
"formation": {},
77
"addons": [],
8-
"buildpacks": [],
9-
"stack": "heroku-18"
8+
"buildpacks": [
9+
{
10+
"url": "https://github.com/salesforce-ux/heroku-buildpack-nginx.git#dse"
11+
}
12+
],
13+
"stack": "heroku-20",
14+
"environments": {
15+
"review": {
16+
"buildpacks": [
17+
{
18+
"url": "https://github.com/salesforce-ux/heroku-buildpack-nginx.git#dse"
19+
}
20+
]
21+
}
22+
}
1023
}

config/nginx.conf.erb

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
daemon off;
2+
# Heroku dynos have at least 4 cores
3+
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;
4+
events {
5+
use epoll;
6+
accept_mutex on;
7+
worker_connections <%= ENV['NGINX_WORKER_CONNECTIONS'] || 1024 %>;
8+
}
9+
10+
http {
11+
gzip on;
12+
gzip_comp_level 2;
13+
gzip_min_length 512;
14+
15+
server_tokens off;
16+
17+
log_format main '$time_iso8601 - $status $request - client IP: $http_x_forwarded_for - <%= ENV['DYNO'] %> to $upstream_addr - upstream status: $upstream_status, upstream_response_time $upstream_response_time, request_time $request_time';
18+
access_log /dev/stdout main;
19+
error_log /dev/stdout notice;
20+
log_not_found on;
21+
include mime.types;
22+
23+
default_type application/octet-stream;
24+
sendfile on;
25+
26+
# Must read the body in 5 seconds.
27+
client_body_timeout <%= ENV['NGINX_CLIENT_BODY_TIMEOUT'] || 5 %>;
28+
29+
# handle SNI
30+
proxy_ssl_server_name on;
31+
# resolver needs to be set because we're using dynamic proxy_pass
32+
resolver 8.8.8.8;
33+
34+
# map possible Vouch destinations
35+
map $host $vouch_destination {
36+
default vouch.lightningdesignsystem.com;
37+
}
38+
39+
server {
40+
listen <%= ENV["PORT"] %>;
41+
server_name *.herokuapp.com;
42+
43+
error_page 404 /404.html;
44+
45+
port_in_redirect off;
46+
47+
# Redirect all non-SSL requests
48+
if ($http_x_forwarded_proto != 'https') {
49+
return 301 https://$host$request_uri;
50+
}
51+
52+
root /app/.www;
53+
54+
location / {
55+
index index.html index.htm;
56+
}
57+
}
58+
59+
server {
60+
listen <%= ENV["PORT"] %>;
61+
server_name ~^storybook\..*\.lightningdesignsystem\.com$;
62+
63+
error_page 404 /404.html;
64+
65+
port_in_redirect off;
66+
67+
# Redirect all non-SSL requests
68+
if ($http_x_forwarded_proto != 'https') {
69+
return 301 https://$host$request_uri;
70+
}
71+
72+
# auth request / SSO
73+
auth_request /validate;
74+
75+
location = /validate {
76+
# This address is where Vouch will be listening on
77+
proxy_pass https://$vouch_destination/validate;
78+
proxy_pass_request_body off; # no need to send the POST body
79+
80+
proxy_ssl_name $vouch_destination;
81+
proxy_set_header x-forwarded-host $host;
82+
proxy_set_header Host $vouch_destination;
83+
proxy_set_header Content-Length "";
84+
proxy_set_header X-Real-IP $remote_addr;
85+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
86+
proxy_set_header X-Forwarded-Proto $scheme;
87+
88+
# these return values are passed to the @error401 call
89+
auth_request_set $auth_resp_jwt $upstream_http_x_vouch_jwt;
90+
auth_request_set $auth_resp_err $upstream_http_x_vouch_err;
91+
auth_request_set $auth_resp_failcount $upstream_http_x_vouch_failcount;
92+
}
93+
94+
# if validate returns `401 not authorized` then forward the request to the error401block
95+
error_page 401 = @error401;
96+
97+
# If the user is not logged in, redirect them to Vouch's login URL
98+
location @error401 {
99+
return 302 https://$vouch_destination/login?url=https://$http_host$request_uri&vouch-failcount=$auth_resp_failcount&X-Vouch-Token=$auth_resp_jwt&error=$auth_resp_err;
100+
}
101+
102+
root /app/.www;
103+
104+
location / {
105+
index index.html index.htm;
106+
}
107+
}
108+
}

heroku-start.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/start-nginx-solo

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
"compile-aura-tokens-map": "npm run gulp -- generate:auraTokensMap",
218218
"compile-token-component-map": "npm run gulp -- generate:tokenComponentMap",
219219
"storybook:heroku": "npm run storybook:prepare && start-storybook -c .storybook -p 9002",
220-
"storybook:build": "npm run storybook:prepare && build-storybook -c .storybook -s .dist/ -o .out",
220+
"storybook:build": "npm run storybook:prepare && build-storybook -c .storybook -s .dist/ -o .www",
221221
"release-notes:compile": "node ./scripts/release-notes/index.js",
222222
"release-notes:hook": "node ./scripts/release-notes/hook.js",
223223
"heroku-postbuild": "npm run build && npm run dist && npm run storybook:build"

0 commit comments

Comments
 (0)