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

feat: docker deployment #51

Merged
merged 9 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ignore all .env files in any directory or subdirectory
**/.env

# Ignore node_modules and dist directories in any directory or subdirectory
**/node_modules
**/dist

**/.git
**/*.md
**/cypress
**/.github
.next
!.next/static
!.next/standalone
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Use an official Node.js image as a parent image
FROM node:20 AS build
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

# # Install pnpm globally
# RUN npm install -g pnpm


# Set the working directory in the container
WORKDIR /app

# Copy pnpm-lock.yaml and package.json files
COPY package.json pnpm-lock.yaml ./

# Install dependencies using pnpm
RUN CI=1 pnpm install --frozen-lockfile

# Copy the rest of the application code
COPY . .

# Build the application
RUN pnpm build

# Use a lighter Node.js image for the final stage
FROM node:20-slim AS ui
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV NODE_ENV=production
RUN corepack enable

# Set the working directory in the container
WORKDIR /app

# Copy only necessary files from the build stage
COPY --from=build /app/package.json /app/pnpm-lock.yaml ./
COPY --from=build /app/public ./public
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static


# # Install only production dependencies with pnpm
# RUN CI=1 pnpm install --no-frozen-lockfile

# Expose the port on which the application will run
EXPOSE 5173
ENV PORT=5173

# Specify the command to run the application
CMD ["node", "server.js"]
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@ Vercel will automatically deploy your project and provide a live URL.
- **[Vercel CLI Documentation](https://vercel.com/docs/cli)**: Find comprehensive information on using the Vercel CLI.
- **[Vercel Documentation](https://vercel.com/docs)**: Access general Vercel documentation and guides.

## 🐳 Docker deployment

## Prerequisites

- **Docker**: Ensure that Docker is installed.

## Deployment Steps

1. **Build the Docker Image**

From your project directory, build the Docker image by running the following command:

```bash
docker build -t <app-name> .
```

2. **Run the Docker Container**

After the image is built, run the Docker container with the environment variables.

```bash
docker run -p 5173:5173 --env-file .env <app-name>
```

3. **Access your app:**

http://localhost:5173

## Development

### 💻 Conventional Commits
Expand Down
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const nextConfig = {
locales: ['en', 'es'],
defaultLocale: 'en',
},
output: 'standalone',
};

export default nextConfig;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"prettier:fix": "pnpm run prettier -- --write",
"format": "pnpm run prettier:fix && yarn run lint:fix",
"format:check": "pnpm run prettier && yarn run lint",
"prepare": "husky install && wonderland-crypto-husky-checks install",
"prepare": "husky install && (is-ci || wonderland-crypto-husky-checks install)",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"test:e2e": "pnpm cypress run",
Expand All @@ -42,6 +42,7 @@
"@tanstack/react-query": "5.28.0",
"cypress": "13.14.1",
"i18next": "23.7.6",
"is-ci": "3.0.1",
"next": "14.2.5",
"next-i18next": "15.2.0",
"react": "18.2.0",
Expand All @@ -64,6 +65,7 @@
"@types/react-dom": "18.2.7",
"@typescript-eslint/eslint-plugin": "6.0.0",
"@typescript-eslint/parser": "6.0.0",
"cypress": "13.14.1",
"eslint": "8.45.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.28.1",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading