diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..40b878db --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/.github/workflows/web.yaml b/.github/workflows/web.yaml index 5d735be6..4ef19a20 100644 --- a/.github/workflows/web.yaml +++ b/.github/workflows/web.yaml @@ -36,34 +36,24 @@ jobs: run: | pnpm run test:web - deploy: + build: needs: validate if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest - name: Deploy + name: Build and push docker image steps: - name: Checkout uses: actions/checkout@v2 - - name: Install Node.js - uses: actions/setup-node@v3 + - name: Login to Docker Hub + uses: docker/login-action@v1 with: - node-version: 20 + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - - name: Install pnpm - uses: pnpm/action-setup@v2 - with: - version: 8 - run_install: false - - - name: Install packages - run: | - pnpm i + - name: Build Docker image + run: docker build -t keyshade/keyshade-web:latest -f Dockerfile-web . - - name: Build and deploy - run: | - pnpm install --global vercel - vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} - vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} - vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} + - name: Push Docker image + run: docker push keyshade/keyshade-web diff --git a/Dockerfile-web b/Dockerfile-web new file mode 100644 index 00000000..be12b92e --- /dev/null +++ b/Dockerfile-web @@ -0,0 +1,18 @@ +FROM node:20-alpine as build + +WORKDIR /app + +RUN npm i -g pnpm + +COPY package.json . +COPY tsconfig.base.json . + +RUN pnpm install + +COPY apps/web apps/web + +RUN pnpm run build:web + +EXPOSE 3000 + +ENTRYPOINT ["pnpm", "run", "start:web"] \ No newline at end of file diff --git a/apps/web/next.config.js b/apps/web/next.config.js index e562b22c..17994a2e 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -4,6 +4,7 @@ const { composePlugins, withNx } = require('@nx/next') * @type {import('@nx/next/plugins/with-nx').WithNxOptions} **/ const nextConfig = { + distDir: 'dist/.next', webpack(config, { isServer }) { config.module.rules.push({ test: /\.svg$/, diff --git a/apps/web/project.json b/apps/web/project.json index 1319f712..3bf07d7e 100644 --- a/apps/web/project.json +++ b/apps/web/project.json @@ -14,7 +14,7 @@ }, "serve": { "executor": "@nx/next:server", - "defaultConfiguration": "development", + "defaultConfiguration": "production", "options": { "buildTarget": "web:build", "dev": true, diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 4a2530b7..b047d0cd 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -30,7 +30,8 @@ "../../dist/apps/web/.next/types/**/*.ts", "next-env.d.ts", ".next/types/**/*.ts", - "../../apps/web/dist/.next/types/**/*.ts" + "../../apps/web/dist/.next/types/**/*.ts", + "dist/.next/types/**/*.ts" ], "exclude": [ "node_modules", diff --git a/package.json b/package.json index 4758fecc..cb00167d 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "test:workspace": "nx run workspace:test", "test:cli": "nx run cli:test", "test:sdk-node": "nx run sdk-js:test", + "start:web": "nx run web:serve", "db:seed": "cd apps/api/src/prisma && pnpx ts-node seed.ts", "db:generate-types": "nx run api:prisma:generate", "db:generate-migrations": "cd apps/api/src/prisma && pnpx prisma migrate dev --create-only --skip-seed",