This is a Next.js project bootstrapped with create-next-app
.
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
Open http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.tsx
. The page auto-updates as you edit the file.
This project uses next/font
to automatically optimize and load Inter, a custom Google Font.
To initialize for the first time:
npm init playwright
To tun tests:
npx playwright test
To show reports after above command:
npx playwright show-report
To run tests with interactive ui:
npx playwright test --ui
To use codegen tool:
npx playwright codegen
- Install Docker on your machine.
- Build your container:
docker build -t your-username/nextjs-app:latest .
. - Push to registry:
docker push your-username/nextjs-app:latest
- Run your container:
docker run -p 3000:3000 your-username/nextjs-app
.
Tip to pass env variables use --build-arg
option eg.: docker build -t nextjs-app --build-arg database-url=DSN .
You can view your images created with docker images
.
You can change directory to infra or operate from root directory
To apply deployment run:
kubectl apply -f ./infra/deployment.yaml
This command instructs Kubernetes to create and manage the deployment based on the configuration in the YAML file.
To make our app accessible from outside the cluster, we need to expose it using a Kubernetes Service. Apply service configuration by command:
kubectl apply -f ./infra/service.yaml
kubectl get services nextjs-service
To scale your app, you can simply adjust the replicas field in the deployment configuration (deployment.yaml
). For instance, to scale up to 5 replicas:
spec:
replicas: 5
Apply the updated configuration with:
kubectl apply -f ./infra/deployment.yaml
When you need to update your app, make changes to your code and build a new Docker image. Then, update the image tag in the deployment configuration (deployment.yaml
):
spec:
template:
spec:
containers:
- name: nextjs-app
image: nextjs-app:newtag # Update the tag
Apply the updated configuration to apply the changes:
kubectl apply -f ./infra/deployment.yaml
To add support for Docker to an existing project, just copy the Dockerfile
into the root of the project and add the following to the next.config.js
file:
// next.config.js
module.exports = {
// ... rest of the configuration.
output: "standalone",
};
This will build the project as a standalone app inside the Docker image.
-
Install the Google Cloud SDK so you can use
gcloud
on the command line. -
Run
gcloud auth login
to log in to your account. -
Create a new project in Google Cloud Run (e.g.
nextjs-docker
). Ensure billing is turned on. -
Build your container image using Cloud Build:
gcloud builds submit --tag gcr.io/PROJECT-ID/helloworld --project PROJECT-ID
. This will also enable Cloud Build for your project. -
Deploy to Cloud Run:
gcloud run deploy --image gcr.io/PROJECT-ID/helloworld --project PROJECT-ID --platform managed --allow-unauthenticated
. Choose a region of your choice.- You will be prompted for the service name: press Enter to accept the default name,
helloworld
. - You will be prompted for region: select the region of your choice, for example
us-central1
.
- You will be prompted for the service name: press Enter to accept the default name,
First, run the development server:
npm run dev
# or
yarn dev
Open http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying pages/index.js
. The page auto-updates as you edit the file.
API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.js
.
The pages/api
directory is mapped to /api/*
. Files in this directory are treated as API routes instead of React pages.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.