Skip to content

Commit

Permalink
feat: deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
gmat224 committed Dec 11, 2024
1 parent 5b4ec19 commit 8869dad
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 75 deletions.
72 changes: 38 additions & 34 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,43 @@ RUN apt-get update -qq && \
COPY --link package.json yarn.lock ./
RUN yarn install --frozen-lockfile

ARG DATABASE_HOST
ARG DATABASE_PORT
ARG DATABASE_USERNAME
ARG DATABASE_PASSWORD
ARG DOMAIN_API
ARG DOMAIN_FRONTEND
ARG DOMAIN_STRAPI
ARG SUPERTOKENS_PORT
ARG STRIPE_SECRET_KEY
ARG STRIPE_WEBHOOK_ENDPOINT
ARG GOOGLE_CLIENT_ID
ARG GOOGLE_CLIENT_SECRET
ARG SUPERTOKENS_API_KEY
ARG SMTP_HOST
ARG SMTP_PORT
ARG SMTP_USER
ARG SMTP_PASS
# ARG DATABASE_HOST
# ARG DATABASE_PORT
# ARG DATABASE_USERNAME
# ARG DATABASE_PASSWORD
# ARG DOMAIN_API
# ARG DOMAIN_FRONTEND
# ARG DOMAIN_STRAPI
# ARG DOMAIN_SUPERTOKENS
# ARG STRIPE_SECRET_KEY
# ARG STRIPE_WEBHOOK_ENDPOINT
# ARG GOOGLE_CLIENT_ID
# ARG GOOGLE_CLIENT_SECRET
# ARG SUPERTOKENS_API_KEY
# ARG SMTP_HOST
# ARG SMTP_PORT
# ARG SMTP_USER
# ARG SMTP_PASS

# Set environment variables
ENV DATABASE_HOST=${DATABASE_HOST}
ENV DATABASE_PORT=${DATABASE_PORT}
ENV DATABASE_USERNAME=${DATABASE_USERNAME}
ENV DATABASE_PASSWORD=${DATABASE_PASSWORD}
ENV DOMAIN_API=${DOMAIN_API}
ENV DOMAIN_FRONTEND=${DOMAIN_FRONTEND}
ENV DOMAIN_STRAPI=${DOMAIN_STRAPI}
ENV SUPERTOKENS_PORT=${SUPERTOKENS_PORT}
ENV STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
ENV STRIPE_WEBHOOK_ENDPOINT=${STRIPE_WEBHOOK_ENDPOINT}
ENV GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
ENV GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
ENV SUPERTOKENS_API_KEY=${SUPERTOKENS_API_KEY}
ENV SMTP_HOST=${SMTP_HOST}
ENV SMTP_PORT=${SMTP_PORT}
ENV SMTP_USER=${SMTP_USER}
ENV SMTP_PASS=${SMTP_PASS}
# ENV DATABASE_HOST=${DATABASE_HOST}
# ENV DATABASE_PORT=${DATABASE_PORT}
# ENV DATABASE_USERNAME=${DATABASE_USERNAME}
# ENV DATABASE_PASSWORD=${DATABASE_PASSWORD}
# ENV DOMAIN_API=${DOMAIN_API}
# ENV DOMAIN_FRONTEND=${DOMAIN_FRONTEND}
# ENV DOMAIN_STRAPI=${DOMAIN_STRAPI}
# ENV DOMAIN_SUPERTOKENS=${DOMAIN_SUPERTOKENS}
# ENV STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
# ENV STRIPE_WEBHOOK_ENDPOINT=${STRIPE_WEBHOOK_ENDPOINT}
# ENV GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
# ENV GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
# ENV SUPERTOKENS_API_KEY=${SUPERTOKENS_API_KEY}
# ENV SMTP_HOST=${SMTP_HOST}
# ENV SMTP_PORT=${SMTP_PORT}
# ENV SMTP_USER=${SMTP_USER}
# ENV SMTP_PASS=${SMTP_PASS}


# Copy application code
COPY --link . .
Expand All @@ -67,6 +68,9 @@ FROM base as build

COPY --from=install /app /app

RUN --mount=type=secret,id=PORT \
PORT="$(cat /run/secrets/PORT)"

RUN yarn run build

# Final stage for app image
Expand Down
2 changes: 1 addition & 1 deletion api/fly.staging.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app = 'wdcc-auis-api-staging'
app = 'auis-api'
primary_region = 'syd'

[build]
Expand Down
45 changes: 22 additions & 23 deletions api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@ import { notFound } from "./middleware/errorMiddleware";
const app = express();
config();

// DELET ONC WE HAVE SUPEROTKEN THING
var domainSuperToken = `postgres://${process.env.DATABASE_USERNAME}:${process.env.DATABASE_PASSWORD}@${process.env.DATABASE_HOST}:${process.env.SUPERTOKENS_PORT}/supertokens`;
console.log(domainSuperToken);
var domainDatabase = `postgres://${process.env.DATABASE_USERNAME}:${process.env.DATABASE_PASSWORD}@${process.env.DATABASE_HOST}:${process.env.DATABASE_PORT}`;

supertokens.init({
// debug: true,
framework: "express",
supertokens: {
connectionURI: `${domainSuperToken}`,
apiKey: `${process.env.SUPERTOKENS_API_KEY}`,
},
appInfo: {
appName: "AUIS",
apiDomain: `${process.env.DOMAIN_API}`,
websiteDomain: `${process.env.DOMAIN_FRONTEND}`,
apiBasePath: "/api/auth",
websiteBasePath: "/signup",
},
recipeList: getConfiguredRecipeList(),
});
try {
supertokens.init({
// debug: true,
framework: "express",
supertokens: {
connectionURI: `${process.env.DOMAIN_SUPERTOKENS}`,
apiKey: `${process.env.SUPERTOKENS_API_KEY}`,
},
appInfo: {
appName: "AUIS",
apiDomain: `${process.env.DOMAIN_API}`,
websiteDomain: `${process.env.DOMAIN_FRONTEND}`,
apiBasePath: "/api/auth",
websiteBasePath: "/signup",
},
recipeList: getConfiguredRecipeList(),
});
} catch (error) {
console.log(error);
}

//init user and admin roles in supertokens
createRoles();
Expand All @@ -51,8 +50,8 @@ app.use(
origin: [
`${process.env.DOMAIN_FRONTEND}`, //FE
`${process.env.DOMAIN_STRAPI}`, //Strapi
`${domainSuperToken}`, //ST user Dashboard
`${domainDatabase}`, //DB
`${process.env.DOMAIN_SUPERTOKENS}`, //ST user Dashboard
`${process.env.DATABASE_HOST}:${process.env.DATABASE_PORT}`, //DB
],
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allowedHeaders: [
Expand Down
4 changes: 3 additions & 1 deletion api/supertokens/supertokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ export function getConfiguredRecipeList(): RecipeListFunction[] {
},
}),
Session.init(), // initializes session features
Dashboard.init(),
Dashboard.init({
admins: ["[email protected]"],
}),
UserMetadata.init(),
UserRoles.init(),
];
Expand Down
41 changes: 41 additions & 0 deletions database/Dockerfile.supertokens
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM ubuntu:bionic-20200219 as tmp
ARG PLUGIN_NAME=postgresql
ARG PLAN_TYPE=FREE
ARG CORE_VERSION=9.3.0
ARG PLUGIN_VERSION=7.2.0
RUN apt-get update && apt-get install -y curl zip
RUN OS= && dpkgArch="$(dpkg --print-architecture)" && \
case "${dpkgArch##*-}" in \
amd64) OS='linux';; \
arm64) OS='linux-arm';; \
*) OS='linux';; \
esac && \
curl -o supertokens.zip -s -X GET \
"https://api.supertokens.io/0/app/download?pluginName=$PLUGIN_NAME&os=$OS&mode=DEV&binary=$PLAN_TYPE&targetCore=$CORE_VERSION&targetPlugin=$PLUGIN_VERSION" \
-H "api-version: 0"
RUN unzip supertokens.zip
RUN cd supertokens && ./install
FROM debian:bookworm-slim
RUN groupadd supertokens && useradd -m -s /bin/bash -g supertokens supertokens
RUN apt-get update && apt-get install -y --no-install-recommends gnupg dirmngr && rm -rf /var/lib/apt/lists/*
ENV GOSU_VERSION 1.7
RUN set -x \
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
&& gpgconf --kill all \
&& rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu \
&& apt-get purge -y --auto-remove ca-certificates wget
COPY --from=tmp --chown=supertokens /usr/lib/supertokens /usr/lib/supertokens
COPY --from=tmp --chown=supertokens /usr/bin/supertokens /usr/bin/supertokens
COPY docker-entrypoint.sh /usr/local/bin/
RUN echo "$(md5sum /usr/lib/supertokens/config.yaml | awk '{ print $1 }')" >> /CONFIG_HASH
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
EXPOSE 3567
USER "supertokens"
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["supertokens", "start"]
12 changes: 8 additions & 4 deletions database/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ services:
image: postgres
restart: always
environment:
POSTGRES_USER: AUIS
POSTGRES_PASSWORD: GuryIsGoat
POSTGRES_DB: AUIS
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- 5432:5432
expose:
Expand All @@ -24,7 +24,11 @@ services:
image: supertokens/supertokens-postgresql
ports:
- 3567:3567
expose:
- 3567
environment:
environment:
- POSTGRESQL_CONNECTION_URI=${POSTGRESQL_CONNECTION_URI}
LOG_LEVEL: ERROR
POSTGRESQL_CONNECTION_URI: "postgresql://db:5432/AUIS?user=AUIS&password=GuryIsGoat"
POSTGRESQL_CONNECTION_URI: POSTGRESQL_CONNECTION_URI
restart: always
20 changes: 19 additions & 1 deletion database/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'auis-staging'
app = 'auis-db'
primary_region = 'syd'

[env]
FLY_SCALE_TO_ZERO = '1h'
PRIMARY_REGION = 'syd'

[build]
# dockerfile contains build time non-sensitive env vars
dockerfile = "docker-compose.yml"

[[mounts]]
source = 'pg_data'
destination = '/data'
Expand All @@ -28,6 +32,20 @@ primary_region = 'syd'
hard_limit = 1000
soft_limit = 1000

[[services]]
protocol = 'tcp'
internal_port = 3567
auto_start_machines = true

[[services.ports]]
port = 3567
handlers = ['pg_tls']

[services.concurrency]
type = 'connections'
hard_limit = 1000
soft_limit = 1000

[[services]]
protocol = 'tcp'
internal_port = 5433
Expand Down
21 changes: 21 additions & 0 deletions deployment/postgres/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# fly.toml app configuration file generated for auis-supertokens on 2024-12-11T18:44:14+13:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'auis-supertokens'
primary_region = 'syd'

[build]
image = 'registry.supertokens.io/supertokens/supertokens-postgresql'

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
size = 'shared-cpu-1x'
4 changes: 2 additions & 2 deletions strapi/fly.staging.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'wdcc-auis-strapi-staging'
app = 'auis-strapi'
primary_region = 'syd'

[build]
Expand All @@ -21,4 +21,4 @@ primary_region = 'syd'
[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
cpus = 1
24 changes: 24 additions & 0 deletions strapi/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# fly.toml app configuration file generated for auis-strapi on 2024-12-11T18:59:18+13:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'auis-strapi'
primary_region = 'syd'

[build]
# dockerfile contains build time non-sensitive env vars
dockerfile = "Dockerfile"

[http_service]
internal_port = 1337
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '512mb'
cpu_kind = 'shared'
cpus = 1
23 changes: 23 additions & 0 deletions supertoken-core/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# fly.toml app configuration file generated for supertoken-core on 2024-12-11T19:36:23+13:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'auis-supertokens'
primary_region = 'syd'

[build]
image = 'registry.supertokens.io/supertokens/supertokens-postgresql'

[http_service]
internal_port = 3567
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
13 changes: 5 additions & 8 deletions web/Dockerfile.staging
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@ RUN yarn install --frozen-lockfile --production=false
# Copy application code
COPY --link . .

ARG VITE_CLERK_PUBLISHABLE_KEY
ENV VITE_CLERK_PUBLISHABLE_KEY=${VITE_CLERK_PUBLISHABLE_KEY}

RUN yarn test

ENV VITE_API_URL="https://wdcc-auis-api-staging.fly.dev"
ENV VITE_STRAPI_URL="https://wdcc-auis-strapi-staging.fly.dev"
ENV VITE_APP_URL="https://wdcc-auis-staging.fly.dev"
ENV VITE_API_URL="https://auis.fly.dev"
ENV VITE_STRAPI_URL="https://auis-strapi.fly.dev"
ENV VITE_APP_URL="https://auis-api.fly.dev"
ENV VITE_APP_NAME="AUIS"
ENV VITE_CLERK_PUBLISHABLE_KEY="pk_test_51PPclyP464csY2UpQPZ4cpWlyupAwPXfvWZRIG0zy9BhlYE8GmR4LYEytjFKOjMS6o5oXF5I0QMB8RWcc0TqsNxC00Nz3UAH14"

# Mount secrets into Dockerfile and set environment variables
RUN --mount=type=secret,id=VITE_STRIPE_PUBLISHABLE_KEY \
VITE_STRIPE_PUBLISHABLE_KEY="$(cat /run/secrets/VITE_STRIPE_PUBLISHABLE_KEY)" \
yarn run build
RUN yarn run build

# Remove development dependencies
RUN yarn install --production=true
Expand Down
2 changes: 1 addition & 1 deletion web/fly.staging.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'wdcc-auis-staging'
app = 'auis'
primary_region = 'syd'

[build]
Expand Down

0 comments on commit 8869dad

Please sign in to comment.