Skip to content

Commit

Permalink
Merge branch 'main' into 62-use-bun-for-the-api
Browse files Browse the repository at this point in the history
  • Loading branch information
bnussman committed Oct 31, 2023
2 parents 699fdb2 + 9bb0b55 commit 8f880e8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ name: e2e
on:
push:
branches:
- main
- production
- main
- production
pull_request:

jobs:
test:
timeout-minutes: 60
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -37,18 +38,14 @@ jobs:
run: pnpm i --frozen-lockfile
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps chromium
- name: Start DB and Redis
- name: Start Docker services (PostgreSQL, Redis, and S3)
run: docker compose up -d
- name: Build the api
run: pnpm build:api
- name: Init the DB
run: pnpm --filter @beep/api db:create
- name: Run Playwright tests
run: pnpm --filter @beep/test test
env:
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_ACCESS_KEY_SECRET: ${{ secrets.S3_ACCESS_KEY_SECRET }}
S3_ENDPOINT_URL: ${{ secrets.S3_ENDPOINT_URL }}
- uses: actions/upload-artifact@v3
if: always()
with:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ To run the development envrionment use in the repo's root
pnpm dev
```

By default, the api will use your local database and redis from docker. You should not need an `.env` to develop locally
You can create a `.env` in `api/` to set the API's env. (`vim api/.env`)
By default, the api will use your local database, redis, and s3 server from docker. You should not need an `.env` to develop locally
You can create a `.env` in `api/` to set the API's env if needed. (`vim api/.env`)

```env
S3_ACCESS_KEY_ID=hkjvbyuverbvugfreukgsig
Expand Down
3 changes: 2 additions & 1 deletion api/src/users/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { password as bunPassword } from 'bun';
import { VerifyEmail } from '../entities/VerifyEmail';
import { GraphQLUpload } from 'graphql-upload-minimal';
import { setContext } from "@sentry/node";
import { S3_BUCKET_URL } from '../utils/constants';

@ObjectType()
class UsersPerDomain {
Expand Down Expand Up @@ -188,7 +189,7 @@ export class UserResolver {
const result = await s3.upload(uploadParams).promise();

if (ctx.user.photo) {
const key = ctx.user.photo.split("https://beep.us-east-1.linodeobjects.com/")[1];
const key = ctx.user.photo.split(S3_BUCKET_URL)[1];

deleteObject(key);
}
Expand Down
10 changes: 7 additions & 3 deletions api/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ export const REDIS_HOST = process.env.REDIS_HOST || "localhost";

export const REDIS_PASSWROD = process.env.REDIS_PASSWORD;

export const S3_ACCESS_KEY_ID = process.env.S3_ACCESS_KEY_ID;
export const S3_ACCESS_KEY_ID = process.env.S3_ACCESS_KEY_ID ?? "beep";

export const S3_ACCESS_KEY_SECRET = process.env.S3_ACCESS_KEY_SECRET;
export const S3_ACCESS_KEY_SECRET = process.env.S3_ACCESS_KEY_SECRET ?? "beepbeepbeep";

export const S3_ENDPOINT_URL = process.env.S3_ENDPOINT_URL;
export const S3_ENDPOINT_URL = process.env.S3_ENDPOINT_URL ?? "http://localhost:9000";

export const isLocalS3 = S3_ACCESS_KEY_SECRET === "beepbeepbeep";

export const S3_BUCKET_URL = isLocalS3 ? "http://localhost:9000/beep/" : "https://beep.us-east-1.linodeobjects.com/";

export const MAIL_HOST = process.env.MAIL_HOST;

Expand Down
5 changes: 3 additions & 2 deletions api/src/utils/s3.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as Sentry from "@sentry/node";
import { S3 } from "aws-sdk";
import { S3_ACCESS_KEY_ID, S3_ACCESS_KEY_SECRET, S3_ENDPOINT_URL } from "./constants";
import { S3_ACCESS_KEY_ID, S3_ACCESS_KEY_SECRET, S3_ENDPOINT_URL, isLocalS3 } from "./constants";

export const s3 = new S3({
accessKeyId: S3_ACCESS_KEY_ID,
secretAccessKey: S3_ACCESS_KEY_SECRET,
endpoint: S3_ENDPOINT_URL
endpoint: S3_ENDPOINT_URL,
s3ForcePathStyle: isLocalS3,
});

export async function getAllObjects(params: S3.ListObjectsV2Request): Promise<S3.ObjectList> {
Expand Down
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ services:
POSTGRES_USER: beep
POSTGRES_PASSWORD: beep
TZ: America/New_York
s3:
image: minio/minio
ports:
- "9000:9000"
environment:
MINIO_ACCESS_KEY: beep
MINIO_SECRET_KEY: beepbeepbeep
MINIO_ROOT_USER: beep
MINIO_ROOT_PASSWORD: beepbeepbeep
command: server ./data
bucket:
image: minio/mc
depends_on:
- s3
entrypoint: >
/bin/sh -c "
/usr/bin/mc alias set beep http://s3:9000 beep beepbeepbeep;
/usr/bin/mc mb beep/beep;
/usr/bin/mc anonymous set public beep/beep;
exit 0;
"
volumes:
data:

0 comments on commit 8f880e8

Please sign in to comment.