Skip to content

Commit

Permalink
fly deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
jtoar committed Oct 11, 2023
1 parent 0e71166 commit 0781061
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Expand Up @@ -16,3 +16,5 @@ LICENSE
Dockerfile
docker-compose*
.dockerignore

fly.toml
2 changes: 1 addition & 1 deletion .env.defaults
Expand Up @@ -4,7 +4,7 @@
# into version control.

# schema.prisma defaults
DATABASE_URL=file:./dev.db
DATABASE_URL=postgresql://postgres@localhost:5432/docker-server-file-example

# location of the test database for api service scenarios (defaults to ./.redwood/test.db if not set)
# TEST_DATABASE_URL=file:./.redwood/test.db
Expand Down
9 changes: 9 additions & 0 deletions .fly/migrate.sh
@@ -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 /home/node/app/api/db/schema.prisma
7 changes: 7 additions & 0 deletions .fly/release.sh
@@ -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/start.sh
@@ -0,0 +1,9 @@
#!/bin/sh

set -ex

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

node /home/node/app/api/dist/server.js --enable-web
60 changes: 5 additions & 55 deletions Dockerfile
Expand Up @@ -37,21 +37,14 @@ FROM base as api_build
COPY --chown=node:node api api
RUN yarn redwood build api

# web prerender build
# ------------------------------------------------
FROM api_build as web_build_with_prerender

COPY --chown=node:node web web
RUN yarn redwood build web

# web build
# ------------------------------------------------
FROM base as web_build

COPY --chown=node:node web web
RUN yarn redwood build web --no-prerender

# serve api
# serve
# ------------------------------------------------
FROM node:18-bookworm-slim as api_serve

Expand Down Expand Up @@ -80,54 +73,11 @@ COPY --chown=node:node --from=api_build /home/node/app/api/dist /home/node/app/a
COPY --chown=node:node --from=api_build /home/node/app/api/db /home/node/app/api/db
COPY --chown=node:node --from=api_build /home/node/app/node_modules/.prisma /home/node/app/node_modules/.prisma

ENV NODE_ENV=production

CMD [ "node", "./api/dist/server.js" ]

# serve web
# ------------------------------------------------
FROM node:18-bookworm-slim as web_serve

USER node
WORKDIR /home/node/app

COPY --chown=node:node .yarn/plugins .yarn/plugins
COPY --chown=node:node .yarn/releases .yarn/releases
COPY --chown=node:node .yarnrc.yml .
COPY --chown=node:node web/package.json .
COPY --chown=node:node yarn.lock .

RUN --mount=type=cache,target=/home/node/.yarn/berry/cache,uid=1000 \
--mount=type=cache,target=/home/node/.cache,uid=1000 \
CI=1 yarn workspaces focus web --production

COPY --chown=node:node redwood.toml .
COPY --chown=node:node graphql.config.js .
COPY --chown=node:node .env.defaults .env.defaults

COPY --chown=node:node --from=web_build /home/node/app/web/dist /home/node/app/web/dist

ENV NODE_ENV=production \
API_HOST=http://api:8911

# We use the shell form here for variable expansion.
CMD "node_modules/.bin/rw-web-server" "--apiHost" "$API_HOST"

# console
# ------------------------------------------------
FROM base as console
ENV NODE_ENV=production

# To add more packages:
#
# ```
# USER root
#
# RUN apt-get update && apt-get install -y \
# curl
#
# USER node
# ```
COPY .fly .fly

COPY --chown=node:node api api
COPY --chown=node:node web web
COPY --chown=node:node scripts scripts
ENTRYPOINT ["sh"]
CMD [".fly/start.sh"]
11 changes: 11 additions & 0 deletions api/db/migrations/20231011000420_setup/migration.sql
@@ -0,0 +1,11 @@
-- CreateTable
CREATE TABLE "UserExample" (
"id" SERIAL NOT NULL,
"email" TEXT NOT NULL,
"name" TEXT,

CONSTRAINT "UserExample_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "UserExample_email_key" ON "UserExample"("email");
3 changes: 3 additions & 0 deletions api/db/migrations/migration_lock.toml
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
2 changes: 1 addition & 1 deletion api/db/schema.prisma
@@ -1,5 +1,5 @@
datasource db {
provider = "sqlite"
provider = "postgresql"
url = env("DATABASE_URL")
}

Expand Down
24 changes: 24 additions & 0 deletions fly.toml
@@ -0,0 +1,24 @@
# fly.toml app configuration file generated for small-pine-440 on 2023-10-11T01:09:41+01:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "small-pine-440"
primary_region = "lhr"

[build]

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

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

[http_service]
internal_port = 8910
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]

0 comments on commit 0781061

Please sign in to comment.