From 91edb5ccfbcb2fcd3b43f494f1605548b48edbc7 Mon Sep 17 00:00:00 2001 From: Terraform Date: Fri, 16 May 2025 09:19:38 -0700 Subject: [PATCH 1/7] Add production release CICD --- .github/workflows/aws_prod_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/aws_prod_release.yml b/.github/workflows/aws_prod_release.yml index 4484006..4b375da 100644 --- a/.github/workflows/aws_prod_release.yml +++ b/.github/workflows/aws_prod_release.yml @@ -50,7 +50,7 @@ jobs: cache: 'npm' - run: git config --global user.email devops@topia.io - run: git config --global user.name Devops - - run: npm version ${{ github.event.release.tag_name }} + - run: npm version --workspaces --include-workspace-root true ${{ github.event.release.tag_name }} - run: npm i - run: CI=false npm run build From fc3bec03840c91307ceaf1e82e9c4f8f7c0854ae Mon Sep 17 00:00:00 2001 From: Lina Date: Thu, 17 Jul 2025 12:11:27 -0700 Subject: [PATCH 2/7] increase lock time --- package-lock.json | 8 ++++---- package.json | 2 +- src/controllers/handleDropPiece.ts | 4 ++-- src/controllers/handlePlayerSelection.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index f7ec56c..c56c986 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "ISC", "dependencies": { "@googleapis/sheets": "^7.0.0", - "@rtsdk/topia": "^0.15.8", + "@rtsdk/topia": "^0.15.9", "@types/cors": "^2.8.13", "axios": "^1.5.0", "body-parser": "^1.20.2", @@ -296,9 +296,9 @@ "dev": true }, "node_modules/@rtsdk/topia": { - "version": "0.15.8", - "resolved": "https://registry.npmjs.org/@rtsdk/topia/-/topia-0.15.8.tgz", - "integrity": "sha512-T0+pZxqMn6OcDzNIGk50B3lgRWoDBOXSmwShOepNGUyM9t7Yuu7NAMsYHKYEUfXN7X948bW5CetfwWk9Cd2K4w==" + "version": "0.15.9", + "resolved": "https://registry.npmjs.org/@rtsdk/topia/-/topia-0.15.9.tgz", + "integrity": "sha512-f8P6Teee0pca9+VIcQJcnZBCNaCjc3EzDosppeYQhI+y4HC0V/YPArp6vVjVRjVKrjd1gnz7H8QArpN7L5ICSg==" }, "node_modules/@rushstack/eslint-patch": { "version": "1.10.4", diff --git a/package.json b/package.json index 4c49c34..c90f27e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "main": "src/index.ts", "dependencies": { "@googleapis/sheets": "^7.0.0", - "@rtsdk/topia": "^0.15.8", + "@rtsdk/topia": "^0.15.9", "@types/cors": "^2.8.13", "axios": "^1.5.0", "body-parser": "^1.20.2", diff --git a/src/controllers/handleDropPiece.ts b/src/controllers/handleDropPiece.ts index fe347ff..9aaea00 100644 --- a/src/controllers/handleDropPiece.ts +++ b/src/controllers/handleDropPiece.ts @@ -16,7 +16,7 @@ import { DroppedAssetInterface } from "@rtsdk/topia"; export const handleDropPiece = async (req: Request, res: Response) => { try { - const credentials = getCredentials(req.body); + const credentials = req.credentials; const { displayName, identityId, sceneDropId, urlSlug, visitorId } = credentials; const { username } = req.body; @@ -67,7 +67,7 @@ export const handleDropPiece = async (req: Request, res: Response) => { try { try { - const timestamp = new Date(Math.round(new Date().getTime() / 5000) * 5000); + const timestamp = new Date(Math.round(new Date().getTime() / 10000) * 10000); await lockDataObject(`${keyAssetId}-${resetCount}-${turnCount}-${timestamp}`, keyAsset); } catch (error) { return res.status(409).json({ message: "Move already in progress." }); diff --git a/src/controllers/handlePlayerSelection.ts b/src/controllers/handlePlayerSelection.ts index 5b9ed09..1afaded 100644 --- a/src/controllers/handlePlayerSelection.ts +++ b/src/controllers/handlePlayerSelection.ts @@ -7,7 +7,7 @@ export const handlePlayerSelection = async (req: Request, res: Response) => { try { const playerId = req.params.player; const isPlayer2 = parseInt(playerId) === 2; - const credentials = getCredentials(req.body); + const credentials = req.credentials; const { profileId, sceneDropId, urlSlug, visitorId } = credentials; const { username } = req.body; From 62e4676f6c9abdb90f58bfc7cd0e98fc83a1ae22 Mon Sep 17 00:00:00 2001 From: Lina Date: Thu, 17 Jul 2025 15:52:23 -0700 Subject: [PATCH 3/7] remove timestamp --- src/controllers/handleDropPiece.ts | 3 +-- src/utils/lockDataObject.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/controllers/handleDropPiece.ts b/src/controllers/handleDropPiece.ts index 9aaea00..136ebfb 100644 --- a/src/controllers/handleDropPiece.ts +++ b/src/controllers/handleDropPiece.ts @@ -67,8 +67,7 @@ export const handleDropPiece = async (req: Request, res: Response) => { try { try { - const timestamp = new Date(Math.round(new Date().getTime() / 10000) * 10000); - await lockDataObject(`${keyAssetId}-${resetCount}-${turnCount}-${timestamp}`, keyAsset); + await lockDataObject(`${keyAssetId}-${resetCount}-${turnCount}`, keyAsset); } catch (error) { return res.status(409).json({ message: "Move already in progress." }); } diff --git a/src/utils/lockDataObject.ts b/src/utils/lockDataObject.ts index 17a7a7f..ca6ac3d 100644 --- a/src/utils/lockDataObject.ts +++ b/src/utils/lockDataObject.ts @@ -1,3 +1,3 @@ export const lockDataObject = async (lockId, recordToLock) => { - await recordToLock.updateDataObject({}, { lock: { lockId, releaseLock: false } }); + return await recordToLock.updateDataObject({}, { lock: { lockId, releaseLock: false } }); }; From e8e151847e5880b9022a052c90046d7331a5e873 Mon Sep 17 00:00:00 2001 From: Lina Date: Thu, 17 Jul 2025 17:11:09 -0700 Subject: [PATCH 4/7] clean up fetchDroppedAssetsBySceneDropId --- src/controllers/handleDropPiece.ts | 7 +++++-- src/utils/droppedAssets/getDroppedAssetDataObject.ts | 4 +--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/controllers/handleDropPiece.ts b/src/controllers/handleDropPiece.ts index 136ebfb..b4ade97 100644 --- a/src/controllers/handleDropPiece.ts +++ b/src/controllers/handleDropPiece.ts @@ -92,9 +92,12 @@ export const handleDropPiece = async (req: Request, res: Response) => { } const world = World.create(urlSlug, { credentials }); - const droppedAssets: DroppedAssetInterface[] = await world.fetchDroppedAssetsBySceneDropId({ sceneDropId }); - const gameText = droppedAssets.find((droppedAsset) => droppedAsset.uniqueName === "gameText"); + const droppedAssets: DroppedAssetInterface[] = await world.fetchDroppedAssetsBySceneDropId({ + sceneDropId, + uniqueName: "gameText", + }); + const gameText = droppedAssets[0]; if (!shouldUpdateGame) { if (gameText) gameText.updateCustomTextAsset({}, text); throw text; diff --git a/src/utils/droppedAssets/getDroppedAssetDataObject.ts b/src/utils/droppedAssets/getDroppedAssetDataObject.ts index f95bf37..8f42aca 100644 --- a/src/utils/droppedAssets/getDroppedAssetDataObject.ts +++ b/src/utils/droppedAssets/getDroppedAssetDataObject.ts @@ -1,6 +1,5 @@ import { errorHandler, DroppedAsset, initializeDroppedAssetDataObject, World } from "../index.js"; import { Credentials, WorldDataObjectType } from "../../types/index.js"; -import { DroppedAssetInterface } from "@rtsdk/topia"; export const getDroppedAssetDataObject = async (credentials: Credentials, isKeyAsset: boolean) => { try { @@ -18,8 +17,7 @@ export const getDroppedAssetDataObject = async (credentials: Credentials, isKeyA keyAssetId = dataObject[sceneDropId].keyAssetId; } else { // find key asset by sceneDropId and unique name - const droppedAssets: DroppedAssetInterface[] = await world.fetchDroppedAssetsBySceneDropId({ sceneDropId }); - keyAsset = droppedAssets.find((droppedAsset) => droppedAsset.uniqueName === "reset"); + keyAsset = await DroppedAsset.getWithUniqueName("reset", urlSlug, process.env.INTERACTIVE_SECRET!, credentials); if (!keyAsset) throw "No key asset with the unique name 'reset' found."; keyAssetId = keyAsset?.id; } From b75a75e5ce90aec4b2ceaa921d9fe0842ce834e4 Mon Sep 17 00:00:00 2001 From: LinaBell Date: Tue, 29 Jul 2025 17:02:13 -0700 Subject: [PATCH 5/7] Add production release CICD --- .github/workflows/aws_prod_release.yml | 120 ------------------------- 1 file changed, 120 deletions(-) delete mode 100644 .github/workflows/aws_prod_release.yml diff --git a/.github/workflows/aws_prod_release.yml b/.github/workflows/aws_prod_release.yml deleted file mode 100644 index 4b375da..0000000 --- a/.github/workflows/aws_prod_release.yml +++ /dev/null @@ -1,120 +0,0 @@ -name: AWS-Build-Push-Prod -on: - release: - types: [published] - -env: - REPOSITORY: 'sdk-prod' - ECS_Cluster: "topia-prod-sdk-apps" - ENV: "prod" - reponame: "${{ github.event.repository.name }}" - -concurrency: - group: ${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -permissions: - id-token: write # This is required for requesting the JWT - contents: read # This is required for actions/checkout -jobs: - Build: - runs-on: ubuntu-latest - outputs: - service: ${{ steps.sername.outputs.service }} - steps: - - - name: Checkout - uses: actions/checkout@v4 - with: - ref: ${{ github.event.release.tag_name }} - - - name: get servicename - id: sername - run: | - service_value=$(jq -c ".\"$reponame\"" <<< '${{ vars.repo_service_map }}') - echo "$(echo $service_value | jq -c)" - if [[ $service_value == null ]]; then - echo "Service value from map is missing. Using repository name instead." - echo "service=[\""$reponame"\"]" >> "$GITHUB_OUTPUT" - elif [[ -n "$service_value" && $(echo "$service_value" | jq 'length == 0') == "true" ]]; then - echo "The app has no service deployed" - echo "service=[]" >> "$GITHUB_OUTPUT" - else - echo "service=$service_value" >> "$GITHUB_OUTPUT" - echo "Service value: $(echo $service_value | jq -c )" - fi - - - uses: actions/setup-node@v4 - with: - node-version: 20.10 - cache: 'npm' - - run: git config --global user.email devops@topia.io - - run: git config --global user.name Devops - - run: npm version --workspaces --include-workspace-root true ${{ github.event.release.tag_name }} - - run: npm i - - run: CI=false npm run build - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3.0.0 - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: arn:aws:iam::368076259134:role/github-actions-role - aws-region: us-east-1 - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v2 - with: - mask-password: 'false' - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - with: - buildkitd-flags: --debug - - - name: Image Metadata - id: metadata - uses: docker/metadata-action@v5 - with: - images: ${{ steps.login-ecr.outputs.registry }}/${{ env.REPOSITORY }} - tags: | - type=raw,value=${{ github.event.repository.name }}-${{ github.event.release.tag_name }} - - - name: Image Metadata - id: metadata-latest - uses: docker/metadata-action@v5 - with: - images: ${{ steps.login-ecr.outputs.registry }}/${{ env.REPOSITORY }} - tags: | - type=raw,value=${{ github.event.repository.name }}-latest - - - name: Build and version tag - run: | - docker build --build-arg REF=${{ github.ref}} --build-arg COMMIT_HASH=$(git rev-parse --short ${{ github.sha }}) -t ${{ steps.metadata.outputs.tags }} . - docker tag ${{ steps.metadata.outputs.tags }} ${{ steps.metadata-latest.outputs.tags }} - - - name: push docker image to Amazon ECR - run: | - docker push ${{ steps.metadata.outputs.tags }} - docker push ${{ steps.metadata-latest.outputs.tags }} - - - deploy_matrix: - runs-on: ubuntu-latest - needs: Build - strategy: - matrix: - service: ${{ fromJson(needs.Build.outputs.service) }} - steps: - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: arn:aws:iam::471112828260:role/github-actions-role - aws-region: us-east-1 - - - name: deploy - run: | - aws ecs update-service --cluster ${{ env.ECS_Cluster }} --service topia-${{ env.ENV }}-${{ matrix.service }}0 --force-new-deployment - From f330bb9053a148bed3261bf3eb3a4254f091f92f Mon Sep 17 00:00:00 2001 From: Terraform Date: Tue, 29 Jul 2025 17:03:11 -0700 Subject: [PATCH 6/7] Add production release CICD --- .github/workflows/aws_dev_release.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/aws_dev_release.yml b/.github/workflows/aws_dev_release.yml index 9674563..46ddb74 100644 --- a/.github/workflows/aws_dev_release.yml +++ b/.github/workflows/aws_dev_release.yml @@ -62,8 +62,6 @@ jobs: - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v2 - with: - mask-password: 'false' - name: Image Metadata id: metadata From fc8a59d2f8c228539456070d4e6e1a97db0d2280 Mon Sep 17 00:00:00 2001 From: Terraform Date: Tue, 29 Jul 2025 17:05:07 -0700 Subject: [PATCH 7/7] Add production release CICD --- .github/workflows/aws_prod_release.yml | 118 +++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 .github/workflows/aws_prod_release.yml diff --git a/.github/workflows/aws_prod_release.yml b/.github/workflows/aws_prod_release.yml new file mode 100644 index 0000000..3ca8116 --- /dev/null +++ b/.github/workflows/aws_prod_release.yml @@ -0,0 +1,118 @@ +name: AWS-Build-Push-Prod +on: + release: + types: [published] + +env: + REPOSITORY: 'sdk-prod' + ECS_Cluster: "topia-prod-sdk-apps" + ENV: "prod" + reponame: "${{ github.event.repository.name }}" + +concurrency: + group: ${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +permissions: + id-token: write # This is required for requesting the JWT + contents: read # This is required for actions/checkout +jobs: + Build: + runs-on: ubuntu-latest + outputs: + service: ${{ steps.sername.outputs.service }} + steps: + + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.release.tag_name }} + + - name: get servicename + id: sername + run: | + service_value=$(jq -c ".\"$reponame\"" <<< '${{ vars.repo_service_map }}') + echo "$(echo $service_value | jq -c)" + if [[ $service_value == null ]]; then + echo "Service value from map is missing. Using repository name instead." + echo "service=[\""$reponame"\"]" >> "$GITHUB_OUTPUT" + elif [[ -n "$service_value" && $(echo "$service_value" | jq 'length == 0') == "true" ]]; then + echo "The app has no service deployed" + echo "service=[]" >> "$GITHUB_OUTPUT" + else + echo "service=$service_value" >> "$GITHUB_OUTPUT" + echo "Service value: $(echo $service_value | jq -c )" + fi + + - uses: actions/setup-node@v4 + with: + node-version: 20.10 + cache: 'npm' + - run: git config --global user.email devops@topia.io + - run: git config --global user.name Devops + - run: npm version ${{ github.event.release.tag_name }} + - run: npm i + - run: CI=false npm run build + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::368076259134:role/github-actions-role + aws-region: us-east-1 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + buildkitd-flags: --debug + + - name: Image Metadata + id: metadata + uses: docker/metadata-action@v5 + with: + images: ${{ steps.login-ecr.outputs.registry }}/${{ env.REPOSITORY }} + tags: | + type=raw,value=${{ github.event.repository.name }}-${{ github.event.release.tag_name }} + + - name: Image Metadata + id: metadata-latest + uses: docker/metadata-action@v5 + with: + images: ${{ steps.login-ecr.outputs.registry }}/${{ env.REPOSITORY }} + tags: | + type=raw,value=${{ github.event.repository.name }}-latest + + - name: Build and version tag + run: | + docker build --build-arg REF=${{ github.ref}} --build-arg COMMIT_HASH=$(git rev-parse --short ${{ github.sha }}) -t ${{ steps.metadata.outputs.tags }} . + docker tag ${{ steps.metadata.outputs.tags }} ${{ steps.metadata-latest.outputs.tags }} + + - name: push docker image to Amazon ECR + run: | + docker push ${{ steps.metadata.outputs.tags }} + docker push ${{ steps.metadata-latest.outputs.tags }} + + + deploy_matrix: + runs-on: ubuntu-latest + needs: Build + strategy: + matrix: + service: ${{ fromJson(needs.Build.outputs.service) }} + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::471112828260:role/github-actions-role + aws-region: us-east-1 + + - name: deploy + run: | + aws ecs update-service --cluster ${{ env.ECS_Cluster }} --service topia-${{ env.ENV }}-${{ matrix.service }}0 --force-new-deployment +