Skip to content

Commit d270313

Browse files
authored
refactor: monorepo layout (#118)
Rework the repository to be ready to add spark-observer as the second service. See CheckerNetwork/spark-api#323 Signed-off-by: Miroslav Bajtoš <[email protected]>
1 parent 8ac87b7 commit d270313

20 files changed

+845
-697
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ version: 2
22
updates:
33
- package-ecosystem: "npm"
44
directory: "/"
5+
versioning-strategy: increase
56
schedule:
67
interval: "daily"
78
time: "09:00"

.github/workflows/ci.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
branches: [main]
77

88
jobs:
9-
build:
9+
build-stats:
1010
runs-on: ubuntu-latest
1111
services:
1212
postgres:
@@ -24,6 +24,7 @@ jobs:
2424
--health-retries 5
2525
env:
2626
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
27+
NPM_CONFIG_WORKSPACE: stats
2728
steps:
2829
- uses: actions/checkout@v4
2930
- uses: actions/setup-node@v4
@@ -33,6 +34,16 @@ jobs:
3334
- run: npm run migrate
3435
- run: npm test
3536

37+
lint-all:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: actions/setup-node@v4
42+
with:
43+
node-version: 20
44+
- run: npm ci
45+
- run: npm run lint
46+
3647
docker-build:
3748
runs-on: ubuntu-latest
3849
permissions:
@@ -49,7 +60,7 @@ jobs:
4960
username: ${{ github.actor }}
5061
password: ${{ secrets.GITHUB_TOKEN }}
5162

52-
- name: Build Docker image
63+
- name: Build monorepo Docker image
5364
uses: docker/build-push-action@v5
5465
with:
5566
context: .
@@ -58,12 +69,12 @@ jobs:
5869

5970
deploy:
6071
if: github.ref == 'refs/heads/main'
61-
needs: [build, docker-build]
72+
needs: [build-stats, docker-build]
6273
runs-on: ubuntu-latest
6374
steps:
6475
- uses: actions/checkout@v4
6576
- uses: superfly/flyctl-actions/setup-flyctl@master
66-
- run: flyctl deploy --remote-only
77+
- run: flyctl deploy --remote-only -c stats/fly.toml
6778
env:
6879
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
6980
- if: failure()

Dockerfile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ WORKDIR /app
1212
# Set production environment
1313
ENV NODE_ENV production
1414
ENV SENTRY_ENVIRONMENT production
15-
ENV REQUEST_LOGGING false
1615

1716
#######################################################################
1817
# Throw-away build stage to reduce size of final image
@@ -27,7 +26,12 @@ RUN apt-get update -qq && \
2726
# to install all modules: "npm install --production=false".
2827
# Ref: https://docs.npmjs.com/cli/v9/commands/npm-install#description
2928
COPY --link package-lock.json package.json ./
30-
RUN npm ci
29+
30+
# We cannot use a wildcard until `COPY --parents` is stabilised
31+
# See https://docs.docker.com/reference/dockerfile/#copy---parents
32+
COPY --link stats/package.json ./stats/
33+
34+
RUN npm ci --workspaces
3135

3236
# Copy application code
3337
COPY --link . .
@@ -39,5 +43,8 @@ FROM base
3943
# Copy built application
4044
COPY --from=build /app /app
4145

42-
# Start the server by default, this can be overwritten at runtime
43-
CMD [ "npm", "run", "start" ]
46+
# Set to `publish` or `api`
47+
# This argument controls the value passed to npm start --workspace parameter
48+
ENV SERVICE=""
49+
50+
CMD npm start --workspace ${SERVICE}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ npm test
8080
### Run the service
8181

8282
```sh
83-
npm start
83+
npm start --workspace stats
8484
```
8585

8686
You can also run the service against live data in Spark DB running on Fly.io.

0 commit comments

Comments
 (0)