Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration for CI deployment to Fly.io #170

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fly/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
9 changes: 9 additions & 0 deletions fly/.fly/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -ex

# This command pushes us over 256MB of RAM at release time
# yarn rw prisma migrate deploy

# This alternative command uses less memory
npx prisma migrate deploy --schema /app/api/db/schema.prisma
7 changes: 7 additions & 0 deletions fly/.fly/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -ex

if [ ! -n $MIGRATE_ON_BOOT ]; then
$(dirname $0)/migrate.sh
fi
9 changes: 9 additions & 0 deletions fly/.fly/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -ex

if [ -n $MIGRATE_ON_BOOT ]; then
$(dirname $0)/migrate.sh
fi

npx rw-server --port ${PORT} $@
2 changes: 1 addition & 1 deletion fly/.yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ nmMode: hardlinks-local

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.2.0.cjs
yarnPath: .yarn/releases/yarn-3.2.0.cjs
48 changes: 48 additions & 0 deletions fly/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ARG BASE_IMAGE=node:16.13.0-alpine
FROM ${BASE_IMAGE} as base

RUN mkdir /app
WORKDIR /app

# Required for building the api and web distributions
ENV NODE_ENV development

FROM base as dependencies

COPY .yarn .yarn
COPY .yarnrc.yml .yarnrc.yml
COPY package.json package.json
COPY web/package.json web/package.json
COPY api/package.json api/package.json
COPY yarn.lock yarn.lock

RUN --mount=type=cache,target=/root/.yarn/berry/cache \
--mount=type=cache,target=/root/.cache yarn install --immutable

COPY redwood.toml .
COPY graphql.config.js .

FROM dependencies as web_build

COPY web web
RUN yarn rw build web

FROM dependencies as api_build

COPY api api
RUN yarn rw build api

FROM dependencies

ENV NODE_ENV production

COPY --from=web_build /app/web/dist /app/web/dist
COPY --from=api_build /app/api /app/api
COPY --from=api_build /app/node_modules/.prisma /app/node_modules/.prisma

COPY .fly .fly

ENTRYPOINT ["sh"]
CMD [".fly/start.sh"]


43 changes: 43 additions & 0 deletions fly/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
app = "redwood-deploy-ci"

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[deploy]
release_command = ".fly/release.sh"

[env]
PORT = "8910"
REDWOOD_DISABLE_TELEMETRY = "1"

[experimental]
allowed_public_ports = []
auto_rollback = true

[[services]]
http_checks = []
internal_port = 8910
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"