Skip to content

Commit

Permalink
Merge pull request #12 from onelikeandidie/main
Browse files Browse the repository at this point in the history
Added fly for git live session
  • Loading branch information
Unisergius authored Mar 12, 2024
2 parents 8657953 + 2e0f604 commit c0e5bd8
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 12 deletions.
107 changes: 107 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
23 changes: 23 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 12 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 };

0 comments on commit c0e5bd8

Please sign in to comment.