Skip to content

Commit

Permalink
Deploy to fly.io
Browse files Browse the repository at this point in the history
  • Loading branch information
errorsolver committed Aug 26, 2024
1 parent 4b3bbc7 commit 72c8b9a
Show file tree
Hide file tree
Showing 8 changed files with 2,086 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
purpose.txt
.env
18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules
purpose.txt
package-lock.json
.env
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=20.16.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

# 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
EXPOSE 3000
CMD [ "npm", "run", "start" ]
8 changes: 4 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const app = express()
app.use(helmet())
app.use(cors(
{
origin: 'http://127.0.0.1:5500',
origin: 'http://127.0.0.1:3000',
credentials: true,
}
))
Expand All @@ -28,9 +28,9 @@ app.use('/js', express.static(__dirname + '/js'))

app.use((req, res, next) => {
res.setHeader("Content-Security-Policy", "script-src 'self' 'unsafe-inline'");
// res.setHeader('Access-Control-Allow-Credentials', 'true');
// res.setHeader('Access-Control-Expose-Headers', 'Set-Cookie')
// res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
// res.setHeader('Access-Control-Allow-Credentials', 'true');
// res.setHeader('Access-Control-Expose-Headers', 'Set-Cookie')
// res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');

next();
});
Expand Down
20 changes: 20 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# fly.toml app configuration file generated for messanger-apps on 2024-08-26T23:16:22+07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'messanger-apps'
primary_region = 'sin'

[build]

[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = 'off'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
size = 'shared-cpu-1x'
Loading

0 comments on commit 72c8b9a

Please sign in to comment.