From 228b4a7b94763e8347a4f898805be24997a1f985 Mon Sep 17 00:00:00 2001 From: Dominic Ferrando Date: Sun, 4 May 2025 15:23:05 -0400 Subject: [PATCH] Fly.io setup with 1 machine --- .dockerignore | 5 +++++ .github/workflows/fly-deploy.yml | 18 ++++++++++++++++ Dockerfile | 35 ++++++++++++++++++++++++++++++++ fly.toml | 25 +++++++++++++++++++++++ main.ts | 5 +++++ package.json | 3 ++- 6 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/fly-deploy.yml create mode 100644 Dockerfile create mode 100644 fly.toml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..47719be --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +fly.toml +Dockerfile +.dockerignore +node_modules +.git 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/Dockerfile b/Dockerfile new file mode 100644 index 0000000..188447d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# syntax = docker/dockerfile:1 + +FROM oven/bun:1.2.12-slim as base + +LABEL fly_launch_runtime="Bun" + +# NodeJS 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 -y python-is-python3 pkg-config build-essential + +# Install node modules +COPY --link package.json . +RUN bun install --production + +# Copy application code +COPY --link . . + +# 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 +CMD [ "bun", "run", "start" ] diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..c3d1029 --- /dev/null +++ b/fly.toml @@ -0,0 +1,25 @@ +# fly.toml app configuration file generated for blade-and-brawn on 2025-05-04T14:56:24-04:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'blade-and-brawn' +primary_region = 'ord' + +[build] + +[env] + PORT = '8080' + +[http_service] + internal_port = 8080 + 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/main.ts b/main.ts index cfbc9f0..baa6c24 100644 --- a/main.ts +++ b/main.ts @@ -6,6 +6,11 @@ const productRecords = new ProductRecords(); const server = Bun.serve({ routes: { + "/test": { + async GET(req){ + return Response.json("Hello world"); + } + }, "/webhook/printful": { async POST(req) { const payload: Printful.Webhook.EventPayload = await req.json() diff --git a/package.json b/package.json index 8f5b278..9c39e5b 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "@types/bun": "^1.2.11" }, "scripts": { - "db:seed": "sqlite3 ./database/data.db < ./database/seed.sql" + "db:seed": "sqlite3 ./database/data.db < ./database/seed.sql", + "start": "bun run main.ts" } }