Skip to content

Show npm workspace monorepo changes against main #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dc718ce
refactor: `lib/migrate.js` → `migrations/index.js`
bajtos May 28, 2024
a737aae
refactor: move spark-api files to a subdir
bajtos May 28, 2024
03237f0
fixup! fix tests + run per-project tests only
bajtos May 28, 2024
55f946e
Merge branch 'main' into monorepo
bajtos May 28, 2024
a202151
fixup! add mocha config
bajtos May 28, 2024
6a82285
fixup! update package lock
bajtos May 28, 2024
a88a17b
docs: update start scripts & README
bajtos May 28, 2024
3166bd7
fix: "npm run migrate"
bajtos May 28, 2024
d77af20
ci: update GHA workflow
bajtos May 28, 2024
1c4d223
fixup! build-api should test only spark-api
bajtos May 28, 2024
6e7af32
docker build using a shared Dockerfile
bajtos May 28, 2024
19c46a1
single Dockerfile shared by all pckages
bajtos May 28, 2024
554f426
remove per-project .dockerignore files
bajtos May 28, 2024
a668dae
fix GHA CI cmd for testing spark api
bajtos May 28, 2024
c7d99f5
fixup! commit .gitignore
bajtos May 29, 2024
29a88de
feat: npm workspaces
bajtos May 29, 2024
05c50ec
fix CI + move `standard` to monorepo root
bajtos May 29, 2024
de05fec
monorepo package name
bajtos May 29, 2024
6ccb779
ci: run CI for all pull requests
bajtos May 29, 2024
d7fbab4
move mocha to sub-packages
bajtos May 29, 2024
daa2650
add standard to child workspaces
bajtos May 29, 2024
30fe8d5
fix CI step to migrate the DB
bajtos May 29, 2024
aa45167
Rework Dockerfile to use `npm start --workspace`
bajtos May 29, 2024
09be6ac
ci: fix build-publish
bajtos May 29, 2024
02f909e
fix dependabot
bajtos May 29, 2024
9760a4e
another fix for Dependabot
bajtos May 29, 2024
98333c7
fix build-publish to test publish, not api
bajtos May 29, 2024
dadc411
add postgrator to spark-publish dev-dependencies
bajtos May 29, 2024
8193fed
minor fixes
bajtos May 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Dockerfile
.dockerignore
node_modules
.git
.env
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ updates:
- package-ecosystem: "npm"
directories:
- "/"
- "/spark-publish"
schedule:
interval: "daily"
time: "09:00"
timezone: "Europe/Berlin"
versioning-strategy: increase
commit-message:
prefix: "deps"
prefix-development: "deps(dev)"
Expand Down
50 changes: 23 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build-api:
Expand All @@ -25,6 +24,7 @@ jobs:
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
GLIF_TOKEN: ${{ secrets.GLIF_TOKEN }}
NPM_CONFIG_WORKSPACE: spark-api
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -51,17 +51,27 @@ jobs:
--health-retries 5
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
NPM_CONFIG_WORKSPACE: spark-publish
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run migrate
- run: cd spark-publish && npm ci
- run: cd spark-publish && npm test
- run: node bin/migrate.js
- run: npm test

docker-build-api:
lint-all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run lint

docker-build:
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -77,44 +87,30 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
- name: Build spark-api Docker image
uses: docker/build-push-action@v5
with:
context: .
build-args: "SERVICE=api"
cache-from: type=registry,ref=ghcr.io/filecoin-station/core
cache-to: type=inline

docker-build-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
env:
REGISTRY: ghcr.io
steps:
- uses: actions/checkout@v4

- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
- name: Build spark-publish Docker image
uses: docker/build-push-action@v5
with:
context: spark-publish
context: .
build-args: "SERVICE=publish"
cache-from: type=registry,ref=ghcr.io/filecoin-station/core
cache-to: type=inline

deploy-api:
if: github.ref == 'refs/heads/main'
needs: [build-api, build-publish, docker-build-api, docker-build-publish]
needs: [build-api, build-publish, docker-build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
- run: cd spark-api && flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- if: failure()
Expand All @@ -138,7 +134,7 @@ jobs:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
deploy-publish:
if: github.ref == 'refs/heads/main'
needs: [build-api, build-publish, docker-build-api, docker-build-publish]
needs: [build-api, build-publish, docker-build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
23 changes: 17 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ WORKDIR /app
# Set production environment
ENV NODE_ENV production
ENV SENTRY_ENVIRONMENT production
ENV DOMAIN api.filspark.com
ENV REQUEST_LOGGING false

#######################################################################
# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install -y build-essential pkg-config python-is-python3
apt-get install -y build-essential pkg-config python-is-python3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: revert

Suggested change
apt-get install -y build-essential pkg-config python-is-python3
apt-get install -y build-essential pkg-config python-is-python3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually nicer when formatted the current way.

# Install packages needed to build node modules
RUN apt-get update -qq && \
    apt-get install -y build-essential pkg-config python-is-python3

Before:

# Install packages needed to build node modules
RUN apt-get update -qq && \
  apt-get install -y build-essential pkg-config python-is-python3


# Install node modules
# NPM will not install any package listed in "devDependencies" when NODE_ENV is set to "production",
# to install all modules: "npm install --production=false".
# Ref: https://docs.npmjs.com/cli/v9/commands/npm-install#description
COPY --link package-lock.json package.json ./
RUN npm ci

# We cannot use a wildcard until `COPY --parents` is stabilised
# See https://docs.docker.com/reference/dockerfile/#copy---parents
COPY --link spark-api/package.json ./spark-api/
COPY --link spark-publish/package.json ./spark-publish/

RUN npm ci --workspaces

# Copy application code
COPY --link . .
Expand All @@ -40,5 +44,12 @@ FROM base
# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
CMD [ "npm", "run", "start" ]
# Set to `publish` or `api`
# This argument controls what npm script is executed as the CMD.
ARG SERVICE

# ARGs are not preserved at runtime, we need to store the value
# as a default value of an ENV var
ENV WORKSPACE="spark-${SERVICE}"

CMD npm start --workspace ${WORKSPACE}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ docker run -d --name spark-db \
Start the API service:

```bash
npm start
npm start --workspace spark-api
```

Run tests and linters:

```bash
npm test
npm test --workspace spark-api
npm run lint --workspace spark-api
```

## Deployment
Expand All @@ -105,5 +106,5 @@ Pushes to `main` will be deployed automatically.
Perform manual devops using [Fly.io](https://fly.io):

```bash
$ fly deploy
$ fly deploy spark-api
```
2 changes: 1 addition & 1 deletion bin/migrate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrate } from '../lib/migrate.js'
import { migrate } from '../migrations/index.js'
import pg from 'pg'

const { DATABASE_URL } = process.env
Expand Down
File renamed without changes.
Loading