diff --git a/api/Dockerfile b/api/Dockerfile index 74cc574..507bc05 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -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 . . @@ -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 diff --git a/api/fly.staging.toml b/api/fly.staging.toml index 31cbb60..61fa426 100644 --- a/api/fly.staging.toml +++ b/api/fly.staging.toml @@ -1,4 +1,4 @@ -app = 'wdcc-auis-api-staging' +app = 'auis-api' primary_region = 'syd' [build] diff --git a/api/index.ts b/api/index.ts index 1580eea..0ee5403 100644 --- a/api/index.ts +++ b/api/index.ts @@ -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(); @@ -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: [ diff --git a/api/supertokens/supertokens.ts b/api/supertokens/supertokens.ts index 04d80a8..2121a08 100644 --- a/api/supertokens/supertokens.ts +++ b/api/supertokens/supertokens.ts @@ -163,7 +163,9 @@ export function getConfiguredRecipeList(): RecipeListFunction[] { }, }), Session.init(), // initializes session features - Dashboard.init(), + Dashboard.init({ + admins: ["au.indiansociety@gmail.com"], + }), UserMetadata.init(), UserRoles.init(), ]; diff --git a/database/Dockerfile.supertokens b/database/Dockerfile.supertokens new file mode 100644 index 0000000..f6529ed --- /dev/null +++ b/database/Dockerfile.supertokens @@ -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"] \ No newline at end of file diff --git a/database/docker-compose.yml b/database/docker-compose.yml index 8d4dc09..ac024e7 100644 --- a/database/docker-compose.yml +++ b/database/docker-compose.yml @@ -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: @@ -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 \ No newline at end of file diff --git a/database/fly.toml b/database/fly.toml index 96b3665..6897eb0 100644 --- a/database/fly.toml +++ b/database/fly.toml @@ -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' @@ -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 diff --git a/deployment/postgres/fly.toml b/deployment/postgres/fly.toml new file mode 100644 index 0000000..2878491 --- /dev/null +++ b/deployment/postgres/fly.toml @@ -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' diff --git a/strapi/fly.staging.toml b/strapi/fly.staging.toml index 9c41755..ce0f963 100644 --- a/strapi/fly.staging.toml +++ b/strapi/fly.staging.toml @@ -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] @@ -21,4 +21,4 @@ primary_region = 'syd' [[vm]] memory = '1gb' cpu_kind = 'shared' - cpus = 1 \ No newline at end of file + cpus = 1 diff --git a/strapi/fly.toml b/strapi/fly.toml new file mode 100644 index 0000000..0643392 --- /dev/null +++ b/strapi/fly.toml @@ -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 diff --git a/supertoken-core/fly.toml b/supertoken-core/fly.toml new file mode 100644 index 0000000..78e25f0 --- /dev/null +++ b/supertoken-core/fly.toml @@ -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 diff --git a/web/Dockerfile.staging b/web/Dockerfile.staging index 12209a7..a2a61e5 100644 --- a/web/Dockerfile.staging +++ b/web/Dockerfile.staging @@ -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 diff --git a/web/fly.staging.toml b/web/fly.staging.toml index f80dd0c..edfdbe3 100644 --- a/web/fly.staging.toml +++ b/web/fly.staging.toml @@ -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]