Skip to content

Commit

Permalink
Merge pull request #136 from P4-Games/develop
Browse files Browse the repository at this point in the history
merge develop into main
  • Loading branch information
dappsar authored Oct 27, 2024
2 parents 2e1cc6e + 7551d26 commit 4b296df
Show file tree
Hide file tree
Showing 54 changed files with 1,453 additions and 1,009 deletions.
12 changes: 11 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


FROM node:18-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
Expand All @@ -15,6 +17,8 @@ ARG BOT_API_TOKEN
ARG BOT_API_URL
ARG BOT_API_WAPP_ENABLED
ARG BACKEND_API_URL
ARG BACKEND_API_TOKEN
ARG BACKEND_API_TOKEN_SECRET
ARG NODE_PROVIDER_SEPOLIA_URL
ARG NODE_PROVIDER_MUMBAI_URL
ARG NODE_PROVIDER_SCROLL_URL
Expand All @@ -29,7 +33,6 @@ ARG RECAPTCHA_API_KEY
ARG NEXT_PUBLIC_RECAPTCHA_SITE_KEY
ARG NEXT_PUBLIC_NFT_IMAGE_REPOSITORY
ARG NEXT_PUBLIC_NFT_MARKETPLACE_URL

#
# env
ENV NODE_ENV production
Expand All @@ -41,6 +44,8 @@ ENV BOT_API_TOKEN $BOT_API_TOKEN
ENV BOT_API_URL $BOT_API_URL
ENV BOT_API_WAPP_ENABLED $BOT_API_WAPP_ENABLED
ENV BACKEND_API_URL $BACKEND_API_URL
ENV BACKEND_API_TOKEN $BACKEND_API_TOKEN
ENV BACKEND_API_TOKEN_SECRET $BACKEND_API_TOKEN_SECRET
ENV NODE_PROVIDER_SEPOLIA_URL $NODE_PROVIDER_SEPOLIA_URL
ENV NODE_PROVIDER_MUMBAI_URL $NODE_PROVIDER_MUMBAI_URL
ENV NODE_PROVIDER_SCROLL_URL $NODE_PROVIDER_SCROLL_URL
Expand All @@ -58,14 +63,19 @@ ENV NEXT_PUBLIC_NFT_MARKETPLACE_URL $NEXT_PUBLIC_NFT_MARKETPLACE_URL
#
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN echo "***********************"
RUN env
RUN echo $BACKEND_API_TOKEN
RUN echo $BACKEND_API_TOKEN_SECRET
RUN echo "***********************"

RUN npm run build
#
FROM node:18-alpine AS runner
WORKDIR /app
ENV NODE_ENV production

RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
Expand Down
137 changes: 84 additions & 53 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
steps:
# Para para generar un .env para que sea tomado por el step de build.
# Las variables serán tomadas de la definición del "trigger",
# "variables de sustitución", en Google Cloud Build.
# en gcp, se tiene que poner como nombre de cada variable, el unserscore
# como prefijo. Ejemplo: "_APP_ENV"
#
# This step is kept as a workaround, generating a .env file that is required by the
# library used with MongoDB. If it is removed, attempting to connect to the database
# throws an error indicating that the URI does not exist in the environment.
#
- name: 'gcr.io/cloud-builders/npm'
id: CreateEnv
Expand All @@ -17,6 +16,8 @@ steps:
- BOT_API_URL=${_BOT_API_URL}
- BOT_API_WAPP_ENABLED=${_BOT_API_WAPP_ENABLED}
- BACKEND_API_URL=${_BACKEND_API_URL}
- BACKEND_API_TOKEN=${_BACKEND_API_TOKEN}
#- BACKEND_API_TOKEN_SECRET=$$BACKEND_API_TOKEN_SECRET
- NODE_PROVIDER_SEPOLIA_URL=${_NODE_PROVIDER_SEPOLIA_URL}
- NODE_PROVIDER_MUMBAI_URL=${_NODE_PROVIDER_MUMBAI_URL}
- NODE_PROVIDER_SCROLL_URL=${_NODE_PROVIDER_SCROLL_URL}
Expand All @@ -31,67 +32,97 @@ steps:
- NEXT_PUBLIC_RECAPTCHA_SITE_KEY=${_NEXT_PUBLIC_RECAPTCHA_SITE_KEY}
- NEXT_PUBLIC_NFT_IMAGE_REPOSITORY=${_NEXT_PUBLIC_NFT_IMAGE_REPOSITORY}
- NEXT_PUBLIC_NFT_MARKETPLACE_URL=${_NEXT_PUBLIC_NFT_MARKETPLACE_URL}

# build the container images
- name: "gcr.io/cloud-builders/docker"
secretEnv: [
'BACKEND_API_TOKEN_SECRET'
]
#
# Build docker imagen.
# Variables with a prefix '_' are from Cloud Build 'substitution' (declared in the job).
# Variables with a prefix '$$' are from Secret Manager.
#
- name: 'gcr.io/cloud-builders/docker'
id: Build
args: [
"build",
"--no-cache",
"-t",
"$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA",
"--build-arg", "APP_ENV=${_APP_ENV}",
"--build-arg", "MONGODB=${_MONGODB}",
"--build-arg", "MONGODB_BOT=${_MONGODB_BOT}",
"--build-arg", "DB_CHATTERPAY_NAME=${_DB_CHATTERPAY_NAME}",
"--build-arg", "RECAPTCHA_API_KEY=${_RECAPTCHA_API_KEY}",
"--build-arg", "NEXT_PUBLIC_RECAPTCHA_SITE_KEY=${_NEXT_PUBLIC_RECAPTCHA_SITE_KEY}",
"--build-arg", "NEXT_PUBLIC_NFT_IMAGE_REPOSITORY=${_NEXT_PUBLIC_NFT_IMAGE_REPOSITORY}",
"--build-arg", "NEXT_PUBLIC_NFT_MARKETPLACE_URL=${_NEXT_PUBLIC_NFT_MARKETPLACE_URL}",
"--build-arg", "BOT_API_TOKEN=${_BOT_API_TOKEN}",
"--build-arg", "BOT_API_URL=${_BOT_API_URL}",
"--build-arg", "BOT_API_WAPP_ENABLED=${_BOT_API_WAPP_ENABLED}",
"--build-arg", "BACKEND_API_URL=${_BACKEND_API_URL}",
"--build-arg", "NODE_PROVIDER_SEPOLIA_URL=${_NODE_PROVIDER_SEPOLIA_URL}",
"--build-arg", "NODE_PROVIDER_MUMBAI_URL=${_NODE_PROVIDER_MUMBAI_URL}",
"--build-arg", "NODE_PROVIDER_SCROLL_URL=${_NODE_PROVIDER_SCROLL_URL}",
"--build-arg", "HANDLE_VERCEL_FREE_PLAN_TIMEOUT=${_HANDLE_VERCEL_FREE_PLAN_TIMEOUT}",
"--build-arg", "NEXT_PUBLIC_USE_MOCK=${_NEXT_PUBLIC_USE_MOCK}",
"--build-arg", "API3_ENABLED=${_API3_ENABLED}",
"--build-arg", "JWT_SECRET=${_JWT_SECRET}",
"--build-arg", "NEXT_PUBLIC_FROM_ICP=${_NEXT_PUBLIC_FROM_ICP}",
"--build-arg", "NEXT_PUBLIC_UI_URL=${_NEXT_PUBLIC_UI_URL}",
"--build-arg", "NEXT_PUBLIC_ALLOWED_ORIGINS=${_NEXT_PUBLIC_ALLOWED_ORIGINS}",
"."
'build',
'--no-cache',
'-t',
'$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA',
'--build-arg', 'APP_ENV=${_APP_ENV}',
'--build-arg', 'MONGODB=${_MONGODB}',
'--build-arg', 'MONGODB_BOT=${_MONGODB_BOT}',
'--build-arg', 'DB_CHATTERPAY_NAME=${_DB_CHATTERPAY_NAME}',
'--build-arg', 'RECAPTCHA_API_KEY=${_RECAPTCHA_API_KEY}',
'--build-arg', 'NEXT_PUBLIC_RECAPTCHA_SITE_KEY=${_NEXT_PUBLIC_RECAPTCHA_SITE_KEY}',
'--build-arg', 'NEXT_PUBLIC_NFT_IMAGE_REPOSITORY=${_NEXT_PUBLIC_NFT_IMAGE_REPOSITORY}',
'--build-arg', 'NEXT_PUBLIC_NFT_MARKETPLACE_URL=${_NEXT_PUBLIC_NFT_MARKETPLACE_URL}',
'--build-arg', 'BOT_API_TOKEN=${_BOT_API_TOKEN}',
'--build-arg', 'BOT_API_URL=${_BOT_API_URL}',
'--build-arg', 'BOT_API_WAPP_ENABLED=${_BOT_API_WAPP_ENABLED}',
'--build-arg', 'BACKEND_API_URL=${_BACKEND_API_URL}',
'--build-arg', 'BACKEND_API_TOKEN=${_BACKEND_API_TOKEN}',
'--build-arg', 'BACKEND_API_TOKEN_SECRET=$$BACKEND_API_TOKEN_SECRET',
'--build-arg', 'NODE_PROVIDER_SEPOLIA_URL=${_NODE_PROVIDER_SEPOLIA_URL}',
'--build-arg', 'NODE_PROVIDER_MUMBAI_URL=${_NODE_PROVIDER_MUMBAI_URL}',
'--build-arg', 'NODE_PROVIDER_SCROLL_URL=${_NODE_PROVIDER_SCROLL_URL}',
'--build-arg', 'HANDLE_VERCEL_FREE_PLAN_TIMEOUT=${_HANDLE_VERCEL_FREE_PLAN_TIMEOUT}',
'--build-arg', 'NEXT_PUBLIC_USE_MOCK=${_NEXT_PUBLIC_USE_MOCK}',
'--build-arg', 'API3_ENABLED=${_API3_ENABLED}',
'--build-arg', 'JWT_SECRET=${_JWT_SECRET}',
'--build-arg', 'NEXT_PUBLIC_FROM_ICP=${_NEXT_PUBLIC_FROM_ICP}',
'--build-arg', 'NEXT_PUBLIC_UI_URL=${_NEXT_PUBLIC_UI_URL}',
'--build-arg', 'NEXT_PUBLIC_ALLOWED_ORIGINS=${_NEXT_PUBLIC_ALLOWED_ORIGINS}',
'.'
]
secretEnv: [
'BACKEND_API_TOKEN_SECRET'
]

#
# push the container images to Container Registry
- name: "gcr.io/cloud-builders/docker"
#
- name: 'gcr.io/cloud-builders/docker'
id: Push
args: [
"push",
"$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA"
'push',
'$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
]

#
# Deploy container images to Cloud Run
- name: "gcr.io/cloud-builders/gcloud"
#
- name: 'gcr.io/cloud-builders/gcloud'
id: Deploy
entrypoint: gcloud
args: [
"run",
"deploy",
"$_SERVICE_NAME",
"--platform",
"managed",
"--region",
"$_DEPLOY_REGION",
"--image",
"$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA",
"--labels",
"managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID",
"--quiet",
"--allow-unauthenticated",
'run',
'deploy',
'$_SERVICE_NAME',
'--platform',
'managed',
'--region',
'$_DEPLOY_REGION',
'--image',
'$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA',
'--labels',
'managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID',
'--quiet',
'--allow-unauthenticated',
]
#
# print secret variables
#
- name: 'bash'
script: |
#!/usr/bin/env bash
echo 'BACKEND_API_TOKEN en cloudbuild.yaml 1: $BACKEND_API_TOKEN_SECRET'
secretEnv: [
'BACKEND_API_TOKEN_SECRET'
]

availableSecrets:
secretManager:
- versionName: 'projects/$PROJECT_ID/secrets/${_BACKEND_API_TOKEN_SECRET_NAME}/versions/latest'
env: 'BACKEND_API_TOKEN_SECRET'

images:
- $_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA

Expand Down
1 change: 1 addition & 0 deletions example_env
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ APP_ENV='development'
BOT_API_TOKEN={api token}
BOT_API_URL=http://localhost:3000
BACKEND_API_URL=https://dev.back.chatterpay.net
BACKEND_API_TOKEN='backend token'
BOT_API_WAPP_ENABLED=true
MONGODB='mongodb://localhost:27017'
MONGODB_BOT='BOT mongo db url'
Expand Down
7 changes: 7 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
'storage.googleapis.com',
'cilxj-yiaaa-aaaag-alkxq-cai.icp0.io',
'gateway.pinata.cloud',
'w.wallhaven.cc',
'img.freepik.com'],
remotePatterns: [
{
Expand All @@ -44,6 +45,12 @@ module.exports = {
hostname: 'img.freepik.com',
port: '',
pathname: '/**',
},
{
protocol: 'https',
hostname: 'w.wallhaven.cc',
port: '',
pathname: '/**',
}
],
},
Expand Down
14 changes: 9 additions & 5 deletions scripts/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ docker build \
--build-arg MONGODB="$MONGODB" \
--build-arg MONGODB_BOT="$MONGODB_BOT" \
--build-arg DB_CHATTERPAY_NAME="$DB_CHATTERPAY_NAME" \
--build-arg RECAPTCHA_API_KEY="$RECAPTCHA_API_KEY" \
--build-arg NEXT_PUBLIC_RECAPTCHA_SITE_KEY="$NEXT_PUBLIC_RECAPTCHA_SITE_KEY" \
--build-arg NEXT_PUBLIC_NFT_IMAGE_REPOSITORY="$NEXT_PUBLIC_NFT_IMAGE_REPOSITORY" \
--build-arg NEXT_PUBLIC_NFT_MARKETPLACE_URL="$NEXT_PUBLIC_NFT_MARKETPLACE_URL" \
--build-arg BOT_API_TOKEN="$BOT_API_TOKEN" \
--build-arg BOT_API_URL="$BOT_API_URL" \
--build-arg BOT_API_WAPP_ENABLED="$BOT_API_WAPP_ENABLED" \
--build-arg BACKEND_API_URL="$BACKEND_API_URL" \
--build-arg BACKEND_API_TOKEN="$BACKEND_API_TOKEN" \
--build-arg NODE_PROVIDER_SEPOLIA_URL="$NODE_PROVIDER_SEPOLIA_URL" \
--build-arg NODE_PROVIDER_MUMBAI_URL="$NODE_PROVIDER_MUMBAI_URL" \
--build-arg NODE_PROVIDER_SCROLL_URL="$NODE_PROVIDER_SCROLL_URL" \
--build-arg HANDLE_VERCEL_FREE_PLAN_TIMEOUT="$HANDLE_VERCEL_FREE_PLAN_TIMEOUT" \
--build-arg NEXT_PUBLIC_USE_MOCK="$NEXT_PUBLIC_USE_MOCK" \
--build-arg API3_ENABLED="$API3_ENABLED" \
--build-arg JWT_SECRET="$JWT_SECRET" \
--build-arg NEXT_PUBLIC_FROM_ICP="$NEXT_PUBLIC_FROM_ICP" \
--build-arg NEXT_PUBLIC_USE_MOCK="$NEXT_PUBLIC_USE_MOCK" \
--build-arg NEXT_PUBLIC_UI_URL="$NEXT_PUBLIC_UI_URL" \
--build-arg NEXT_PUBLIC_ALLOWED_ORIGINS="$NEXT_PUBLIC_ALLOWED_ORIGINS" \
--build-arg RECAPTCHA_API_KEY="$RECAPTCHA_API_KEY" \
--build-arg NEXT_PUBLIC_RECAPTCHA_SITE_KEY="$NEXT_PUBLIC_RECAPTCHA_SITE_KEY" \
--build-arg NEXT_PUBLIC_NFT_IMAGE_REPOSITORY="$NEXT_PUBLIC_NFT_IMAGE_REPOSITORY" \
--build-arg NEXT_PUBLIC_NFT_MARKETPLACE_URL="$NEXT_PUBLIC_NFT_MARKETPLACE_URL" \
-t my-nextjs-app ..
File renamed without changes.
65 changes: 0 additions & 65 deletions src/app/api/_data/_mock/_mock.ts

This file was deleted.

52 changes: 0 additions & 52 deletions src/app/api/_data/_mock/_others.ts

This file was deleted.

Loading

0 comments on commit 4b296df

Please sign in to comment.