Skip to content

Commit

Permalink
Merge pull request #721 from jetstreamapp/server-refactor
Browse files Browse the repository at this point in the history
Migrate server to esbuild
  • Loading branch information
paustint authored Feb 10, 2024
2 parents 8305758 + 1cf0949 commit f590df6
Show file tree
Hide file tree
Showing 26 changed files with 726 additions and 260 deletions.
39 changes: 38 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
.editorconfig
.env
.env.example
.env.staging
.git
.github
.nx
.vscode
.workspace.code-workspace
app
# dist
apps/landing/.next
dist
electron-scripts
logs
node_modules
npm-debug.log
test-results
tmp
yarn-error.log

# System Files
.DS_Store
Thumbs.db

# Generated Docusaurus files
.docusaurus/
.cache-loader/

# Next.js
.next

# Playwright
**/test-results
**/playwright-report
**/playwright/.cache
.nx

# Not required for core jetstream
apps/cron-tasks
apps/docs
apps/electron
apps/jetstream-e2e
electron-scripts
*#
*~
.DS_Store
Thumbs.db

2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SFDC_CONSUMER_KEY='3MVG9tSqyyAXNH5ItQtuplEg40Ks_MLSG37L1PV.TLDjsCbdp7EDonFUW0csS
SFDC_CONSUMER_SECRET='F77C1B4AF03CF51B290A591766F4C430E3136949A636D4AA5339F8EB6A40052A'

# API VERSION TO USE
NX_SFDC_API_VERSION='58.0'
SFDC_API_VERSION='58.0'

# If set to true, then authentication will be bypassed
# You will use a test account instead of a real account - only works if running locally
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
name: Checkout [master]
with:
fetch-depth: 0
Expand All @@ -30,9 +30,9 @@ jobs:
run: git branch --track main origin/main

- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v3
uses: nrwl/nx-set-shas@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
Expand All @@ -46,7 +46,7 @@ jobs:
run: npx nx run-many --target=build --parallel=3 --projects=jetstream,api,download-zip-sw,landing --configuration=production

- name: Uploading artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dist-artifacts
path: dist
Expand Down Expand Up @@ -98,12 +98,12 @@ jobs:
- 5432:5432

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
name: Checkout [master]
with:
fetch-depth: 0

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
Expand All @@ -112,7 +112,7 @@ jobs:
run: yarn install --frozen-lockfile

- name: Download artifacts from build
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: dist-artifacts
path: dist
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:

- name: Upload test results
if: always() # This ensures step will always run even if prior steps fail
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: |
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens",
"ms-playwright.playwright",
"wayou.vscode-todo-highlight"
"wayou.vscode-todo-highlight",
"firsttris.vscode-jest-runner"
]
}
76 changes: 46 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,57 @@
# docker build -f Dockerfile . -t jetstream
# docker-compose up
# syntax = docker/dockerfile:1

# Login and run DB migrations (TODO: figure out how to automate this)
# https://medium.com/@sumankpaul/run-db-migration-script-in-docker-compose-ce8e447a77ba
# docker ps
# docker exec -it 791 bash
# npx prisma migrate deploy
ARG NODE_VERSION=20.10.0
ARG ENVIRONMENT=production

# TODO: auth redirect flow is broken, need to fix it
FROM node:${NODE_VERSION}-slim as base

FROM node:16
# App lives here
WORKDIR /app

WORKDIR /usr/src/app
# Set production environment
ENV NODE_ENV=production
ARG YARN_VERSION=1.22.21
RUN npm install -g yarn@$YARN_VERSION --force

# Copy application
COPY ./dist/apps/api ./dist/apps/api/
COPY ./dist/apps/jetstream ./dist/apps/jetstream/
COPY ./dist/apps/download-zip-sw ./dist/apps/download-zip-sw/
COPY ./dist/apps/landing ./dist/apps/landing/
# Throw-away build stage to reduce size of final image
FROM base as build

# Copy supporting files
COPY ./dist/apps/api/package.json .
COPY ./yarn.lock .
COPY ./.env .
COPY ./ecosystem.config.js .
COPY ./prisma ./prisma/
# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp openssl pkg-config python-is-python3

# Install core dependencies
RUN yarn
# Install node modules
COPY --link package.json yarn.lock ./
RUN yarn install --frozen-lockfile --production=false

# Install other dependencies that were not calculated by nx, but are required
RUN yarn add dotenv prisma@^3.13.0
# Generate Prisma Client
COPY --link prisma .
RUN yarn run db:generate

# Generate prisma client - ensure that there are no OS differences
RUN npx prisma generate
# Copy application code
COPY --link . .

EXPOSE 3333
EXPOSE 9229
# Build application
RUN yarn build:core
RUN yarn build:landing

# Remove development dependencies
RUN yarn install --production=true


# Final stage for app image
FROM base

CMD [ "node", "--inspect=0.0.0.0", "dist/apps/api/main.js" ]
# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y openssl && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

RUN npm install -g [email protected]

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 3333
CMD [ "yarn", "run", "start:prod" ]
11 changes: 0 additions & 11 deletions Dockerfile.db-migration

This file was deleted.

50 changes: 35 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ The Jetstream platform makes managing your Salesforce instances a breeze. Use Je

Learn more by [reading the docs](https://docs.getjetstream.app/).

**JETSTREAM IS SOURCE-AVAILABLE AND FREE TO USE. IF YOUR COMPANY IS GETTING VALUE, PLEASE CONSIDER SPONSORING THE PROJECT ❤️**
**JETSTREAM IS SOURCE-AVAILABLE AND FREE TO USE. IF YOUR COMPANY IS GETTING VALUE, CONSIDER SPONSORING THE PROJECT ❤️**

Jetstream wouldn't be possible without your contributions.

[![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/jetstreamapp)

There are multiple ways to use Jetstream.

1. Use the hosted version at https://getjetstream.app
2. Use the desktop version **TODO: COMING SOON**
3. Run locally
2. Run locally
1. Using nodejs
1. Building yourself (recommended if you want to contribute to the Jetstream codebase)
2. Using the pre-built version **TODO: COMING SOON**
2. Using Docker
4. Want to self-host behind your company firewall? Reach out to the team for assistance.
3. Want to self-host behind your company firewall? Reach out to the team for assistance.

# Overview of the codebase structure

Expand Down Expand Up @@ -73,13 +73,39 @@ This project was generated using [Nx](https://nx.dev) - This repository is consi

**Pre-req**

1. Make sure you have node 16 or 18 installed.
2. If you want to run the dev server, make sure you have yarn installed.
1. Make sure you have node 20 installed.
2. If you are using docker, make sure you have Docker installed.
3. If you want to run the dev server, make sure you have yarn version 1 installed.

📓 You can choose to skip authentication locally by setting the environment variable `EXAMPLE_USER_OVERRIDE=true`. This is set to true by default in the `.env.example` file.
🌟 To use this, don't click the login button, but instead just go to `http://localhost:3333/app` or `http://localhost:4200/app` (if running the react development server) directly.

The easiest way to run Jetstream locally is to download the pre-built and transpiled javascript files and run them using NodeJs.
### Using Docker

If you have docker and just want to run the application locally, using docker is the easiest option.

Build the docker image (this takes a while the first time).

```shell
docker build -t jetstream-app .
```

Use docker compose to create a dockerized postgres database and run the app.

```shell
docker compose up
```

- Jetstream will be running at `http://localhost:3333`
- Postgres will be running on port `5555` if you wanted to connect to it locally.
- When you click "Login", you should immediately be logged in without having to sign in.
- You can set `EXAMPLE_USER_OVERRIDE` if you want to disable this behavior
- If assets on the page don't load, do a hard refresh (hold cmd or shift and press refresh)
- This might happen if you have re-built the image and the browser has cached the page with now missing resources.

### Running without Docker

Use this option if you want to contribute to the codebase.

Jetstream relies on a Postgres database, so you either need to [run Postgresql locally](https://www.postgresql.org/download/) or use a managed provider such as one from the list below. Optionally you can run jetstream in a Docker container which includes Postgresql.

Expand All @@ -106,12 +132,6 @@ If you want to create your own:
3. All other defaults are fine
3. Update the file named `.env` and replace `SFDC_CONSUMER_KEY` and `SFDC_CONSUMER_SECRET` with the values from your connected app.

### Download pre-built application

This is the fastest 🏃 way to run Jetstream locally.

TODO: instructions to download and instructions to run

### Building

⭐ If you want to contribute to Jetstream, this is the best option.
Expand Down Expand Up @@ -166,7 +186,7 @@ TODO: instructions to download and instructions to run

## Desktop Application

**TODO: THIS HAS NOT BEEN ENTIRELY WORKED OUT YET**
This is a work in progress and may be removed as an available option.

### Local development

Expand Down
6 changes: 1 addition & 5 deletions apps/api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"extends": "../../.eslintrc.json",
"rules": {},
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"parserOptions": {
"project": ["apps/api/tsconfig.*?.json"]
},
"rules": {}
},
{
Expand Down
24 changes: 24 additions & 0 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is generated by Nx.
#
# Build the docker image with `npx nx docker-build api`.
# Tip: Modify "docker-build" options in project.json to change docker build args.
#
# Run the container with `docker run -p 3333:3333 -t api`.
FROM docker.io/node:lts-alpine

ENV HOST=0.0.0.0
ENV PORT=3333

WORKDIR /app

RUN addgroup --system api && \
adduser --system -G api api

COPY dist/apps/api api
RUN chown -R api:api .

# You can remove this install step if you build with `--bundle` option.
# The bundled output will include external dependencies.
RUN npm --prefix server --omit=dev -f install

CMD [ "node", "server" ]
11 changes: 7 additions & 4 deletions apps/api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-disable */
export default {
coverageDirectory: '../../coverage/apps/api',
globals: {},
displayName: 'api',
testEnvironment: 'node',
displayName: 'server',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/server',
};
Loading

0 comments on commit f590df6

Please sign in to comment.