Skip to content

Commit

Permalink
🎇 merge pull request #46 from devsoc-unsw/feature/deployment
Browse files Browse the repository at this point in the history
🐳 ready for deployment (#45)
  • Loading branch information
lachlanshoesmith authored Oct 18, 2024
2 parents ccd318c + efba86b commit a6d5133
Show file tree
Hide file tree
Showing 17 changed files with 386 additions and 172 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ by alyssa, ben, chris, lachlan, and osvaldo

1. `cd backend && pnpm i`
2. set the following value in `backend/.env`:

```bash
SESSION_SECRET=
NODE_ENV=
ALLOWED_ORIGINS=/commaseparated/,/regexes/
```
NODE_ENV is usually either 'development' or 'production'
3. `cd ../frontend && pnpm i`
4. set the following values in `frontend/.env`:

NODE_ENV is usually either 'development' or 'production' 3. `cd ../frontend && pnpm i` 4. set the following values in `frontend/.env`:

```bash
VITE_FIREBASE_API_KEY=
VITE_FIREBASE_AUTH_DOMAIN=
Expand All @@ -23,12 +25,15 @@ VITE_FIREBASE_STORAGE_BUCKET=
VITE_FIREBASE_MESSAGING_SENDER_ID=
VITE_FIREBASE_APP_ID=
```
5. *optionally*, create a .env file at the root of the repository which contains a cloudflare deploy book endpoint.

5. _optionally_, create a .env file at the root of the repository which contains a cloudflare deploy book endpoint.

```
echo "https://api.cloudflare.com/client/v4/pages/webhooks/deploy_hooks/ENDPOINT_GOES_HERE" > .env
```

you can now use the `rebuild` script in the root of the repository to initiate manual deployments without having to push changes to `main`.

## level editor

you can create your own yellowshirt levels (or, more precisely, *maps* composed of *levels*) using the [panoproc](https://github.com/lachlanshoesmith/panoproc) level editor. installation and usage instructions can be found in that repository's readme.
you can create your own yellowshirt levels (or, more precisely, _maps_ composed of _levels_) using the [panoproc](https://github.com/lachlanshoesmith/panoproc) level editor. installation and usage instructions can be found in that repository's readme.
2 changes: 2 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
Dockerfile
35 changes: 35 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM node:22.10.0-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

# install dependencies for compiling bcrypt
RUN apk --no-cache add --virtual builds-deps build-base python3

COPY . /yellowshirt-backend
WORKDIR /yellowshirt-backend

FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod

ENV NODE_ENV=production

# envs to set for runtime
# if using fly, env vars can be specified in fly.toml

#ENV ALLOWED_ORIGINS=/yellowshirt\.xyz$/,/trainee-woodelf-24t2\.pages\.dev$/,/yellowshirt-backend\.fly\.dev$/

# ⚠️ SESSION_SECRET should be, well, a secret!
# if using fly, use fly secrets
#ENV SESSION_SECRET=...

FROM base AS build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install && pnpm rebuild bcrypt
RUN pnpm run build

FROM base
COPY --from=prod-deps /yellowshirt-backend/node_modules /yellowshirt-backend/node_modules
COPY --from=build /yellowshirt-backend/dist /yellowshirt-backend/dist

EXPOSE 3000
CMD ["pnpm", "start"]
25 changes: 25 additions & 0 deletions backend/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# fly.toml app configuration file generated for yellowshirt-backend on 2024-10-18T15:00:04+11:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'yellowshirt-backend'
primary_region = 'syd'

[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

[env]
ALLOWED_ORIGINS = 'yellowshirt\.xyz$,trainee-woodelf-24t2\.pages\.dev$,yellowshirt-backend\.fly\.dev$'
7 changes: 4 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"fs": "^0.0.1-security"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/express-session": "^1.18.0",
"@types/node": "^20.14.9",
Expand All @@ -26,9 +28,8 @@
"dev_env": "tsx watch --env-file=.env ./src/index.ts",
"dev": "tsx watch ./src/index.ts",
"build": "tsc --build",
"start_env": "node --env-file=.env dist/src/index.js",
"start": "node dist/src/index.js",
"production": "node dist/src/index.js"
"start_env": "node --env-file=.env dist/index.js",
"start": "node dist/index.js"
},
"prettier": {
"singleQuote": false,
Expand Down
20 changes: 20 additions & 0 deletions backend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a6d5133

Please sign in to comment.