Skip to content

Commit

Permalink
Merge pull request #98 from systemphil/firgrep/nextra-4-alpha
Browse files Browse the repository at this point in the history
v1 (nextra-4 and symposia migration)
  • Loading branch information
Firgrep authored Nov 14, 2024
2 parents 089cdcf + 19a6960 commit 4a37de5
Show file tree
Hide file tree
Showing 251 changed files with 18,475 additions and 2,894 deletions.
25 changes: 24 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
NEXT_PUBLIC_SITE_ROOT=""
# Minimal required envs
NEXT_PUBLIC_SITE_ROOT="http://localhost:3000"
NEXT_PUBLIC_GA_ID="G-MMKZQ2ZQ5G"
DATABASE_URL=
AUTH_SECRET=
AUTH_GITHUB_ID=
AUTH_GITHUB_SECRET=
GCP_PRIMARY_BUCKET_NAME=
GCP_SECONDARY_BUCKET_NAME=
GCP_BUCKET_HANDLER_KEY=
STRIPE_API_KEY=

# Full scope
AUTH_GOOGLE_ID=
AUTH_GOOGLE_SECRET=
AUTH_RESEND_KEY=
AUTH_EMAIL_FROM=
STRIPE_WEBHOOK_SECRET=
RESEND_API_KEY=
EMAIL_SEND=
EMAIL_RECEIVE=

# Debug
PRISMA_DEBUG=""
9 changes: 5 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!-- Thank you for wanting to contribute to sPhil! 🧙 🦉 -->
<!-- We would like to keep our code and writing as neat and tidy as possible, and would appreciate if you could verify the following checklist if you are submitting philosophical or literary content -->

## Author's Note

Expand Down Expand Up @@ -52,10 +53,10 @@ Consider adding the Stub component to encourage further contributions.

### License Scope

The Apache License 2.0 applies to all code except content within `src/pages/**`
(with specific exclusions like `/contributing/**`, `_app.mdx`, `_document.tsx`,
etc.). This primarily covers technical implementations rather than content,
literature, or philosophy.
The Apache License 2.0 applies to all code except content within `content/**`
folder (excluding `/contributing/**`, `_meta.ts`, `acknowledgements.mdx`,
`index.mdx`, `privacy.mdx`, `team.mdx`, `terms.mdx`). This primarily covers
technical implementations rather than content, literature, or philosophy.

</details>

Expand Down
71 changes: 71 additions & 0 deletions .github/deploy_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

echo "🚀 Deployment script starting..."

# Function to print usage
print_usage() {
echo "Usage: $0 <PROJECT_ID> <PROJECT_NUMBER> <REGION> <SERVICE> <TAG> '<SECRET1> <SECRET2> ...' '<CONFIG_KEY>:<CONFIG_VALUE> ...'"
echo "Example: $0 my-project 43543524523 us-central1 my-service latest 'MONGO_URI DB_NAME' 'port:8080 memory:2Gi cpu:2'"
}

# Check if we have at least 6 arguments
if [ $# -lt 6 ]; then
print_usage
exit 1
fi

# Assign common variables
PROJECT_ID="$1"
PROJECT_NUMBER="$2"
REGION="$3"
SERVICE="$4"
TAG="$5"
SECRETS="$6"
DEPLOY_CONFIG="$7"

# Process secrets
declare -a secrets
for secret in $SECRETS; do
secrets+=("$secret")
done

# Process deploy config
declare -A config
for item in $DEPLOY_CONFIG; do
IFS=':' read -r key value <<< "$item"
config["$key"]="$value"
done

# Generate the --set-secrets argument
set_secrets_arg=""
for secret in "${secrets[@]}"; do
echo "${secret}=projects/${PROJECT_NUMBER}/secrets/${secret}:latest"
set_secrets_arg+="${secret}=projects/${PROJECT_NUMBER}/secrets/${secret}:latest,"
done
set_secrets_arg=${set_secrets_arg%,} # Remove trailing comma

# Generate the deploy command with dynamic config
deploy_command="gcloud beta run deploy $SERVICE \\
--platform=managed \\
--region=$REGION \\
--image=\"$REGION-docker.pkg.dev/$PROJECT_ID/$SERVICE/$SERVICE:$TAG\" \\"

# Add dynamic config options
for key in "${!config[@]}"; do
value="${config[$key]}"
if [ -n "$value" ]; then
deploy_command+="
--$key=$value \\"
else
deploy_command+="
--$key \\"
fi
done

# Add set-secrets to the command
deploy_command+="
--set-secrets=$set_secrets_arg"

# Execute the deploy command
echo "⚙️ Executing deploy command..."
eval "$deploy_command"
73 changes: 60 additions & 13 deletions .github/workflows/dev.yaml → .github/workflows/cd_dev.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: Deploy to Development
name: CD Development 🧪

on:
workflow_dispatch:
push:
branches:
- main

jobs:
prepyrus_verify:
Expand All @@ -27,7 +24,7 @@ jobs:
run: cargo build --release --package prepyrus_runner

- name: Run prepyrus script in VERIFY mode
run: target/release/prepyrus_runner absolute_bibliography.bib src/pages verify
run: target/release/prepyrus_runner absolute_bibliography.bib content verify

- name: Upload prepyrus for next job
uses: actions/upload-artifact@v4
Expand All @@ -49,10 +46,36 @@ jobs:
environment: dev
runs-on: ubuntu-latest
env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
SERVICE: ${{ secrets.SERVICE }}
BUILD_PATH:
SECRETS: >-
DATABASE_URL
AUTH_URL
AUTH_SECRET
AUTH_GITHUB_ID
AUTH_GITHUB_SECRET
AUTH_GOOGLE_ID
AUTH_GOOGLE_SECRET
AUTH_RESEND_KEY
AUTH_EMAIL_FROM
GCP_PRIMARY_BUCKET_NAME
GCP_SECONDARY_BUCKET_NAME
STRIPE_API_KEY
STRIPE_WEBHOOK_SECRET
RESEND_API_KEY
EMAIL_SEND
EMAIL_RECEIVE
PROJECT_ID: ${{ secrets.PROJECT_ID }}
PROJECT_NUMBER: ${{ secrets.PROJECT_NUMBER }}
REGION: ${{ secrets.REGION }}
TAG: latest
DEPLOY_CONFIG: >-
port:8080
execution-environment:gen2
concurrency:80
service-min-instances:default
min-instances:default
max-instances:1
steps:
- name: Check if running in the parent repository
Expand All @@ -79,7 +102,7 @@ jobs:
run: chmod +x target/release/prepyrus_runner/prepyrus_runner

- name: Run prepyrus in PROCESS mode
run: target/release/prepyrus_runner/prepyrus_runner absolute_bibliography.bib src/pages process
run: target/release/prepyrus_runner/prepyrus_runner absolute_bibliography.bib content process

- name: GCP Auth
uses: "google-github-actions/auth@v2"
Expand All @@ -88,6 +111,8 @@ jobs:

- name: Set up Cloud SDK
uses: "google-github-actions/setup-gcloud@v2"
with:
install_components: beta

- name: Docker Auth
id: docker-auth
Expand All @@ -97,6 +122,25 @@ jobs:
password: "${{ secrets.GOOGLE_CREDENTIALS }}"
registry: "${{ env.REGION }}-docker.pkg.dev"

- name: Verify Artifact Registry
# Verify artifact registry exists, otherwise create one
run: |
set +e # Temporarily allow errors
gcloud artifacts repositories describe ${{ env.SERVICE }} --location=${{ env.REGION }} --format='value(name)' > /dev/null 2>&1
STATUS=$? # Capture the exit status
set -e # Re-enable exit on error
if [ $STATUS -ne 0 ]; then
echo "🏗️ Artifact Registry not found. Attempting to create one..."
gcloud artifacts repositories create ${{ env.SERVICE }} \
--repository-format=docker \
--location=${{ env.REGION }}
gcloud artifacts repositories set-cleanup-policies ${{ env.SERVICE }} \
--location=${{ env.REGION }} \
--policy=.github/artifact_repository_cleanup_policy.json
else
echo "✅ Artifact Registry already exists."
fi
- name: Build and Push Container
# NEXT_PUBLIC_ env variables have to be set during the build phase.
run: |-
Expand All @@ -109,9 +153,12 @@ jobs:
- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{env.SERVICE}} \
--platform=managed \
--region=${{ env.REGION }} \
--max-instances=1 \
--min-instances=default \
--image="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}"
chmod +x .github/deploy_script.sh
.github/deploy_script.sh \
${{ env.PROJECT_ID }} \
${{ env.PROJECT_NUMBER }} \
${{ env.REGION }} \
${{ env.SERVICE }} \
${{ env.TAG }} \
"${{ env.SECRETS }}" \
"${{ env.DEPLOY_CONFIG }}"
76 changes: 64 additions & 12 deletions .github/workflows/prod.yaml → .github/workflows/cd_prod.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Production
name: CD Production 🚀

on:
workflow_dispatch:
Expand Down Expand Up @@ -26,7 +26,7 @@ jobs:
run: cargo build --release --package prepyrus_runner

- name: Run prepyrus script in VERIFY mode
run: target/release/prepyrus_runner absolute_bibliography.bib src/pages verify
run: target/release/prepyrus_runner absolute_bibliography.bib content verify

- name: Upload prepyrus for next job
uses: actions/upload-artifact@v4
Expand All @@ -48,10 +48,36 @@ jobs:
environment: prod
runs-on: ubuntu-latest
env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
SERVICE: ${{ secrets.SERVICE }}
BUILD_PATH:
SECRETS: >-
DATABASE_URL
AUTH_URL
AUTH_SECRET
AUTH_GITHUB_ID
AUTH_GITHUB_SECRET
AUTH_GOOGLE_ID
AUTH_GOOGLE_SECRET
AUTH_RESEND_KEY
AUTH_EMAIL_FROM
GCP_PRIMARY_BUCKET_NAME
GCP_SECONDARY_BUCKET_NAME
STRIPE_API_KEY
STRIPE_WEBHOOK_SECRET
RESEND_API_KEY
EMAIL_SEND
EMAIL_RECEIVE
PROJECT_ID: ${{ secrets.PROJECT_ID }}
PROJECT_NUMBER: ${{ secrets.PROJECT_NUMBER }}
REGION: ${{ secrets.REGION }}
TAG: latest
DEPLOY_CONFIG: >-
port:8080
execution-environment:gen2
concurrency:80
service-min-instances:default
min-instances:default
max-instances:1
steps:
- name: Check if running in the parent repository
Expand All @@ -64,8 +90,10 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

repository: ${{ github.repository }}
ref: ${{ github.ref }}
fetch-depth: 1

- name: Download prepyrus artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -76,7 +104,7 @@ jobs:
run: chmod +x target/release/prepyrus_runner/prepyrus_runner

- name: Run prepyrus in PROCESS mode
run: target/release/prepyrus_runner/prepyrus_runner absolute_bibliography.bib src/pages process
run: target/release/prepyrus_runner/prepyrus_runner absolute_bibliography.bib content process

- name: GCP Auth
uses: "google-github-actions/auth@v2"
Expand All @@ -85,6 +113,8 @@ jobs:

- name: Set up Cloud SDK
uses: "google-github-actions/setup-gcloud@v2"
with:
install_components: beta

- name: Docker Auth
id: docker-auth
Expand All @@ -94,6 +124,25 @@ jobs:
password: "${{ secrets.GOOGLE_CREDENTIALS }}"
registry: "${{ env.REGION }}-docker.pkg.dev"

- name: Verify Artifact Registry
# Verify artifact registry exists, otherwise create one
run: |
set +e # Temporarily allow errors
gcloud artifacts repositories describe ${{ env.SERVICE }} --location=${{ env.REGION }} --format='value(name)' > /dev/null 2>&1
STATUS=$? # Capture the exit status
set -e # Re-enable exit on error
if [ $STATUS -ne 0 ]; then
echo "🏗️ Artifact Registry not found. Attempting to create one..."
gcloud artifacts repositories create ${{ env.SERVICE }} \
--repository-format=docker \
--location=${{ env.REGION }}
gcloud artifacts repositories set-cleanup-policies ${{ env.SERVICE }} \
--location=${{ env.REGION }} \
--policy=.github/artifact_repository_cleanup_policy.json
else
echo "✅ Artifact Registry already exists."
fi
- name: Build and Push Container
# NEXT_PUBLIC_ env variables have to be set during the build phase.
run: |-
Expand All @@ -106,9 +155,12 @@ jobs:
- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{env.SERVICE}} \
--platform=managed \
--region=${{ env.REGION }} \
--max-instances=2 \
--min-instances=default \
--image="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}"
chmod +x .github/deploy_script.sh
.github/deploy_script.sh \
${{ env.PROJECT_ID }} \
${{ env.PROJECT_NUMBER }} \
${{ env.REGION }} \
${{ env.SERVICE }} \
${{ env.TAG }} \
"${{ env.SECRETS }}" \
"${{ env.DEPLOY_CONFIG }}"
Loading

0 comments on commit 4a37de5

Please sign in to comment.