From e858ae2dc60de6720d840db491011d0b90f0b698 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 3 Feb 2024 11:34:34 +0530 Subject: [PATCH 1/6] Deploy auth from the same repository --- scripts/deploy.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 scripts/deploy.sh diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 000000000..f39c5b204 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# This script is run by the Cloudflare Pages integration when deploying the apps +# in this repository. The app to build is decided based on the the value of the +# CF_PAGES_BRANCH environment variable. +# +# Ref: https://developers.cloudflare.com/pages/how-to/build-commands-branches/ + +set -o errexit + +if test "$CF_PAGES_BRANCH" == "auth-release" +then + yarn export:auth +else + yarn export:photos +fi From 67624839f3c9235e5896605695938c2b16fdd46a Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 3 Feb 2024 15:54:45 +0530 Subject: [PATCH 2/6] Handle the single output directory by creating a symlink --- scripts/deploy.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index f39c5b204..15309e9a3 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -5,12 +5,17 @@ # CF_PAGES_BRANCH environment variable. # # Ref: https://developers.cloudflare.com/pages/how-to/build-commands-branches/ +# +# The CF Pages configuration is set to use `out/` as the build output directory, +# so once we're done building we symlink `out/` to the app specific output. set -o errexit if test "$CF_PAGES_BRANCH" == "auth-release" then yarn export:auth + ln -sf apps/auth/out else yarn export:photos + ln -sf apps/photos/out fi From d3cf5a9afb15a0ecccad20a1dfd3b309d316821b Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 3 Feb 2024 16:14:23 +0530 Subject: [PATCH 3/6] Make the deploy script executable --- scripts/deploy.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/deploy.sh diff --git a/scripts/deploy.sh b/scripts/deploy.sh old mode 100644 new mode 100755 From 7bd332bad2f45f605fc2461a1204cddd28c46eae Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 3 Feb 2024 16:33:51 +0530 Subject: [PATCH 4/6] POSIX test requires a single = https://pubs.opengroup.org/onlinepubs/009695399/utilities/test.html Fixes the following error when running on CF pages: ./scripts/deploy.sh: 14: test: multi-deploy-test: unexpected operator Also xtrace the commands for the log --- scripts/deploy.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 15309e9a3..82e4b63c3 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -10,8 +10,9 @@ # so once we're done building we symlink `out/` to the app specific output. set -o errexit +set -o xtrace -if test "$CF_PAGES_BRANCH" == "auth-release" +if test "$CF_PAGES_BRANCH" = "auth-release" then yarn export:auth ln -sf apps/auth/out From e083c7caf2cab76d9371e8f7ccc211921dcc942a Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 3 Feb 2024 16:49:50 +0530 Subject: [PATCH 5/6] Copy the out directory The symlink does not seem to be working. In the build logs there is nothing wrong, but at the end CF gives up by saying: + ln -sf apps/auth/out Finished Note: No functions dir at /functions found. Skipping. Validating asset output directory Failed: build output directory contains links to files that can't be accessed --- scripts/deploy.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 82e4b63c3..9a305dd03 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -7,16 +7,18 @@ # Ref: https://developers.cloudflare.com/pages/how-to/build-commands-branches/ # # The CF Pages configuration is set to use `out/` as the build output directory, -# so once we're done building we symlink `out/` to the app specific output. +# so once we're done building we copy the app specific output to `out/`. set -o errexit set -o xtrace +rm -rf out + if test "$CF_PAGES_BRANCH" = "auth-release" then yarn export:auth - ln -sf apps/auth/out + cp -R apps/auth/out . else yarn export:photos - ln -sf apps/photos/out + cp -r apps/photos/out . fi From a2c9cd5071c64eeb0e2cc342aded9fd3ed0fed9d Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 3 Feb 2024 17:12:25 +0530 Subject: [PATCH 6/6] Use the correct casing -r also worked, but -R is the preferred casing https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cp.html --- scripts/deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 9a305dd03..c1a19160a 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -20,5 +20,5 @@ then cp -R apps/auth/out . else yarn export:photos - cp -r apps/photos/out . + cp -R apps/photos/out . fi