Dan Van Brunt
10/06/2021, 3:26 PMyarn workspace frontend run build (gatsby build)
• NO WORK - yarn deploy (SST)
The site's gatsby-config.js failed validation:
"siteMetadata.siteUrl" must be a valid uri
Likely because we have a number of gatsby plugins that need the GATSBY_SITE_URL in order to work. Ex. gatsby-plugin-robots-txt, and siteMetadata all inside gatsby-config.jsDan Van Brunt
10/06/2021, 3:31 PM.env file in the frontend root and thats what allows the build to work locally with yarn workspace frontend run build but running yarn deploy from the root causes sst to fail. So not only is the envs that we’re passing into StaticSite don’t work, but neither does that .env file in the frontend folder.Dan Van Brunt
10/06/2021, 3:38 PMDan Van Brunt
10/06/2021, 3:47 PMDan Van Brunt
10/06/2021, 3:47 PMDan Van Brunt
10/06/2021, 3:50 PMsiteMetadata in gatsby-config.esm.js I get ….
{
siteMetadata: {
siteUrl: '{{ GATSBY_SITE_URL }}',
stackname: '{{ GATSBY_STACKNAME }}',
gitVersion: '{{ GATSBY_GIT_SHORT }}'
}
}Frank
siteUrl?Dan Van Brunt
10/06/2021, 4:46 PMthdxr
10/06/2021, 4:48 PMDan Van Brunt
10/06/2021, 4:48 PMthdxr
10/06/2021, 4:48 PMenvironment is a bit confusing because people expect those values would be passed in as process.envFrank
siteUrl coming from another stack in the same SST app?Dan Van Brunt
10/06/2021, 4:50 PMFrank
process.env in React/Next.js siteFrank
siteUrl is unknown. So SST uses a placeholder {{ xxxxx }}, and creates a Custom Resource that will go in and replaces {{ xxxx }}} with the actual url after it is deployed.Dan Van Brunt
10/06/2021, 4:56 PMDan Van Brunt
10/06/2021, 4:56 PMDan Van Brunt
10/06/2021, 4:56 PMDan Van Brunt
10/06/2021, 4:57 PMexecSync as untokenizedFrank
Frank
Dan Van Brunt
10/06/2021, 4:58 PMDan Van Brunt
10/06/2021, 4:58 PMFrank
isResolvable() function, where it can tell u if something is resolvable (ie. untokenized) or not.Dan Van Brunt
10/06/2021, 4:59 PMconst { name: SERVICE, stage: STAGE } = scope
const STACKNAME = `${SERVICE}-${STAGE}`
for usDan Van Brunt
10/06/2021, 5:00 PMDan Van Brunt
10/06/2021, 5:01 PMFrank
Frank
cdk.Token.isUnresolved(value)Dan Van Brunt
10/06/2021, 5:05 PMsiteUrl we need that var in both the gatsby cli build as well as a process.env post build. … So I guess this would still work… all the untokenized (Resolvables) would just get baked in at build time by gatsby cli as usual. Since they already equal the actual string. Vs any tokenized ones that are not Resolvable…. which would get baked in by Gatsby as tokens and replaced by the custom resource laterFrank
process.env at build time right?Dan Van Brunt
10/06/2021, 5:07 PMDan Van Brunt
10/06/2021, 5:07 PMDan Van Brunt
10/06/2021, 5:08 PMFrank
Dan Van Brunt
10/06/2021, 5:08 PMDan Van Brunt
10/06/2021, 5:08 PMFrank
Dan Van Brunt
10/06/2021, 5:09 PMthdxr
10/06/2021, 5:21 PMcdk.Token.isUnresolvedthdxr
10/06/2021, 5:21 PMFrank
thdxr
10/06/2021, 5:21 PMFrank
Dan Van Brunt
10/06/2021, 5:22 PMFrank
Dan Van Brunt
10/06/2021, 5:24 PMDan Van Brunt
10/06/2021, 5:29 PMdvb-envs
• commit changes with tests and proper commit msg with Fixes #893 in the body
• Submit PR from dvb-envs -> upstream master
Anything else? does things get CI tested right then?
I noticed running tests locally doesnt work.Frank
Dan Van Brunt
10/06/2021, 5:31 PMFrank
cd packages/resources
yarn test StaticSiteDan Van Brunt
10/06/2021, 5:32 PMthdxr
10/06/2021, 5:36 PMDan Van Brunt
10/06/2021, 5:59 PMDan Van Brunt
10/06/2021, 6:16 PMenvironment StaticSite prop nets out to environment AND replaceValues.
Where replaceValues prop is ONLY replaceValuesDan Van Brunt
10/06/2021, 6:18 PMFrank
Frank
Dan Van Brunt
10/06/2021, 6:23 PMDan Van Brunt
10/06/2021, 6:29 PMindex.html file that already has {{ REACT_APP_API_URL }} in it.
Then we read that file into the test… and test if that exact value is in it. ??? Why would it not be?Dan Van Brunt
10/06/2021, 6:32 PMenvironment vs replaceValuesFrank
thdxr
10/06/2021, 6:35 PMDan Van Brunt
10/06/2021, 6:36 PMFrank
Frank
Dan Van Brunt
10/06/2021, 6:37 PMDan Van Brunt
10/06/2021, 6:37 PMFrank
Dan Van Brunt
10/06/2021, 6:38 PMCustom::SSTBucketDeployment > ReplaceValues when the value is inresolvable or notFrank
Dan Van Brunt
10/06/2021, 6:39 PMDan Van Brunt
10/06/2021, 6:39 PMFrank
environment does a couple of things:
1. set the env vars in the npm build command
2. sets the replaceValues
3. generates a metadata file consumed by sst-env to make the env vars available when you run npm start in for React appDan Van Brunt
10/06/2021, 6:42 PMDan Van Brunt
10/06/2021, 6:53 PMyarn watch in the root and then I edit and save packages/resources/test/StaticSite.test.ts and nothing seems to compile ?Dan Van Brunt
10/06/2021, 6:53 PMthdxr
10/06/2021, 6:53 PMDan Van Brunt
10/06/2021, 6:54 PMthdxr
10/06/2021, 6:54 PMts-jest. Been meaning to switch it to esr which is a lot fasterDan Van Brunt
10/06/2021, 6:54 PMFrank
Dan Van Brunt
10/06/2021, 6:55 PMthdxr
10/06/2021, 6:55 PMDan Van Brunt
10/06/2021, 6:55 PMFrank
thdxr
10/06/2021, 6:57 PMthdxr
10/06/2021, 6:58 PMFrank
Dan Van Brunt
10/06/2021, 7:06 PMDan Van Brunt
10/06/2021, 7:06 PM{
"Fn::GetAtt": [
"ApiCD79AAA0",
"ApiEndpoint"
]
}Dan Van Brunt
10/06/2021, 7:08 PMFn::GetAtt ?Dan Van Brunt
10/06/2021, 7:09 PMhaveResource stuff… doesn’t seem super straighforwardFrank
replace exists is fine. Whereas for the constant value case, ReplaceValues should be empty.Dan Van Brunt
10/06/2021, 7:22 PMFrank
Dan Van Brunt
10/06/2021, 7:47 PMexpectCdk(stack).to(
haveResource("Custom::SSTBucketDeployment", {
ReplaceValues: not(arrayWith(objectLike({
search: "{{ REACT_APP_CONSTANT }}"
}))),
})
);
meaning I want to be sure there is NO object in the array like thisDan Van Brunt
10/06/2021, 7:57 PMexpectCdk(stack).to(
haveResource("Custom::SSTBucketDeployment", {
ReplaceValues: notMatching(arrayWith(objectLike({
search: "{{ REACT_APP_CONSTANT }}",
}))),
})
);Dan Van Brunt
10/06/2021, 8:36 PMundefined
https://github.com/serverless-stack/serverless-stack/blob/master/packages/resources/test/ReactStaticSite.test.ts#L69Dan Van Brunt
10/06/2021, 8:36 PMDan Van Brunt
10/06/2021, 8:53 PMDan Van Brunt
10/06/2021, 8:54 PMDan Van Brunt
10/07/2021, 1:16 PMthdxr
10/07/2021, 1:16 PMFrank
Frank