From feb49f7c02c0a42f3d39bb75b842ceed78381252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20DEM=C4=B0RC=C4=B0?= Date: Sun, 5 Nov 2023 12:51:50 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Update=20to=20fly=20app=20v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 34 ++++++++++++++++++++ .github/workflows/deploy-to-fly.yaml | 9 ++++-- Dockerfile | 42 +++++++++++++++++++++++++ fly.toml | 47 +++++++--------------------- package.json | 1 + 5 files changed, 94 insertions(+), 39 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9dad703 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,34 @@ +# compiled output +/dist +/node_modules + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# OS +.DS_Store + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +# Others +*.env +*lock* diff --git a/.github/workflows/deploy-to-fly.yaml b/.github/workflows/deploy-to-fly.yaml index 69a0d8c..581ad5b 100644 --- a/.github/workflows/deploy-to-fly.yaml +++ b/.github/workflows/deploy-to-fly.yaml @@ -1,16 +1,19 @@ name: Fly Deploy -on: [push] +on: + push: + branches: + - main env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} jobs: deploy: - name: Deploy app + name: Deploy app to fly.io runs-on: ubuntu-latest if: contains(github.event.head_commit.message, '(deploy)') steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: superfly/flyctl-actions/setup-flyctl@master - run: flyctl deploy --remote-only diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dad9f71 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +# syntax = docker/dockerfile:1 + +# Adjust NODE_VERSION as desired +ARG NODE_VERSION=18.18.1 +FROM node:${NODE_VERSION}-slim as base + +LABEL fly_launch_runtime="NestJS" + +# NestJS 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 build-essential pkg-config python-is-python3 + +# Install node modules +COPY --link package.json yarn.lock ./ +RUN yarn install --frozen-lockfile --production=false + +# Copy application code +COPY --link . . + +# Build application +RUN yarn run build + + +# 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 [ "yarn", "run", "start" ] diff --git a/fly.toml b/fly.toml index 407cf39..c94730d 100644 --- a/fly.toml +++ b/fly.toml @@ -1,42 +1,17 @@ -# fly.toml file generated for brawlhalla on 2022-07-08T09:31:28+03:00 +# fly.toml app configuration file generated for brawlhalla on 2023-11-05T12:49:16+03:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# app = "brawlhalla" -kill_signal = "SIGINT" -kill_timeout = 5 -processes = [] +primary_region = "cdg" [build] - builder = "heroku/buildpacks:20" -[env] - PORT = "8080" - -[experimental] - allowed_public_ports = [] - auto_rollback = true - -[[services]] - http_checks = [] - internal_port = 8080 +[http_service] + internal_port = 3000 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 processes = ["app"] - protocol = "tcp" - script_checks = [] - [services.concurrency] - hard_limit = 25 - soft_limit = 20 - type = "connections" - - [[services.ports]] - force_https = true - handlers = ["http"] - port = 80 - - [[services.ports]] - handlers = ["tls", "http"] - port = 443 - - [[services.tcp_checks]] - grace_period = "1s" - interval = "15s" - restart_limit = 0 - timeout = "2s" diff --git a/package.json b/package.json index 8989c61..837c41b 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "xml2js": "^0.6.2" }, "devDependencies": { + "@flydotio/dockerfile": "^0.4.10", "@nestjs/cli": "^10.2.1", "@nestjs/schematics": "^10.0.3", "@types/morgan": "^1.9.7",