Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lambda endpoints env vars for astrosite #9

Draft
wants to merge 17 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ jobs:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Install Lambda dependencies
run: |
npm install
Expand All @@ -64,6 +71,15 @@ jobs:
shopt -s extglob
cp -r !(AppForm|GameForm) GameForm/
working-directory: aws-lambdas

- name: Build Astro site
env:
PUBLIC_API_HOST: ${{ vars.PUBLIC_API_HOST }}
PUBLIC_APPLICATION_API_ENDPOINT: ${{ vars.PUBLIC_APPLICATION_API_ENDPOINT }}
PUBLIC_GAME_API_ENDPOINT: ${{ vars.PUBLIC_GAME_API_ENDPOINT }}
run: |
yarn install
yarn astro build

- name: Build and deploy
env:
Expand All @@ -73,7 +89,7 @@ jobs:
GITHUB_BASE_BRANCH: ${{ vars.GH_BASE_BRANCH }}
GITHUB_OWNER: ${{ vars.GH_OWNER }}
GITHUB_REPO: ${{ vars.GH_REPO }}
RECAPTCHA_V2_VERIFY_URL: ${{ vars.PUBLIC_CAPTCHA_WEB_SITE_KEY }}
RECAPTCHA_V2_VERIFY_URL: ${{ vars.RECAPTCHA_V2_VERIFY_URL }}
RECAPTCHA_V2_SECRET_KEY: ${{ secrets.RECAPTCHA_V2_SECRET_KEY }}
run: |
# Set up the environment variables
Expand All @@ -89,6 +105,9 @@ jobs:
export CUSTOM_DOMAIN=${{ vars.CUSTOM_DOMAIN }}
export HOSTED_ZONE=${{ vars.HOSTED_ZONE }}
export IS_PUBLIC=${{ vars.IS_PUBLIC }}
export PUBLIC_API_HOST=${{ vars.PUBLIC_API_HOST }}
export PUBLIC_APPLICATION_API_ENDPOINT=${{ vars.PUBLIC_APPLICATION_API_ENDPOINT }}
export PUBLIC_GAME_API_ENDPOINT=${{ vars.PUBLIC_GAME_API_ENDPOINT }}
# Set up yarn
yarn install
# Set up AWS CLI & credentials
Expand All @@ -98,12 +117,8 @@ jobs:
sudo ./aws/install --update
cp -R .aws ~/
pipx run pipenv install
$(pipx run pipenv run python ./get_aws_creds.py -i ${{ secrets.VAULT_ROLE_ID }} -s ${{ secrets.VAULT_SECRET_ID }} -r ${{ secrets.VAULT_ROLE }} 2>&1 | tee /dev/stderr)
# Build & deploy
if [[ "${{ github.ref_name }}" == "staging" ]]; then
export STAGE="dev"
fi
if [[ "${{ github.ref_name }}" == "main" ]]; then
export STAGE="main"
fi
yarn sst deploy --stage $STAGE
# Default stage to "dev" or set explicitly
export STAGE="dev" # or "main" if you'd like to default to production
echo "Deploying with stage: $STAGE"
# Always deploy
yarn sst deploy --stage $STAGE
4 changes: 2 additions & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const { IS_PUBLIC, PRE_BUILD, CUSTOM_DOMAIN } = loadEnv(
process.cwd(),
""
);
const is_public = IS_PUBLIC === "true"
const is_pre_build = PRE_BUILD === "true"
const is_public = true;
const is_pre_build = false;

// https://astro.build/config
export default defineConfig({
Expand Down
1 change: 1 addition & 0 deletions src/lib/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ form.addEventListener("submit", (e) => {
// }, 3000);
// } else
{
console.log(`THIS IS THE ENV VAR ${import.meta.env.PUBLIC_API_HOST}`)
var data = new FormData(form)
fetch(`${import.meta.env.PUBLIC_API_HOST}${import.meta.env.PUBLIC_APPLICATION_API_ENDPOINT}`, {
method: "POST",
Expand Down
8 changes: 6 additions & 2 deletions sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default {
customDomain: cd,
environment: {
IS_PUBLIC: "true",
PUBLIC_API_HOST: "https://www.google.com",
PUBLIC_APPLICATION_API_ENDPOINT: process.env.PUBLIC_APPLICATION_API_ENDPOINT!,
PUBLIC_GAME_API_ENDPOINT: process.env.PUBLIC_GAME_API_ENDPOINT!,
PUBLIC_CAPTCHA_WEB_SITE_KEY: process.env.PUBLIC_CAPTCHA_WEB_SITE_KEY!
},
cdk: {
distribution: {
Expand Down Expand Up @@ -71,8 +75,8 @@ export default {
GITHUB_OWNER: process.env.GITHUB_OWNER!,
GITHUB_REPO: process.env.GITHUB_REPO!,
GITHUB_BASE_BRANCH: process.env.GITHUB_BASE_BRANCH!,
RECAPTCHA_VERIFY_URL: process.env.RECAPTCHA_VERIFY_URL!,
RECAPTCHA_SECRET_KEY: process.env.RECAPTCHA_SECRET_KEY!,
RECAPTCHA_V2_VERIFY_URL: process.env.RECAPTCHA_V2_VERIFY_URL!,
RECAPTCHA_V2_SECRET_KEY: process.env.RECAPTCHA_V2_SECRET_KEY!,
};

const appFormFunction = new Function(stack, "ProcessAppFormSubmissions", {
Expand Down
Loading