diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..19272ee --- /dev/null +++ b/.dockerignore @@ -0,0 +1,107 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and *not* Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# dsStore +.DS_Store \ No newline at end of file diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml new file mode 100644 index 0000000..f3cbe5d --- /dev/null +++ b/.github/workflows/fly-deploy.yml @@ -0,0 +1,23 @@ +name: Deploy to Fly +on: [push] +jobs: + deploy: + name: Deploy proxy + runs-on: ubuntu-latest + environment: production + steps: + # Checkout to repo + - uses: actions/checkout@v4 + # Initialize fly.io CLI + - uses: superfly/flyctl-actions/setup-flyctl@master + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + - run: npm install + - run: npm run build + - run: npm run test + # Deploy to fly.io with a remote runner + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1a55692 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +# syntax = docker/dockerfile:1 + +# Adjust NODE_VERSION as desired +ARG NODE_VERSION=20.9.0 +FROM node:${NODE_VERSION}-slim as base + +LABEL fly_launch_runtime="Node.js" + +# Node.js app lives here +WORKDIR /app + +# Set production environment +ENV NODE_ENV="production" + + +# 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 pkg-config python-is-python3 + +# Install node modules +COPY --link package-lock.json package.json ./ +RUN npm ci --include=dev + +# Copy application code +COPY --link . . + +# Build application +RUN npm run build + +# Remove development dependencies +RUN npm prune --omit=dev + + +# Final stage for app image +FROM base + +# Copy built application +COPY --from=build /app /app + +# Start the server by default, this can be overwritten at runtime +EXPOSE 3000 +CMD [ "npm", "run", "start" ] diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..906d04e --- /dev/null +++ b/fly.toml @@ -0,0 +1,23 @@ +# fly.toml app configuration file generated for simple-math-api-exercise on 2024-03-11T23:13:09Z +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'simple-math-api-exercise' +primary_region = 'mad' + +[build] + +[http_service] + internal_port = 3000 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + +[[vm]] + size = 'shared-cpu-1x' + +[env] + PORT = 3000 diff --git a/index.ts b/index.ts index b735177..7820dcb 100644 --- a/index.ts +++ b/index.ts @@ -17,7 +17,7 @@ using express.js const app: Express = express(); // This is how you setup a simple GET handler -app.get('/', (req: Request, res: Response) => { +app.get('/', (_req: Request, res: Response) => { // With express, we can respond with JSON directly without having to // `JSON.stringify()` response. You might want to do this if you're building // an API @@ -56,16 +56,16 @@ app.get('/div/:a/:b', (req: Request, res: Response) => { }); // Handler for the subtraction route -app.get('/subtract/:a/:b', (req: Request, res: Response) => { - const { a, b } = { a: Number(req.params.a), b: Number(req.params.b) }; - const subtraction = subtractTwoNumbers(Number(a), Number(b)); - res.json({ - message: 'Subtract Operation', - operation: 'success', - a, - b, - subtraction - }); -}); +// app.get('/subtract/:a/:b', (req: Request, res: Response) => { +// const { a, b } = { a: Number(req.params.a), b: Number(req.params.b) }; +// const subtraction = subtractTwoNumbers(Number(a), Number(b)); +// res.json({ +// message: 'Subtract Operation', +// operation: 'success', +// a, +// b, +// subtraction +// }); +// }); export { app };