diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml new file mode 100644 index 0000000..b0c246e --- /dev/null +++ b/.github/workflows/fly-deploy.yml @@ -0,0 +1,18 @@ +# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ + +name: Fly Deploy +on: + push: + branches: + - main +jobs: + deploy: + name: Deploy app + runs-on: ubuntu-latest + concurrency: deploy-group # optional: ensure only one action runs at a time + steps: + - uses: actions/checkout@v4 + - uses: superfly/flyctl-actions/setup-flyctl@master + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index e69de29..0000000 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dc95ca7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +# syntax = docker/dockerfile:1 + +# Adjust NODE_VERSION as desired +ARG NODE_VERSION=22.9.0 +FROM node:${NODE_VERSION}-slim as base + +LABEL fly_launch_runtime="Node.js/Prisma" + +# Node.js/Prisma app lives here +WORKDIR /app + +# Set production environment +ENV NODE_ENV="production" + +# Install pnpm +ARG PNPM_VERSION=9.11.0 +RUN npm install -g pnpm@$PNPM_VERSION + + +# Throw-away build stage to reduce size of final image +FROM base as build + +# Install packages needed to build node modules +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential node-gyp openssl pkg-config python-is-python3 + +# Install node modules +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile --prod=false + +# Generate Prisma Client +COPY prisma . +RUN npx prisma generate + +# Copy application code +COPY . . + +# Build application +RUN pnpm run build + +# Remove development dependencies +RUN pnpm prune --prod + + +# Final stage for app image +FROM base + +# Install packages needed for deployment +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y chromium chromium-sandbox openssl && \ + rm -rf /var/lib/apt/lists /var/cache/apt/archives + +# Copy built application +COPY --from=build /app /app + +# Start the server by default, this can be overwritten at runtime +EXPOSE 3000 +ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/chromium" +CMD [ "pnpm", "run", "start" ] diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100644 index 8ea72d0..0000000 --- a/Dockerfile.dev +++ /dev/null @@ -1,27 +0,0 @@ -# Stage 1: Installer Stage -FROM node:22-alpine3.20 AS installer - -WORKDIR /usr/src/app - -RUN corepack enable && corepack prepare pnpm@9.5.0 --activate -COPY package.json pnpm-lock.yaml ./ -COPY prisma ./prisma - -RUN apk add --no-cache make gcc g++ python3 && \ - if [ -f pnpm-lock.yaml ]; then \ - pnpm install --frozen-lockfile --ignore-scripts; \ - else \ - echo "pnpm-lock.yaml not found" && exit 1; \ - fi && \ - npm rebuild bcrypt --build-from-source && \ - apk del make gcc g++ python3 - -COPY . . - -# Stage 2: Development Stage -FROM node:22-alpine3.20 AS development - -WORKDIR /usr/src/app -RUN corepack enable && corepack prepare pnpm@9.5.0 --activate -COPY --from=installer /usr/src/app/ ./ -CMD ["pnpm", "run", "dev:docker"] diff --git a/Dockerfile.prod b/Dockerfile.prod deleted file mode 100644 index 95b7183..0000000 --- a/Dockerfile.prod +++ /dev/null @@ -1,32 +0,0 @@ -# Stage 1: Builder Stage -FROM node:22-alpine3.20 AS builder -WORKDIR /usr/src/app - -RUN corepack enable && corepack prepare pnpm@9.5.0 --activate - -COPY package.json pnpm-lock.yaml ./ -COPY prisma ./prisma - -RUN apk add --no-cache make gcc g++ python3 && \ - if [ -f pnpm-lock.yaml ]; then \ - pnpm install --frozen-lockfile --ignore-scripts; \ - else \ - echo "pnpm-lock.yaml not found" && exit 1; \ - fi && \ - npm rebuild bcrypt --build-from-source && \ - apk del make gcc g++ python3 - -COPY . . - -RUN DATABASE_URL=$DATABASE_URL pnpm run build - -# Stage 2: Production Stage -FROM node:22-alpine3.20 AS production -WORKDIR /usr/src/app - -COPY --from=builder /usr/src/app/dist ./dist -COPY --from=builder /usr/src/app/node_modules/ ./node_modules - -EXPOSE 3000 - -CMD [ "node", "dist/index.js" ] \ No newline at end of file diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..b1840e5 --- /dev/null +++ b/fly.toml @@ -0,0 +1,27 @@ +# fly.toml app configuration file generated for phishdirectory-api on 2024-10-29T00:30:08-04:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'phishdirectory-api' +primary_region = 'yul' +kill_signal = 'SIGINT' +kill_timeout = '5s' + +[build] + +[deploy] + release_command = 'npx prisma migrate dev' + +[http_service] + internal_port = 3000 + force_https = true + auto_stop_machines = 'stop' + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1 diff --git a/package.json b/package.json index 75c02f3..29e2d0a 100644 --- a/package.json +++ b/package.json @@ -10,22 +10,13 @@ "url": "https://jaspermayone.com" } ], - "packageManager": "pnpm@9.5.0", "scripts": { - "preinstall": "npx only-allow pnpm", "start": "node dist/index.js", - "postinstall": "npx prisma generate && tsc", "watch-node": "nodemon dist/index.js", "watch-ts": "tsc -w", "dev": "nodemon --quiet --watch './**/*.ts' --exec 'ts-node' src/index.ts", "build": "npx prisma generate && tsc", - "compile": "npx prisma generate && tsc", - "heroku-prebuild": "echo This runs before Heroku installs dependencies.", - "heroku-postbuild": "echo This runs after Heroku installs dependencies, but before Heroku prunes and caches dependencies.", - "heroku-cleanup": "echo This runs after Heroku prunes and caches dependencies.", - "prepare": "husky", - "prisma:docker": "npx prisma generate && npx prisma migrate dev", - "dev:docker": "pnpm prisma:docker && pnpm dev" + "compile": "npx prisma generate && tsc" }, "keywords": [], "author": "Jasper Mayone ", @@ -56,14 +47,12 @@ "@types/node-statsd": "^0.1.6", "@types/request-ip": "^0.0.41", "@types/response-time": "^2.3.8", - "husky": "^9.1.4", "nodemon": "^3.1.4", "prisma": "^5.18.0", "typescript": "^5.5.4" }, "engines": { "node": "22.x", - "npm": "10.8.2", - "pnpm": "9.5.0" + "npm": "10.8.2" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2a771f8..e4bcd45 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -81,9 +81,6 @@ importers: '@types/response-time': specifier: ^2.3.8 version: 2.3.8 - husky: - specifier: ^9.1.4 - version: 9.1.4 nodemon: specifier: ^3.1.4 version: 3.1.4 @@ -718,11 +715,6 @@ packages: resolution: {integrity: sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==} engines: {node: '>= 14'} - husky@9.1.4: - resolution: {integrity: sha512-bho94YyReb4JV7LYWRWxZ/xr6TtOTt8cMfmQ39MQYJ7f/YE268s3GdghGwi+y4zAeqewE5zYLvuhV0M0ijsDEA==} - engines: {node: '>=18'} - hasBin: true - iconv-lite@0.4.24: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} @@ -2031,8 +2023,6 @@ snapshots: transitivePeerDependencies: - supports-color - husky@9.1.4: {} - iconv-lite@0.4.24: dependencies: safer-buffer: 2.1.2