Skip to content

Commit

Permalink
feat: add fly deploy config
Browse files Browse the repository at this point in the history
  • Loading branch information
schwepps committed Oct 8, 2024
1 parent b6b9887 commit e028606
Show file tree
Hide file tree
Showing 24 changed files with 2,758 additions and 9,562 deletions.
40 changes: 40 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local
.env
.env.deploy

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

.vscode
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: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ yarn-error.log*
# local env files
.env*.local
.env
.env.deploy

# vercel
.vercel
Expand Down
78 changes: 78 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=20.13.1
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Next.js"

# Next.js app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"
ARG NEXT_PUBLIC_GRAPHQL_API_URL
ENV NEXT_PUBLIC_GRAPHQL_API_URL=$NEXT_PUBLIC_GRAPHQL_API_URL

ARG NEXT_PUBLIC_MAPBOX_KEY
ENV NEXT_PUBLIC_MAPBOX_KEY=$NEXT_PUBLIC_MAPBOX_KEY

ARG NEXT_PUBLIC_TRACKING_ACTIVATED
ENV NEXT_PUBLIC_TRACKING_ACTIVATED=$NEXT_PUBLIC_TRACKING_ACTIVATED

ARG NEXT_PUBLIC_SANITY_API_VERSION
ENV NEXT_PUBLIC_SANITY_API_VERSION=$NEXT_PUBLIC_SANITY_API_VERSION

ARG NEXT_PUBLIC_SANITY_DATASET
ENV NEXT_PUBLIC_SANITY_DATASET=$NEXT_PUBLIC_SANITY_DATASET

ARG NEXT_PUBLIC_SANITY_PROJECT_ID
ENV NEXT_PUBLIC_SANITY_PROJECT_ID=$NEXT_PUBLIC_SANITY_PROJECT_ID

ARG NEXT_PUBLIC_CLERK_SIGN_IN_URL
ENV NEXT_PUBLIC_CLERK_SIGN_IN_URL=$NEXT_PUBLIC_CLERK_SIGN_IN_URL

ARG NEXT_PUBLIC_CLERK_SIGN_UP_URL
ENV NEXT_PUBLIC_CLERK_SIGN_UP_URL=$NEXT_PUBLIC_CLERK_SIGN_UP_URL

ARG NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
ENV NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=$NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY

ARG NEXT_PUBLIC_ENABLED_MENU_ITEMS
ENV NEXT_PUBLIC_ENABLED_MENU_ITEMS=$NEXT_PUBLIC_ENABLED_MENU_ITEMS

# Install pnpm
ARG PNPM_VERSION=9.9.0
RUN npm install -g pnpm@$PNPM_VERSION


# 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 .npmrc package-lock.json package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prod=false

# Copy application code
COPY . .

# Build application
RUN pnpm run build

# Remove development dependencies
RUN pnpm prune --prod


# 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 [ "pnpm", "run", "start" ]
36 changes: 36 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Initialize variables
CONFIG_FILE=""

# Parse command line arguments
while getopts ":c:" opt; do
case $opt in
c)
CONFIG_FILE="-c $OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done

# Read .env file
set -a
source .env.deploy
set +a

# Construct build args string
BUILD_ARGS=""
for var in "${!NEXT_PUBLIC_@}"; do
BUILD_ARGS="$BUILD_ARGS --build-arg $var=${!var}"
done

# Deploy with build args and optional config file
echo "Deploying with command: fly deploy $CONFIG_FILE $BUILD_ARGS"
fly deploy $CONFIG_FILE $BUILD_ARGS
22 changes: 22 additions & 0 deletions fly-debug.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# fly.toml app configuration file generated for debug-ccrp-front on 2024-10-08T16:17:32+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'debug-ccrp-front'
primary_region = 'cdg'

[build]

[http_service]
internal_port = 3000
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
33 changes: 33 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# fly.toml app configuration file generated for debug-ccrp-front on 2024-10-08T16:17:32+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'ccrp-front'
primary_region = 'cdg'

[build]
[build.args]
NEXT_PUBLIC_GRAPHQL_API_URL = ""
NEXT_PUBLIC_MAPBOX_KEY = ""
NEXT_PUBLIC_TRACKING_ACTIVATED = ""
NEXT_PUBLIC_SANITY_API_VERSION = ""
NEXT_PUBLIC_SANITY_DATASET = ""
NEXT_PUBLIC_SANITY_PROJECT_ID = ""
NEXT_PUBLIC_CLERK_SIGN_IN_URL = ""
NEXT_PUBLIC_CLERK_SIGN_UP_URL = ""
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY = ""
NEXT_PUBLIC_ENABLED_MENU_ITEMS = ""

[http_service]
internal_port = 3000
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
8 changes: 0 additions & 8 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,4 @@ const requiredEnvVars = [
'CLERK_SECRET_KEY',
];

requiredEnvVars.forEach((envVar) => {
if (!process.env[envVar]) {
throw new Error(
`Environment variable ${envVar} is missing! Please set it before starting the application.`,
);
}
});

export default nextConfig;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
"@graphql-codegen/cli": "^5.0.2",
"@graphql-codegen/client-preset": "^4.3.3",
"@graphql-tools/schema": "^10.0.6",
"@graphql-typed-document-node/core": "^3.2.0",
"@headlessui/react": "^2.1.3",
"@heroicons/react": "^2.1.5",
"@nextui-org/react": "^2.4.6",
"@portabletext/react": "^3.1.0",
"@sanity/image-url": "^1.0.2",
"framer-motion": "^11.3.17",
"graphql": "^16.9.0",
"mapbox-gl": "^3.6.0",
"moment": "^2.30.1",
"next": "14.2.4",
Expand All @@ -35,6 +37,7 @@
"recharts": "^2.12.7"
},
"devDependencies": {
"@flydotio/dockerfile": "^0.5.9",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
Loading

0 comments on commit e028606

Please sign in to comment.